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