|
11 | 11 | # files. |
12 | 12 | # * recreate_readme: recreate readme to update translation progress. |
13 | 13 | # * regenerate_tx_config: recreate configuration for all resources. |
| 14 | +# * generate_commit_msg: generates commit message with co-authors |
14 | 15 |
|
15 | 16 | fromargparseimportArgumentParser |
16 | 17 | fromcollectionsimportCounter |
17 | 18 | importos |
18 | 19 | fromdataclassesimportdataclass |
19 | 20 | frompathlibimportPath |
20 | 21 | fromreimportmatch,search |
21 | | -fromsubprocessimportcall,run |
| 22 | +fromsubprocessimportcall,run,CalledProcessError |
22 | 23 | importsys |
23 | 24 | fromurllib.parseimportunquote |
24 | 25 | fromwarningsimportwarn |
25 | 26 |
|
| 27 | +frompolibimportpofile,POFile |
| 28 | + |
26 | 29 | LANGUAGE='pl' |
27 | 30 |
|
28 | 31 |
|
@@ -273,9 +276,63 @@ def average(averages, weights): |
273 | 276 | ''' |
274 | 277 | ) |
275 | 278 |
|
| 279 | +defgenerate_commit_msg(): |
| 280 | +"""Generate a commit message |
| 281 | + Parses staged files and generates a commit message with Last-Translator's as |
| 282 | + co-authors. |
| 283 | + """ |
| 284 | +translators:set[str]=set() |
276 | 285 |
|
277 | | -if__name__=="__main__": |
278 | | -RUNNABLE_SCRIPTS= ('fetch','recreate_tx_config','recreate_readme','warn_about_files_to_delete') |
| 286 | +result=run( |
| 287 | + ['git','diff','--cached','--name-only','--diff-filter=ACM'], |
| 288 | +capture_output=True, |
| 289 | +text=True, |
| 290 | +check=True, |
| 291 | + ) |
| 292 | +staged= [ |
| 293 | +filenameforfilenameinresult.stdout.splitlines()iffilename.endswith('.po') |
| 294 | + ] |
| 295 | + |
| 296 | +forfileinstaged: |
| 297 | +staged_file=run( |
| 298 | + ['git','show',f':{file}'],capture_output=True,text=True,check=True |
| 299 | + ).stdout |
| 300 | +try: |
| 301 | +old_file=run( |
| 302 | + ['git','show',f'HEAD:{file}'], |
| 303 | +capture_output=True, |
| 304 | +text=True, |
| 305 | +check=True, |
| 306 | + ).stdout |
| 307 | +exceptCalledProcessError: |
| 308 | +old_file='' |
| 309 | + |
| 310 | +new_po=pofile(staged_file) |
| 311 | +old_po=pofile(old_file)ifold_fileelsePOFile() |
| 312 | +old_entries= {entry.msgid:entry.msgstrforentryinold_po} |
| 313 | + |
| 314 | +forentryinnew_po: |
| 315 | +ifentry.msgstrand ( |
| 316 | +entry.msgidnotinold_entries |
| 317 | +orold_entries[entry.msgid]!=entry.msgstr |
| 318 | + ): |
| 319 | +translator=new_po.metadata.get('Last-Translator') |
| 320 | +translator=translator.split(',')[0].strip() |
| 321 | +iftranslator: |
| 322 | +translators.add(f'Co-Authored-By:{translator}') |
| 323 | +break |
| 324 | + |
| 325 | +print('Update translation from Transifex\n\n'+'\n'.join(translators)) |
| 326 | + |
| 327 | + |
| 328 | +if__name__=='__main__': |
| 329 | +RUNNABLE_SCRIPTS= ( |
| 330 | +'fetch', |
| 331 | +'recreate_tx_config', |
| 332 | +'recreate_readme', |
| 333 | +'warn_about_files_to_delete', |
| 334 | +'generate_commit_msg', |
| 335 | + ) |
279 | 336 |
|
280 | 337 | parser=ArgumentParser() |
281 | 338 | parser.add_argument('cmd',nargs=1,choices=RUNNABLE_SCRIPTS) |
|