add "all" argument for check and update flag (maintenance and tests)

svn: r20747
This commit is contained in:
Jérôme Rapinat 2012-12-02 17:22:40 +00:00
parent 870f54c733
commit 6f6c3845f0

View File

@ -70,6 +70,10 @@ elif sys.platform == 'linux2' or os.name == 'darwin':
else: else:
print ("ERROR: unknown system, don't know msgmerge, ... commands") print ("ERROR: unknown system, don't know msgmerge, ... commands")
sys.exit(0) sys.exit(0)
LANG = [file for file in os.listdir('.') if file.endswith('.po')]
LANG.append("all")
LANG.sort()
def tests(): def tests():
""" """
@ -368,18 +372,18 @@ def main():
# lang.po files maintenance # lang.po files maintenance
update.add_argument("-m", "--merge", dest="merge", update.add_argument("-m", "--merge", dest="merge",
choices=[file for file in os.listdir('.') if file.endswith('.po')], choices=LANG,
help="merge lang.po files with last catalog") help="merge lang.po files with last catalog")
update.add_argument("-k", "--check", dest="check", update.add_argument("-k", "--check", dest="check",
choices=[file for file in os.listdir('.') if file.endswith('.po')], choices=LANG,
help="check lang.po files") help="check lang.po files")
# testing stage # testing stage
trans = parser.add_argument_group('Translation', 'Display content of translations file') trans = parser.add_argument_group('Translation', 'Display content of translations file')
# need one argument (eg, de.po) # need one argument (eg, de.po)
trans.add_argument("-u", "--untranslated", dest="untranslated", trans.add_argument("-u", "--untranslated", dest="untranslated",
choices=[file for file in os.listdir('.') if file.endswith('.po')], choices=[file for file in os.listdir('.') if file.endswith('.po')],
help="list untranslated messages") help="list untranslated messages")
@ -411,9 +415,13 @@ def main():
clean() clean()
if args.merge: if args.merge:
if sys.argv[2:] == ['all']:
sys.argv[2:] = LANG
merge(sys.argv[2:]) merge(sys.argv[2:])
if args.check: if args.check:
if sys.argv[2:] == ['all']:
sys.argv[2:] = LANG
check(sys.argv[2:]) check(sys.argv[2:])
if args.untranslated: if args.untranslated:
@ -595,49 +603,47 @@ def clean():
os.unlink('tmpfiles') os.unlink('tmpfiles')
print ("Remove 'tmpfiles'") print ("Remove 'tmpfiles'")
def merge(arg): def merge(args):
""" """
Merge messages with 'gramps.pot' Merge messages with 'gramps.pot'
""" """
arg = arg[0] for arg in args:
if arg == 'all':
print ('Merge %(lang)s with current template' % {'lang': arg}) continue
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})
print ("Updated file: 'updated_%(lang)s'." % {'lang': arg})
def check(arg): def check(args):
""" """
Check the translation file Check the translation file
""" """
arg = arg[0] for arg in args:
if arg == 'all':
print ("Checked file: '%(lang.po)s'. See '%(txt)s.txt'." \ continue
% {'lang.po': arg, 'txt': arg[:-3]}) print ("Checked file: '%(lang.po)s'. See '%(txt)s.txt'." \
os.system('''%(python)s ./check_po -s %(lang.po)s > %(lang)s.txt''' \ % {'lang.po': arg, 'txt': arg[:-3]})
% {'python': pythonCmd, 'lang.po': arg, 'lang': arg[:-3]}) os.system('''%(python)s ./check_po -s %(lang.po)s > %(lang)s.txt''' \
os.system('''%(msgfmt)s -c -v %(lang.po)s''' % {'python': pythonCmd, 'lang.po': arg, 'lang': arg[:-3]})
% {'msgfmt': msgfmtCmd, 'lang.po': arg}) os.system('''%(msgfmt)s -c -v %(lang.po)s'''
% {'msgfmt': msgfmtCmd, 'lang.po': arg})
def untranslated(arg): def untranslated(arg):
""" """
List untranslated messages List untranslated messages
""" """
arg = arg[0] os.system('''%(msgattrib)s --untranslated %(lang.po)s''' % {'msgattrib': msgattribCmd, 'lang.po': arg[0]})
os.system('''%(msgattrib)s --untranslated %(lang.po)s''' % {'msgattrib': msgattribCmd, 'lang.po': arg})
def fuzzy(arg): def fuzzy(arg):
""" """
List fuzzy messages List fuzzy messages
""" """
arg = arg[0] os.system('''%(msgattrib)s --only-fuzzy --no-obsolete %(lang.po)s''' % {'msgattrib': msgattribCmd, 'lang.po': arg[0]})
os.system('''%(msgattrib)s --only-fuzzy --no-obsolete %(lang.po)s''' % {'msgattrib': msgattribCmd, 'lang.po': arg})
if __name__ == "__main__": if __name__ == "__main__":
main() main()