|
6 | 6 |
|
7 | 7 |
|
8 | 8 | parser=argparse.ArgumentParser()
|
9 |
| -parser.add_argument( |
10 |
| -"subject",nargs="?",default=None,help="Subject to check (file or directory)" |
11 |
| -) |
| 9 | +parser.add_argument("subject",nargs="?",default=None,help="Subject to check (file or directory)") |
12 | 10 | parser.add_argument("-c","--completed",action="store_true")
|
13 | 11 | parser.add_argument("-t","--threshold",type=int,default=90)
|
14 | 12 | args=parser.parse_args()
|
|
28 | 26 |
|
29 | 27 | elifos.path.isfile(args.subject):
|
30 | 28 | is_file=True
|
31 |
| -args.subject= ( |
32 |
| -args.subject |
33 |
| -ifos.path.isabs(args.subject) |
34 |
| -elseos.path.join(PO_DIR,args.subject) |
35 |
| - ) |
| 29 | +args.org_subject=args.subject |
| 30 | +args.subject=args.subjectifos.path.isabs(args.subject)elseos.path.join(PO_DIR,args.subject) |
36 | 31 |
|
37 | 32 | else:
|
38 | 33 | print("Invalid subject, showing all files.")
|
39 | 34 |
|
40 | 35 |
|
| 36 | +defpo_stats(pofilename): |
| 37 | +po=polib.pofile(pofilename) |
| 38 | +translated=len(po.translated_entries()) |
| 39 | +total=len(po)+translated |
| 40 | +return (po.percent_translated(),translated,total) |
| 41 | + |
| 42 | + |
41 | 43 | defmain():
|
42 | 44 | files= []
|
| 45 | +translated= [] |
| 46 | +total= [] |
43 | 47 | ifis_file:
|
44 | 48 | po=polib.pofile(args.subject)
|
45 |
| -return[[args.subject.replace(PO_DIR,""),po.percent_translated()]] |
| 49 | +returnos.path.relpath(args.org_subject),po.percent_translated() |
46 | 50 |
|
47 | 51 | forpofilenameinglob.glob(f"{PO_DIR}**/*.po"):
|
48 |
| -po=polib.pofile(pofilename) |
49 |
| -files.append((pofilename.replace(PO_DIR,""),po.percent_translated())) |
| 52 | +stats=po_stats(pofilename) |
| 53 | +translated.append(stats[1]) |
| 54 | +total.append(stats[2]) |
| 55 | +files.append((os.path.relpath(pofilename).replace("\\","/"),stats[0])) |
50 | 56 | forpofilenameinglob.glob(f"{PO_DIR}**/**/*.po"):
|
51 |
| -po=polib.pofile(pofilename) |
52 |
| -files.append((pofilename.replace(PO_DIR,""),po.percent_translated())) |
53 |
| -returnfiles |
| 57 | +stats=po_stats(pofilename) |
| 58 | +translated.append(stats[1]) |
| 59 | +total.append(stats[2]) |
| 60 | +files.append((os.path.relpath(pofilename).replace("\\","/"),stats[0])) |
| 61 | +returnfiles,round(sum(translated)/sum(total)*100,1) |
54 | 62 |
|
55 | 63 |
|
56 | 64 | if__name__=="__main__":
|
57 |
| -results= [f"{file[0]}:{file[1]}%"forfileinmain()] |
58 |
| - |
59 |
| -forresultinresults: |
60 |
| -ifargs.completedandint(result.split(" ")[1].replace("%",""))>min( |
61 |
| -args.threshold,100 |
62 |
| - ): |
63 |
| -print(result) |
64 |
| -elifnotargs.completed: |
65 |
| -print(result) |
| 65 | +files,weighted_progress=main() |
| 66 | +ifnotargs.subject: |
| 67 | +print("No subject provided, showing general progress") |
| 68 | +print(f"{len([fileforfileinfilesiffile[1]>min(args.threshold,100)])} /{len(files)} files completed") |
| 69 | +print(f"Weighted progress:{weighted_progress}%\n") |
| 70 | + |
| 71 | +ifargs.completed: |
| 72 | +print("Completed files:") |
| 73 | +completed_files= [fileforfileinfilesiffile[1]>min(args.threshold,100)] |
| 74 | +forfile,percentageincompleted_files: |
| 75 | +print(f"{file}:{percentage}%") |
| 76 | +elifis_file: |
| 77 | +print(f"{files}:{weighted_progress}%") |
| 78 | + |
| 79 | +else: |
| 80 | +print(f"{len([fileforfileinfilesiffile[1]>min(args.threshold,100)])} /{len(files)} files completed") |
| 81 | +print(f"Weighted progress:{weighted_progress}%\n") |
| 82 | + |
| 83 | +ifargs.completed: |
| 84 | +print("Completed files:") |
| 85 | +completed_files= [fileforfileinfilesiffile[1]>min(args.threshold,100)] |
| 86 | +forfile,percentageincompleted_files: |
| 87 | +print(f"{file}:{percentage}%") |