Total Complexity | 11 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import os.path |
||
2 | import subprocess |
||
3 | |||
4 | |||
5 | def untracked_files(): |
||
6 | for file_ in ( |
||
7 | subprocess.run(["hg", "status", "--unknown"], capture_output=True) |
||
8 | .stdout.decode() |
||
9 | .split("\n") |
||
10 | ): |
||
11 | if file_: |
||
12 | yield file_[2:] |
||
13 | |||
14 | |||
15 | def backup_files(file_list): |
||
16 | for file_ in file_list: |
||
17 | fn, ext = os.path.splitext(file_) |
||
18 | if ext == ".bak": |
||
19 | yield fn |
||
20 | |||
21 | |||
22 | def cache_files(file_list): |
||
23 | for file_ in file_list: |
||
24 | dirname, fn = os.path.split(file_) |
||
25 | cache_dir = os.path.join(dirname, "__pycache__") |
||
26 | prefix = fn + os.extsep |
||
27 | try: |
||
28 | cache_files = os.listdir(cache_dir) |
||
29 | except FileNotFoundError: |
||
30 | continue |
||
31 | for cache_file in cache_files: |
||
32 | if cache_file.startswith(prefix): |
||
33 | yield os.path.join(cache_dir, cache_file) |
||
34 | |||
35 | |||
36 | for cache_file in cache_files(backup_files(untracked_files())): |
||
37 | os.remove(cache_file) |
||
38 |