forked from python/python-docs-tr
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprogress.py
More file actions
65 lines (52 loc) · 1.7 KB
/
progress.py
File metadata and controls
65 lines (52 loc) · 1.7 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
import os
import argparse
import contextlib
import glob
import polib
parser = argparse.ArgumentParser()
parser.add_argument(
"subject", nargs="?", default=None, help="Subject to check (file or directory)"
)
parser.add_argument("-c", "--completed", action="store_true")
parser.add_argument("-t", "--threshold", type=int, default=90)
args = parser.parse_args()
PO_DIR = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
"..",
)
)
is_file = False
with contextlib.suppress(TypeError):
if os.path.isdir(args.subject):
PO_DIR = os.path.abspath(args.subject)
elif os.path.isfile(args.subject):
is_file = True
args.subject = (
args.subject
if os.path.isabs(args.subject)
else os.path.join(PO_DIR, args.subject)
)
else:
print("Invalid subject, showing all files.")
def main():
files = []
if is_file:
po = polib.pofile(args.subject)
return [[args.subject.replace(PO_DIR, ""), po.percent_translated()]]
for pofilename in glob.glob(f"{PO_DIR}**/*.po"):
po = polib.pofile(pofilename)
files.append((pofilename.replace(PO_DIR, ""), po.percent_translated()))
for pofilename in glob.glob(f"{PO_DIR}**/**/*.po"):
po = polib.pofile(pofilename)
files.append((pofilename.replace(PO_DIR, ""), po.percent_translated()))
return files
if __name__ == "__main__":
results = [f"{file[0]}: {file[1]}%" for file in main()]
for result in results:
if args.completed and int(result.split(" ")[1].replace("%", "")) > min(
args.threshold, 100
):
print(result)
elif not args.completed:
print(result)