-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvert.py
More file actions
executable file
·93 lines (70 loc) · 2.53 KB
/
convert.py
File metadata and controls
executable file
·93 lines (70 loc) · 2.53 KB
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
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/python3
import os
import sys
from collections import deque
from src.options import options as prog_options
from src.conversion import conversion
from src.metrics import ExitStatus
from src.metadata.keep import ConvertKeep
def help() :
print(f"{sys.argv[0]} [--dry-run] [--no-remove] [--keep-threshold <keep>] [--default-keep <keep>] [--prometheus-metrics] [--metrics-path <dir>] <source> <destination>")
def main() :
args = deque(sys.argv[1:])
if len(args) > 0 and args[0] in ['-h', '--help'] :
help()
sys.exit(0)
if len(args) > 0 and args[0] == '--dry-run' :
prog_options.dry_run = True
args.popleft()
if len(args) > 0 and args[0] == '--no-remove' :
prog_options.can_remove = False
args.popleft()
if len(args) > 1 and args[0] == '--keep-threshold' :
args.popleft()
keep_repr = args.popleft().lower()
if keep_repr != 'all' :
keep = ConvertKeep.parse(keep_repr)
if keep == None :
print(f"Bad keep threshold : {keep_repr}")
sys.exit(1)
prog_options.keep_treshold = keep
if len(args) > 1 and args[0] == '--default-keep' :
args.popleft()
keep = ConvertKeep.parse(args.popleft().lower())
if keep == None :
print(f"Bad default Convert-Keep value : {keep_repr}")
sys.exit(1)
prog_options.default_keep = keep
if len(args) > 0 and args[0] == '--prometheus-metrics' :
args.popleft()
prog_options.metrics_enabled = True
if len(args) > 1 and args[0] == '--metrics-path' :
args.popleft()
prog_options.matrics_path = args.popleft()
if len(args) != 2 :
help()
sys.exit(1)
source_dir = args.popleft()
dest_dir = args.popleft()
if source_dir.endswith('/') :
source_dir = source_dir[:-1]
if dest_dir.endswith('/') :
dest_dir = dest_dir[:-1]
metrics = conversion(source_dir, dest_dir)
print()
if not prog_options.metrics_enabled :
metrics.summary()
elif prog_options.dry_run :
print(' --- Metrics ---')
metrics.print()
else :
metrics.summary()
filepath = os.path.join(prog_options.matrics_path, 'mp3conv.prom')
filepath_tmp = f"{filepath}.tmp"
with open(filepath_tmp, 'w') as f :
metrics.print(f)
os.rename(filepath_tmp, filepath)
if metrics.status != ExitStatus.SUCCESS :
sys.exit(1)
if __name__== '__main__' :
main()