83 """ |
83 """ |
84 Module function to set the values of globals that need more than a |
84 Module function to set the values of globals that need more than a |
85 simple assignment. |
85 simple assignment. |
86 """ |
86 """ |
87 global modDir, pyModDir |
87 global modDir, pyModDir |
88 |
88 |
89 import sysconfig |
89 import sysconfig |
90 |
90 |
91 modDir = sysconfig.get_path('platlib') |
91 modDir = sysconfig.get_path("platlib") |
92 pyModDir = modDir |
92 pyModDir = modDir |
93 |
93 |
94 |
94 |
95 def copyTree(src, dst, filters, excludeDirs=None, excludePatterns=None): |
95 def copyTree(src, dst, filters, excludeDirs=None, excludePatterns=None): |
96 """ |
96 """ |
97 Copy files of a directory tree. |
97 Copy files of a directory tree. |
98 |
98 |
99 @param src name of the source directory |
99 @param src name of the source directory |
100 @param dst name of the destination directory |
100 @param dst name of the destination directory |
101 @param filters list of filter pattern determining the files to be copied |
101 @param filters list of filter pattern determining the files to be copied |
102 @param excludeDirs list of (sub)directories to exclude from copying |
102 @param excludeDirs list of (sub)directories to exclude from copying |
103 @param excludePatterns list of filter pattern determining the files to |
103 @param excludePatterns list of filter pattern determining the files to |
129 shutil.copy2(srcname, dstname) |
129 shutil.copy2(srcname, dstname) |
130 os.chmod(dstname, 0o644) |
130 os.chmod(dstname, 0o644) |
131 break |
131 break |
132 else: |
132 else: |
133 if os.path.isdir(srcname) and srcname not in excludeDirs: |
133 if os.path.isdir(srcname) and srcname not in excludeDirs: |
134 copyTree(srcname, dstname, filters, |
134 copyTree(srcname, dstname, filters, excludePatterns=excludePatterns) |
135 excludePatterns=excludePatterns) |
|
136 |
135 |
137 |
136 |
138 def cleanupSource(dirName): |
137 def cleanupSource(dirName): |
139 """ |
138 """ |
140 Cleanup the sources directory to get rid of leftover files |
139 Cleanup the sources directory to get rid of leftover files |
141 and directories. |
140 and directories. |
142 |
141 |
143 @param dirName name of the directory to prune (string) |
142 @param dirName name of the directory to prune (string) |
144 """ |
143 """ |
145 # step 1: delete the __pycache__ directory and all *.pyc files |
144 # step 1: delete the __pycache__ directory and all *.pyc files |
146 if os.path.exists(os.path.join(dirName, "__pycache__")): |
145 if os.path.exists(os.path.join(dirName, "__pycache__")): |
147 shutil.rmtree(os.path.join(dirName, "__pycache__")) |
146 shutil.rmtree(os.path.join(dirName, "__pycache__")) |
148 for name in [f for f in os.listdir(dirName) |
147 for name in [f for f in os.listdir(dirName) if fnmatch.fnmatch(f, "*.pyc")]: |
149 if fnmatch.fnmatch(f, "*.pyc")]: |
|
150 os.remove(os.path.join(dirName, name)) |
148 os.remove(os.path.join(dirName, name)) |
151 |
149 |
152 # step 2: descent into subdirectories and delete them if empty |
150 # step 2: descent into subdirectories and delete them if empty |
153 for name in os.listdir(dirName): |
151 for name in os.listdir(dirName): |
154 name = os.path.join(dirName, name) |
152 name = os.path.join(dirName, name) |
155 if os.path.isdir(name): |
153 if os.path.isdir(name): |
156 cleanupSource(name) |
154 cleanupSource(name) |
161 def cleanUp(): |
159 def cleanUp(): |
162 """ |
160 """ |
163 Uninstall the old eric debug client files. |
161 Uninstall the old eric debug client files. |
164 """ |
162 """ |
165 global pyModDir, installPackage |
163 global pyModDir, installPackage |
166 |
164 |
167 try: |
165 try: |
168 # Cleanup the install directories |
166 # Cleanup the install directories |
169 dirname = os.path.join(pyModDir, installPackage) |
167 dirname = os.path.join(pyModDir, installPackage) |
170 if os.path.exists(dirname): |
168 if os.path.exists(dirname): |
171 shutil.rmtree(dirname, True) |
169 shutil.rmtree(dirname, True) |
172 except OSError as msg: |
170 except OSError as msg: |
173 sys.stderr.write( |
171 sys.stderr.write("Error: {0}\nTry install with admin rights.\n".format(msg)) |
174 'Error: {0}\nTry install with admin rights.\n'.format(msg)) |
|
175 exit(7) |
172 exit(7) |
176 |
173 |
177 |
174 |
178 def shutilCopy(src, dst, perm=0o644): |
175 def shutilCopy(src, dst, perm=0o644): |
179 """ |
176 """ |
180 Wrapper function around shutil.copy() to ensure the permissions. |
177 Wrapper function around shutil.copy() to ensure the permissions. |
181 |
178 |
182 @param src source file name (string) |
179 @param src source file name (string) |
183 @param dst destination file name or directory name (string) |
180 @param dst destination file name or directory name (string) |
184 @param perm permissions to be set (integer) |
181 @param perm permissions to be set (integer) |
185 """ |
182 """ |
186 shutil.copy(src, dst) |
183 shutil.copy(src, dst) |
190 |
187 |
191 |
188 |
192 def installEricDebugClients(): |
189 def installEricDebugClients(): |
193 """ |
190 """ |
194 Actually perform the installation steps. |
191 Actually perform the installation steps. |
195 |
192 |
196 @return result code (integer) |
193 @return result code (integer) |
197 """ |
194 """ |
198 global distDir, doCleanup, sourceDir, modDir |
195 global distDir, doCleanup, sourceDir, modDir |
199 |
196 |
200 # set install prefix, if not None |
197 # set install prefix, if not None |
201 targetDir = ( |
198 targetDir = ( |
202 os.path.normpath(os.path.join(distDir, installPackage)) |
199 os.path.normpath(os.path.join(distDir, installPackage)) |
203 if distDir else |
200 if distDir |
204 os.path.join(modDir, installPackage) |
201 else os.path.join(modDir, installPackage) |
205 ) |
202 ) |
206 |
203 |
207 try: |
204 try: |
208 # Install the files |
205 # Install the files |
209 # copy the various parts of eric debug clients |
206 # copy the various parts of eric debug clients |
210 copyTree( |
207 copyTree( |
211 os.path.join(eric7SourceDir, "DebugClients"), |
208 os.path.join(eric7SourceDir, "DebugClients"), |
212 targetDir, |
209 targetDir, |
213 ['*.py', '*.pyc', '*.pyo', '*.pyw'], |
210 ["*.py", "*.pyc", "*.pyo", "*.pyw"], |
214 excludePatterns=["eric7config.py*"]) |
211 excludePatterns=["eric7config.py*"], |
215 |
212 ) |
|
213 |
216 # copy the license file |
214 # copy the license file |
217 shutilCopy(os.path.join(sourceDir, "docs", "LICENSE.GPL3"), targetDir) |
215 shutilCopy(os.path.join(sourceDir, "docs", "LICENSE.GPL3"), targetDir) |
218 |
216 |
219 except OSError as msg: |
217 except OSError as msg: |
220 sys.stderr.write( |
218 sys.stderr.write("Error: {0}\nTry install with admin rights.\n".format(msg)) |
221 'Error: {0}\nTry install with admin rights.\n'.format(msg)) |
219 return 7 |
222 return(7) |
220 |
223 |
|
224 return 0 |
221 return 0 |
225 |
222 |
226 |
223 |
227 def main(argv): |
224 def main(argv): |
228 """ |
225 """ |
233 import getopt |
230 import getopt |
234 |
231 |
235 # Parse the command line. |
232 # Parse the command line. |
236 global progName, modDir, doCleanup, doCompile, distDir |
233 global progName, modDir, doCleanup, doCompile, distDir |
237 global sourceDir, eric7SourceDir |
234 global sourceDir, eric7SourceDir |
238 |
235 |
239 if sys.version_info < (3, 7, 0) or sys.version_info >= (4, 0, 0): |
236 if sys.version_info < (3, 7, 0) or sys.version_info >= (4, 0, 0): |
240 print('Sorry, the eric debugger requires Python 3.7 or better' |
237 print("Sorry, the eric debugger requires Python 3.7 or better" " for running.") |
241 ' for running.') |
|
242 exit(5) |
238 exit(5) |
243 |
239 |
244 progName = os.path.basename(argv[0]) |
240 progName = os.path.basename(argv[0]) |
245 |
241 |
246 if os.path.dirname(argv[0]): |
242 if os.path.dirname(argv[0]): |
247 os.chdir(os.path.dirname(argv[0])) |
243 os.chdir(os.path.dirname(argv[0])) |
248 |
244 |
249 initGlobals() |
245 initGlobals() |
250 |
246 |
251 try: |
247 try: |
252 if sys.platform.startswith("win"): |
248 if sys.platform.startswith("win"): |
253 optlist, args = getopt.getopt( |
249 optlist, args = getopt.getopt(argv[1:], "chzd:", ["help"]) |
254 argv[1:], "chzd:", ["help"]) |
|
255 elif sys.platform == "darwin": |
250 elif sys.platform == "darwin": |
256 optlist, args = getopt.getopt( |
251 optlist, args = getopt.getopt(argv[1:], "chzd:i:", ["help"]) |
257 argv[1:], "chzd:i:", ["help"]) |
|
258 else: |
252 else: |
259 optlist, args = getopt.getopt( |
253 optlist, args = getopt.getopt(argv[1:], "chzd:i:", ["help"]) |
260 argv[1:], "chzd:i:", ["help"]) |
|
261 except getopt.GetoptError as err: |
254 except getopt.GetoptError as err: |
262 print(err) |
255 print(err) |
263 usage() |
256 usage() |
264 |
257 |
265 for opt, arg in optlist: |
258 for opt, arg in optlist: |
271 distDir = os.path.normpath(arg) |
264 distDir = os.path.normpath(arg) |
272 elif opt == "-c": |
265 elif opt == "-c": |
273 doCleanup = False |
266 doCleanup = False |
274 elif opt == "-z": |
267 elif opt == "-z": |
275 doCompile = False |
268 doCompile = False |
276 |
269 |
277 installFromSource = not os.path.isdir(sourceDir) |
270 installFromSource = not os.path.isdir(sourceDir) |
278 if installFromSource: |
271 if installFromSource: |
279 sourceDir = os.path.abspath("..") |
272 sourceDir = os.path.abspath("..") |
280 |
273 |
281 eric7SourceDir = ( |
274 eric7SourceDir = ( |
282 os.path.join(sourceDir, "eric7") |
275 os.path.join(sourceDir, "eric7") |
283 if os.path.exists(os.path.join(sourceDir, "eric7")) else |
276 if os.path.exists(os.path.join(sourceDir, "eric7")) |
284 os.path.join(sourceDir, "src", "eric7") |
277 else os.path.join(sourceDir, "src", "eric7") |
285 ) |
278 ) |
286 |
279 |
287 # cleanup source if installing from source |
280 # cleanup source if installing from source |
288 if installFromSource: |
281 if installFromSource: |
289 print("Cleaning up source ...") |
282 print("Cleaning up source ...") |
290 cleanupSource(os.path.join(eric7SourceDir, "DebugClients")) |
283 cleanupSource(os.path.join(eric7SourceDir, "DebugClients")) |
291 print() |
284 print() |
292 |
285 |
293 # cleanup old installation |
286 # cleanup old installation |
294 try: |
287 try: |
295 if doCleanup: |
288 if doCleanup: |
296 print("Cleaning up old installation ...") |
289 print("Cleaning up old installation ...") |
297 if distDir: |
290 if distDir: |
298 shutil.rmtree(distDir, True) |
291 shutil.rmtree(distDir, True) |
299 else: |
292 else: |
300 cleanUp() |
293 cleanUp() |
301 except OSError as msg: |
294 except OSError as msg: |
302 sys.stderr.write('Error: {0}\nTry install as root.\n'.format(msg)) |
295 sys.stderr.write("Error: {0}\nTry install as root.\n".format(msg)) |
303 exit(7) |
296 exit(7) |
304 |
297 |
305 if doCompile: |
298 if doCompile: |
306 print("\nCompiling source files ...") |
299 print("\nCompiling source files ...") |
307 skipRe = re.compile(r"DebugClients[\\/]Python[\\/]") |
300 skipRe = re.compile(r"DebugClients[\\/]Python[\\/]") |
309 if distDir: |
302 if distDir: |
310 compileall.compile_dir( |
303 compileall.compile_dir( |
311 os.path.join(eric7SourceDir, "DebugClients"), |
304 os.path.join(eric7SourceDir, "DebugClients"), |
312 ddir=os.path.join(distDir, modDir, installPackage), |
305 ddir=os.path.join(distDir, modDir, installPackage), |
313 rx=skipRe, |
306 rx=skipRe, |
314 quiet=True) |
307 quiet=True, |
|
308 ) |
315 else: |
309 else: |
316 compileall.compile_dir( |
310 compileall.compile_dir( |
317 os.path.join(eric7SourceDir, "DebugClients"), |
311 os.path.join(eric7SourceDir, "DebugClients"), |
318 ddir=os.path.join(modDir, installPackage), |
312 ddir=os.path.join(modDir, installPackage), |
319 rx=skipRe, |
313 rx=skipRe, |
320 quiet=True) |
314 quiet=True, |
|
315 ) |
321 sys.stdout = sys.__stdout__ |
316 sys.stdout = sys.__stdout__ |
322 print("\nInstalling eric debug clients ...") |
317 print("\nInstalling eric debug clients ...") |
323 res = installEricDebugClients() |
318 res = installEricDebugClients() |
324 |
319 |
325 print("\nInstallation complete.") |
320 print("\nInstallation complete.") |
326 print() |
321 print() |
327 |
322 |
328 exit(res) |
323 exit(res) |
329 |
324 |
330 |
325 |
331 if __name__ == "__main__": |
326 if __name__ == "__main__": |
332 try: |
327 try: |
333 main(sys.argv) |
328 main(sys.argv) |
334 except SystemExit: |
329 except SystemExit: |
335 raise |
330 raise |
336 except Exception: |
331 except Exception: |
337 print("""An internal error occured. Please report all the output""" |
332 print( |
338 """ of the program,\nincluding the following traceback, to""" |
333 """An internal error occured. Please report all the output""" |
339 """ eric-bugs@eric-ide.python-projects.org.\n""") |
334 """ of the program,\nincluding the following traceback, to""" |
|
335 """ eric-bugs@eric-ide.python-projects.org.\n""" |
|
336 ) |
340 raise |
337 raise |
341 |
338 |
342 # |
339 # |
343 # eflag: noqa = M801 |
340 # eflag: noqa = M801 |