16 |
16 |
17 def cleanupSource(dirName): |
17 def cleanupSource(dirName): |
18 """ |
18 """ |
19 Cleanup the sources directory to get rid of leftover files |
19 Cleanup the sources directory to get rid of leftover files |
20 and directories. |
20 and directories. |
21 |
21 |
22 @param dirName name of the directory to prune (string) |
22 @param dirName name of the directory to prune (string) |
23 """ |
23 """ |
24 # step 1: delete all Ui_*.py files without a corresponding |
24 # step 1: delete all Ui_*.py files without a corresponding |
25 # *.ui file |
25 # *.ui file |
26 dirListing = os.listdir(dirName) |
26 dirListing = os.listdir(dirName) |
27 for formName, sourceName in [ |
27 for formName, sourceName in [ |
28 (f.replace('Ui_', "").replace(".py", ".ui"), f) |
28 (f.replace("Ui_", "").replace(".py", ".ui"), f) |
29 for f in dirListing if fnmatch.fnmatch(f, "Ui_*.py")]: |
29 for f in dirListing |
|
30 if fnmatch.fnmatch(f, "Ui_*.py") |
|
31 ]: |
30 if not os.path.exists(os.path.join(dirName, formName)): |
32 if not os.path.exists(os.path.join(dirName, formName)): |
31 os.remove(os.path.join(dirName, sourceName)) |
33 os.remove(os.path.join(dirName, sourceName)) |
32 if os.path.exists(os.path.join(dirName, sourceName + "c")): |
34 if os.path.exists(os.path.join(dirName, sourceName + "c")): |
33 os.remove(os.path.join(dirName, sourceName + "c")) |
35 os.remove(os.path.join(dirName, sourceName + "c")) |
34 |
36 |
35 # step 2: delete the __pycache__ directory and all remaining *.pyc files |
37 # step 2: delete the __pycache__ directory and all remaining *.pyc files |
36 if os.path.exists(os.path.join(dirName, "__pycache__")): |
38 if os.path.exists(os.path.join(dirName, "__pycache__")): |
37 shutil.rmtree(os.path.join(dirName, "__pycache__")) |
39 shutil.rmtree(os.path.join(dirName, "__pycache__")) |
38 for name in [f for f in os.listdir(dirName) |
40 for name in [f for f in os.listdir(dirName) if fnmatch.fnmatch(f, "*.pyc")]: |
39 if fnmatch.fnmatch(f, "*.pyc")]: |
|
40 os.remove(os.path.join(dirName, name)) |
41 os.remove(os.path.join(dirName, name)) |
41 |
42 |
42 # step 3: descent into subdirectories and delete them if empty |
43 # step 3: descent into subdirectories and delete them if empty |
43 for name in os.listdir(dirName): |
44 for name in os.listdir(dirName): |
44 name = os.path.join(dirName, name) |
45 name = os.path.join(dirName, name) |
45 if os.path.isdir(name): |
46 if os.path.isdir(name): |
46 cleanupSource(name) |
47 cleanupSource(name) |
55 @param argv the list of command line arguments. |
56 @param argv the list of command line arguments. |
56 """ |
57 """ |
57 print("Cleaning up source ...") |
58 print("Cleaning up source ...") |
58 sourceDir = os.path.dirname(os.path.dirname(__file__)) or "." |
59 sourceDir = os.path.dirname(os.path.dirname(__file__)) or "." |
59 cleanupSource(sourceDir) |
60 cleanupSource(sourceDir) |
60 |
61 |
61 |
62 |
62 if __name__ == "__main__": |
63 if __name__ == "__main__": |
63 try: |
64 try: |
64 main(sys.argv) |
65 main(sys.argv) |
65 except SystemExit: |
66 except SystemExit: |
66 raise |
67 raise |
67 except Exception: |
68 except Exception: |
68 print( |
69 print( |
69 "\nAn internal error occured. Please report all the output of the" |
70 "\nAn internal error occured. Please report all the output of the" |
70 " program, \nincluding the following traceback, to" |
71 " program, \nincluding the following traceback, to" |
71 " eric-bugs@eric-ide.python-projects.org.\n") |
72 " eric-bugs@eric-ide.python-projects.org.\n" |
|
73 ) |
72 raise |
74 raise |
73 |
75 |
74 # |
76 # |
75 # eflag: noqa = M801 |
77 # eflag: noqa = M801 |