Add mutually exclusive arguments --file and --all
Only one of these arguments must be supplied, or argparse raises an error.
This commit is contained in:
parent
4a93288353
commit
b14f3780d4
|
|
@ -7,7 +7,8 @@ by calling within the ./po folder:
|
||||||
python ../lang-extract.py --no-missing -s -o Firmware.pot ../../Firmware/[a-zA-Z]*.[ch]* ../../Firmware/mmu2/[a-zA-Z]*.[ch]*
|
python ../lang-extract.py --no-missing -s -o Firmware.pot ../../Firmware/[a-zA-Z]*.[ch]* ../../Firmware/mmu2/[a-zA-Z]*.[ch]*
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import argparse
|
||||||
|
from sys import stderr, exit
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import polib
|
import polib
|
||||||
from polib import POFile
|
from polib import POFile
|
||||||
|
|
@ -19,7 +20,21 @@ POT_REFERENCE: POFile = polib.pofile(PO_DIR/'Firmware.pot')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
PO_FILE_LIST = sorted(PO_DIR.glob('**/*.po'))
|
global PO_FILE_LIST
|
||||||
|
ap = argparse.ArgumentParser()
|
||||||
|
group = ap.add_mutually_exclusive_group(required=True)
|
||||||
|
group.add_argument('-f', '--file', help='File path for a single PO file to update Example: ./po/Firmware_cs.po')
|
||||||
|
group.add_argument('--all', action='store_true', help='Update all PO files at once')
|
||||||
|
args = ap.parse_args()
|
||||||
|
|
||||||
|
if args.all:
|
||||||
|
PO_FILE_LIST = sorted(PO_DIR.glob('**/*.po'))
|
||||||
|
elif args.file:
|
||||||
|
if Path(args.file).is_file():
|
||||||
|
PO_FILE_LIST.append(Path(args.file))
|
||||||
|
else:
|
||||||
|
print("{}: file does not exist or is not a regular file".format(args.file), file=stderr)
|
||||||
|
return 1
|
||||||
|
|
||||||
for po_file in PO_FILE_LIST:
|
for po_file in PO_FILE_LIST:
|
||||||
po = polib.pofile(po_file)
|
po = polib.pofile(po_file)
|
||||||
|
|
@ -31,4 +46,4 @@ if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
main()
|
main()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
sys.exit(-1)
|
exit(-1)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue