start to use choice lists (argsparser)

svn: r20716
This commit is contained in:
Jérôme Rapinat 2012-12-01 10:10:44 +00:00
parent f4abcb7f66
commit 2ca04af319

View File

@ -367,12 +367,12 @@ def main():
# need at least one argument (sv.po, de.po, etc ...) # need at least one argument (sv.po, de.po, etc ...)
# lang.po files maintenance # lang.po files maintenance
update.add_argument("-m", "--merge", update.add_argument("-m", "--merge", dest="merge",
type=int, dest="merge", default=[file for file in os.listdir('.') if file.endswith('.po')], choices=[file for file in os.listdir('.') if file.endswith('.po')],
help="merge lang.po files with last catalog") help="merge lang.po files with last catalog")
update.add_argument("-k", "--check", update.add_argument("-k", "--check", dest="check",
type=int, dest="check", default=[file for file in os.listdir('.') if file.endswith('.po')], choices=[file for file in os.listdir('.') if file.endswith('.po')],
help="check lang.po files") help="check lang.po files")
# testing stage # testing stage
@ -410,10 +410,10 @@ def main():
if args.clean: if args.clean:
clean() clean()
if args.merge and sys.argv[2:] in namespace.merge: if args.merge:
merge(sys.argv[2:]) merge(sys.argv[2:])
if args.check and sys.argv[2:] in namespace.check: if args.check:
check(sys.argv[2:]) check(sys.argv[2:])
if args.untranslated and sys.argv[2:]: if args.untranslated and sys.argv[2:]:
@ -595,36 +595,31 @@ def clean():
os.unlink('tmpfiles') os.unlink('tmpfiles')
print ("Remove 'tmpfiles'") print ("Remove 'tmpfiles'")
def merge(args): def merge(arg):
""" """
Merge messages with 'gramps.pot' Merge messages with 'gramps.pot'
""" """
for arg in args:
if arg[-3:] == '.po': arg = arg[0]
print ('Merge %(lang)s with current template' % {'lang': arg})
os.system('''%(msgmerge)s --no-wrap %(lang)s gramps.pot -o updated_%(lang)s''' \ print ('Merge %(lang)s with current template' % {'lang': arg})
% {'msgmerge': msgmergeCmd, 'lang': arg}) os.system('''%(msgmerge)s --no-wrap %(lang)s gramps.pot -o updated_%(lang)s''' \
print ("Updated file: 'updated_%(lang)s'." % {'lang': arg}) % {'msgmerge': msgmergeCmd, 'lang': arg})
else: print ("Updated file: 'updated_%(lang)s'." % {'lang': arg})
print ("Please, try to set an argument with .po extension like "
"'%(arg)s.po'." % {'arg': arg})
def check(args): def check(arg):
""" """
Check the translation file Check the translation file
""" """
print (args)
for arg in args: arg = arg[0]
if arg[-3:] == '.po':
print ("Checked file: '%(lang.po)s'. See '%(txt)s.txt'." \ print ("Checked file: '%(lang.po)s'. See '%(txt)s.txt'." \
% {'lang.po': arg, 'txt': arg[:-3]}) % {'lang.po': arg, 'txt': arg[:-3]})
os.system('''%(python)s ./check_po --skip-fuzzy ./%(lang.po)s > %(lang)s.txt''' \ os.system('''%(python)s ./check_po --skip-fuzzy ./%(lang.po)s > %(lang)s.txt''' \
% {'python': pythonCmd, 'lang.po': arg, 'lang': arg[:-3]}) % {'python': pythonCmd, 'lang.po': arg, 'lang': arg[:-3]})
os.system('''%(msgfmt)s -c -v %(lang.po)s''' os.system('''%(msgfmt)s -c -v %(lang.po)s'''
% {'msgfmt': msgfmtCmd, 'lang.po': arg}) % {'msgfmt': msgfmtCmd, 'lang.po': arg})
else:
print ("Please, try to set an argument with .po extension like "
"'%(arg)s.po'." % {'arg': arg})
def untranslated(args): def untranslated(args):
""" """