1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """SCons targets for installing relax."""
24
25
26 from os import F_OK, access, getcwd, path, remove, rmdir, sep, system, walk
27 from shutil import copytree
28 import sys
29
30
31 try:
32 from os import lstat, symlink
33 except ImportError:
34 pass
35
36
38 """relax installation function (a Builder action)."""
39
40
41
42
43 print('')
44 print("####################")
45 print("# Installing relax #")
46 print("####################\n\n")
47 print("Installing the program relax into the directory " + repr(env['RELAX_PATH']) + "\n\n")
48
49
50
51
52
53
54 if not access(env['INSTALL_PATH'], F_OK):
55 sys.stderr.write("Cannot install relax, the installation path " + repr(env['INSTALL_PATH']) + " does not exist.\n\n")
56 return
57
58
59 if not access(env['BIN_PATH'], F_OK):
60 sys.stderr.write("Cannot install relax, the directory " + repr(env['BIN_PATH']) + " does not exist.\n\n")
61 return
62
63
64 if access(env['RELAX_PATH'], F_OK):
65 sys.stderr.write("Cannot install relax, the directory " + repr(env['RELAX_PATH']) + " already exists.\n\n")
66 return
67
68
69 if env['SYMLINK_FLAG']:
70 try:
71 lstat(env['SYMLINK'])
72 except OSError:
73
74 pass
75 else:
76 sys.stderr.write("Cannot install relax, the file " + repr(env['SYMLINK']) + " already exists.\n\n")
77 return
78
79
80
81
82
83
84 try:
85 print("\nCopying all files in " + repr(getcwd()) + " to " + repr(env['RELAX_PATH']) + ".")
86 copytree(getcwd(), env['RELAX_PATH'])
87 except OSError:
88 message = sys.exc_info()[1]
89
90
91 sys.stderr.write("Cannot install relax, " + message.__doc__ + "\n")
92
93
94 if message.errno == 13:
95 sys.stderr.write("Permission denied, cannot create the directory " + repr(env['RELAX_PATH']) + ".\n\n")
96
97
98 else:
99 sys.stderr.write("OSError: [Errno " + repr(message.errno) + "] " + message.strerror + ": " + repr(message.filename) + "\n\n")
100
101
102 return
103
104
105 if env['SYMLINK_FLAG']:
106 print("\nCreating the symbolic link from " + repr(env['RELAX_PATH'] + sep + 'relax') + " to " + repr(env['SYMLINK']) + ".")
107 symlink(env['RELAX_PATH'] + sep + 'relax', env['SYMLINK'])
108
109
110
111
112
113
114 print("\nCreating the byte-compiled *.pyc files.")
115 python_path = sys.prefix + path.sep + 'bin' + path.sep + 'python' + repr(sys.version_info[0]) + '.' + repr(sys.version_info[1])
116 cmd = "cd %s; %s -m compileall . ; %s -O -m compileall ." % (env['RELAX_PATH'], python_path, python_path)
117 print(cmd)
118 system(cmd)
119
120
121 print("\n\n\n")
122
123
125 """relax deinstallation function (a Builder action)."""
126
127
128
129
130 print('')
131 print("######################")
132 print("# Uninstalling relax #")
133 print("######################\n\n")
134 print("Uninstalling the program relax from the directory " + repr(env['INSTALL_PATH']) + "\n\n")
135
136
137
138
139
140
141 if not access(env['INSTALL_PATH'], F_OK):
142 sys.stderr.write("Cannot uninstall relax, the installation path " + repr(env['INSTALL_PATH']) + " does not exist.\n\n")
143 return
144
145
146 if not access(env['BIN_PATH'], F_OK):
147 sys.stderr.write("Cannot uninstall relax, the directory " + repr(env['BIN_PATH']) + " does not exist.\n\n")
148 return
149
150
151 if not access(env['RELAX_PATH'], F_OK):
152 sys.stderr.write("Cannot uninstall relax, the directory " + repr(env['RELAX_PATH']) + " does not exist.\n\n")
153 return
154
155
156 if env['SYMLINK_FLAG']:
157 try:
158 lstat(env['SYMLINK'])
159 except OSError:
160 sys.stderr.write("Cannot uninstall relax, the file " + repr(env['SYMLINK']) + " does not exist.\n\n")
161 return
162
163
164
165
166
167
168 if env['SYMLINK_FLAG']:
169 print("\nRemoving the symbolic link " + repr(env['SYMLINK']) + ".")
170 remove(env['SYMLINK'])
171
172
173 print("\nRemoving the entire directory " + repr(env['RELAX_PATH']) + ".\n")
174 for root, dirs, files in walk(env['RELAX_PATH'], topdown=False):
175 for file in files:
176 remove(path.join(root, file))
177 for file in dirs:
178 rmdir(path.join(root, file))
179 rmdir(env['RELAX_PATH'])
180
181
182 print("\n\n\n")
183