upgrade deprecated "optparse" module to "argparse" for a python2.7/3.2 support; skip fuzzy by default because it is ignored on .mo generation and not yet reviewed by translators; only check and print a summary
svn: r20742
This commit is contained in:
parent
f44e1d2297
commit
fbac0193af
36
po/check_po
36
po/check_po
@ -27,7 +27,8 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
from optparse import OptionParser
|
import os
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
all_total = {}
|
all_total = {}
|
||||||
all_fuzzy = {}
|
all_fuzzy = {}
|
||||||
@ -504,7 +505,7 @@ def read_msgs( fname ):
|
|||||||
msgs = msgs1
|
msgs = msgs1
|
||||||
return msgs
|
return msgs
|
||||||
|
|
||||||
def analyze_msgs( options, fname, msgs, nr_templates = None, nth = 0 ):
|
def analyze_msgs( args, fname, msgs, nr_templates = None, nth = 0 ):
|
||||||
nr_fuzzy = 0
|
nr_fuzzy = 0
|
||||||
nr_untranslated = 0
|
nr_untranslated = 0
|
||||||
|
|
||||||
@ -531,8 +532,6 @@ def analyze_msgs( options, fname, msgs, nr_templates = None, nth = 0 ):
|
|||||||
|
|
||||||
if msg.is_fuzzy:
|
if msg.is_fuzzy:
|
||||||
nr_fuzzy += 1
|
nr_fuzzy += 1
|
||||||
if options.skip_fuzzy:
|
|
||||||
continue
|
|
||||||
|
|
||||||
for c in checks:
|
for c in checks:
|
||||||
c.process( msg )
|
c.process( msg )
|
||||||
@ -565,30 +564,27 @@ def analyze_msgs( options, fname, msgs, nr_templates = None, nth = 0 ):
|
|||||||
else:
|
else:
|
||||||
print text + ' (previous gramps.pot)'
|
print text + ' (previous gramps.pot)'
|
||||||
|
|
||||||
if not options.only_summary:
|
|
||||||
for c in checks:
|
|
||||||
c.diag()
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = OptionParser( description='This program validates a PO file for GRAMPS.', usage='%prog [options] po-file...' )
|
|
||||||
|
parser = ArgumentParser( description='This program validates a PO file for GRAMPS.')
|
||||||
parser.add_option("", "--skip-fuzzy",
|
|
||||||
action="store_true", dest="skip_fuzzy", default=False,
|
parser.add_argument("-s", "--summary", dest="summary",
|
||||||
help="skip fuzzies")
|
choices=[file for file in os.listdir('.') if file.endswith('.po')],
|
||||||
|
default=False, help="only give the summary")
|
||||||
parser.add_option("-s", "--only-summary",
|
|
||||||
action="store_true", dest="only_summary", default=False,
|
args = parser.parse_args()
|
||||||
help="only give the summary")
|
|
||||||
|
if args.summary:
|
||||||
(options, args) = parser.parse_args()
|
files = sys.argv[2:]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pot_msgs = read_msgs( 'gramps.pot' )
|
pot_msgs = read_msgs( 'gramps.pot' )
|
||||||
nr_templates = len( pot_msgs )
|
nr_templates = len( pot_msgs )
|
||||||
nth = 0
|
nth = 0
|
||||||
for fname in args:
|
for fname in files:
|
||||||
msgs = read_msgs( fname )
|
msgs = read_msgs( fname )
|
||||||
analyze_msgs( options, fname, msgs, nr_templates, nth )
|
analyze_msgs( files, fname, msgs, nr_templates, nth )
|
||||||
nth += 1
|
nth += 1
|
||||||
|
|
||||||
except CheckException, e:
|
except CheckException, e:
|
||||||
|
@ -616,7 +616,7 @@ def check(arg):
|
|||||||
|
|
||||||
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 -s %(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})
|
||||||
|
Loading…
Reference in New Issue
Block a user