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 " + `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 " + `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 " + `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 " + `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 " + `env['SYMLINK']` + " already exists.\n\n")
80 return
81
82
83
84
85
86
87 try:
88 print "\nCopying all files in " + `getcwd()` + " to " + `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 " + `env['RELAX_PATH']` + ".\n\n")
97
98
99 else:
100 sys.stderr.write("OSError: [Errno " + `message.errno` + "] " + message.strerror + ": " + `message.filename` + "\n\n")
101
102
103 return
104
105
106 if env['SYMLINK_FLAG']:
107 print "\nCreating the symbolic link from " + `env['RELAX_PATH'] + sep + 'relax'` + " to " + `env['SYMLINK']` + "."
108 symlink(env['RELAX_PATH'] + sep + 'relax', env['SYMLINK'])
109
110
111
112
113
114
115 print "\nRunning relax to create the byte-compiled *.pyc files."
116 system(env['SYMLINK'] + " --test")
117
118
119 print "\n\n\n"
120
121
123 """relax deinstallation function (a Builder action)."""
124
125
126
127
128 print
129 print "######################"
130 print "# Uninstalling relax #"
131 print "######################\n\n"
132 print "Uninstalling the program relax from the directory " + `env['INSTALL_PATH']` + "\n\n"
133
134
135
136
137
138
139 if not access(env['INSTALL_PATH'], F_OK):
140 sys.stderr.write("Cannot uninstall relax, the installation path " + `env['INSTALL_PATH']` + " does not exist.\n\n")
141 return
142
143
144 if not access(env['BIN_PATH'], F_OK):
145 sys.stderr.write("Cannot uninstall relax, the directory " + `env['BIN_PATH']` + " does not exist.\n\n")
146 return
147
148
149 if not access(env['RELAX_PATH'], F_OK):
150 sys.stderr.write("Cannot uninstall relax, the directory " + `env['RELAX_PATH']` + " does not exist.\n\n")
151 return
152
153
154 if env['SYMLINK_FLAG']:
155 try:
156 lstat(env['SYMLINK'])
157 except OSError:
158 sys.stderr.write("Cannot uninstall relax, the file " + `env['SYMLINK']` + " does not exist.\n\n")
159 return
160
161
162
163
164
165
166 if env['SYMLINK_FLAG']:
167 print "\nRemoving the symbolic link " + `env['SYMLINK']` + "."
168 remove(env['SYMLINK'])
169
170
171 print "\nRemoving the entire directory " + `env['RELAX_PATH']` + ".\n"
172 for root, dirs, files in walk(env['RELAX_PATH'], topdown=False):
173 for file in files:
174 remove(path.join(root, file))
175 for file in dirs:
176 rmdir(path.join(root, file))
177 rmdir(env['RELAX_PATH'])
178
179
180 print "\n\n\n"
181