Passed
Push — master ( 416358...d9c5dd )
by Max
01:22
created

mutmut_helper   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 11

3 Functions

Rating   Name   Duplication   Size   Complexity  
A cache_files() 0 12 5
A untracked_files() 0 8 3
A backup_files() 0 5 3
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