forked from Spyro-Soft/scargo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean.py
executable file
·83 lines (64 loc) · 1.74 KB
/
clean.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
# #
# @copyright Copyright (C) 2022 SpyroSoft Solutions S.A. All rights reserved.
# #
import argparse
import os
import subprocess
from typing import List, Optional, Sequence
OUTPUT_FILES = [
"build",
"out",
".coverage",
]
def get_cmdline_arguments() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Cleans build and optionally cache")
parser.add_argument(
"-a",
"--all",
action="store_true",
dest="remove_cache",
help="If flag is use, all cache will be removed",
)
parser.add_argument(
"-d",
"--directory",
type=list_files,
default="",
dest="list_of_files",
help="Set custom directory for cleaning.",
)
parser.add_argument(
"-f",
"--file",
type=list_files,
default="",
dest="list_of_files",
help="Run lint for one file",
)
return parser.parse_args()
def list_files(path: str) -> Optional[List[str]]:
if path:
if os.path.isdir(path):
return [path]
raise argparse.ArgumentTypeError(
f"readable_dir:schemas/{path} is not a valid path"
)
return None
def clean(output_file_names: Sequence[str]) -> None:
try:
command = ["py3clean", "."]
subprocess.check_call(command)
except subprocess.CalledProcessError:
print("Pyclean fail")
for item in output_file_names:
subprocess.run(["rm", "-rf", item], check=True)
def main() -> None:
args = get_cmdline_arguments()
if args.list_of_files:
output_files = [args.list_of_files]
else:
output_files = OUTPUT_FILES
clean(output_files)
if __name__ == "__main__":
main()