-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
executable file
·84 lines (68 loc) · 2.84 KB
/
install.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! /usr/bin/env python
import os, sys
import shutil
from optparse import OptionParser
CUR_DIR = os.getcwd()
################################################################################
## main method
################################################################################
def main():
parser = OptionParser()
parser.add_option("-l", "--symlink", help='symlink instead of hard installation')
(options, args) = parser.parse_args()
install(options)
################################################################################
## install method
################################################################################
def install(options):
DEST_LIB_DIR = "/usr/lib/sominst"
DEST_BIN_DIR = "/usr/bin"
SOMINST_SYMLINK = os.path.join(DEST_BIN_DIR, "sominst")
SOMINST_LIB_DIR = os.path.join(DEST_LIB_DIR, "sominst")
SOMINST_FILE = os.path.join(DEST_LIB_DIR, "sominst.py")
BASE_DIR = os.getcwd()
# create temp base directory
if not os.path.exists(DEST_LIB_DIR):
print "############################################"
print " Destination directory does not exist"
print " creating ... "
print DEST_LIB_DIR
os.makedirs(DEST_LIB_DIR)
# directory exist already, so clean files first
if os.path.exists(DEST_LIB_DIR):
print "############################################"
print " Cleaning old files"
print ""
for the_file in os.listdir(DEST_LIB_DIR):
file_path = os.path.join(DEST_LIB_DIR, the_file)
try:
if os.path.isfile(file_path):
os.unlink(file_path)
if os.path.isdir(file_path):
shutil.rmtree(file_path)
except Exception, e:
print e
# check sominst symlink in /usr/bin if exists, remove it
try:
if os.path.lexists(SOMINST_SYMLINK):
print "############################################"
print " Removing old file /usr/bin/symlink"
print ""
os.unlink(SOMINST_SYMLINK)
except IOError:
pass
#if os.path.exists(SOMINST_SYMLINK):
# print "removing symlink: ", SOMINST_SYMLINK
# os.unlink(os.path.join(DEST_BIN_DIR,"sominst"))
# copy
shutil.copytree(os.path.join(BASE_DIR, "sominst"), SOMINST_LIB_DIR)
shutil.copy2(os.path.join(BASE_DIR, "sominst.py"), SOMINST_FILE)
os.symlink(SOMINST_FILE, SOMINST_SYMLINK)
print "############################################"
print "### sominst was successfully installed"
print "############################################"
################################################################################
## execute the program
################################################################################
if __name__ == '__main__':
sys.exit(main())