-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
61 lines (46 loc) · 1.61 KB
/
main.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
# pylint: disable=missing-docstring
import platform
import sys
from rich import print as pr
from analyzer.file_processing import process_directory
from analyzer.utils.logger import setup_logging
from analyzer.utils.parser import parse_args
def main():
arguments = parse_args()
if not arguments or not arguments.target_dir:
sys.exit(1)
setup_logging(
log_file=arguments.log_file,
target_dir=arguments.target_dir,
size_threshold=arguments.size_threshold,
delete_files=arguments.delete_files,
)
try:
process_directory(
dir_path=arguments.target_dir,
size_threshold=str(arguments.size_threshold),
delete_files=arguments.delete_files,
log_file=arguments.log_file,
)
finally:
if arguments.log_file is not None:
# Close log file
sys.stdout.close()
sys.stderr.close()
# Reset back to stanrds
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
def is_valid_environment() -> bool:
if platform.system() != "Linux":
pr("[bold red]Error:[/] This tool is designed to run on Linux systems only.")
pr("[bold red]Please run this script on a Linux system to proceed.[/]")
return False
if platform.python_version_tuple()[0] < "3":
pr("[bold red]Error:[/] This tool is designed to run on Python 3.")
pr("[bold red]Please use Python 3 to run this script.[/]")
return False
return True
if __name__ == "__main__":
if not is_valid_environment():
sys.exit(1)
main()