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