Bug 6268: Fix check_po for python3

svn: r20933
This commit is contained in:
John Ralls 2013-01-01 23:13:45 +00:00
parent c8708ae3bc
commit edc74447d1

View File

@ -55,11 +55,11 @@ class Check:
def diag( self ):
if len( self.msgs ):
print
print self.diag_header
print(self.diag_header)
for m in self.msgs:
m.diag()
def summary( self ):
print "%-20s%d" % ( self.summary_text, len(self.msgs) )
print("%-20s%d" % ( self.summary_text, len(self.msgs) ))
class Check_fmt( Check ):
def __init__( self, fmt ):
@ -119,7 +119,7 @@ class Check_named_fmt( Check ):
class Check_missing_sd( Check ):
# A pattern to find %() without s or d
# Here is a command to use for testing
# print re.compile('% \( \w+ \) \d* (\D|$)', re.VERBOSE).findall( '%(event_name)s: %(place)s%(endnotes)s. ' )
# print(re.compile('% \( \w+ \) \d* (\D|$)', re.VERBOSE).findall( '%(event_name)s: %(place)s%(endnotes)s. ' ))
find_named_fmt_pat2 = re.compile('% \( \w+ \) \d* (\D|$)', re.VERBOSE)
def __init__( self ):
@ -241,7 +241,7 @@ class Msgid:
def diag( self ):
print
print "msg nr: %d, lineno: %d%s" % ( self.nr, self.lineno, self.is_fuzzy and " (fuzzy)" or "" )
print("msg nr: %d, lineno: %d%s" % ( self.nr, self.lineno, self.is_fuzzy and " (fuzzy)" or "" ))
sys.stdout.write( ''.join( self._msgid ) )
sys.stdout.write( ''.join( self._msgidp ) )
sys.stdout.write( ''.join( self._msgstr ) )
@ -251,7 +251,7 @@ class Msgid:
line = re.sub( r'msgid\s+', '', line )
line = line.strip()
if line[0] != '"' or line[-1:] != '"':
print "ERROR at line %d: Missing quote." % lineno
print("ERROR at line %d: Missing quote." % lineno)
line = strip_quotes( line )
self.msgid += line
@ -260,7 +260,7 @@ class Msgid:
line = re.sub( r'msgid_plural\s+', '', line )
line = line.strip()
if line[0] != '"' or line[-1:] != '"':
print "ERROR at line %d: Missing quote." % lineno
print("ERROR at line %d: Missing quote." % lineno)
line = strip_quotes( line )
self.msgidp += line
@ -273,7 +273,7 @@ class Msgid:
line = re.sub( r'msgstr(\[\d\])?\s+', '', line )
line = line.strip()
if line[0] != '"' or line[-1:] != '"':
print "ERROR at line %d: Missing quote." % lineno
print("ERROR at line %d: Missing quote." % lineno)
line = strip_quotes( line )
self.msgstr[-1] += line
@ -336,10 +336,10 @@ def read_msgs( fname ):
elif str_pat.match( line ):
next_state = STR
else:
print 'WARNING: Unexpected input at %(fname)s:%(lineno)d' % vars()
print('WARNING: Unexpected input at %(fname)s:%(lineno)d' % vars())
next_state = NONE
#print "%(state)d->%(next_state)d\t%(line)s" % vars()
#print("%(state)d->%(next_state)d\t%(line)s" % vars())
if state == NONE:
# expect msgid or comment or old stuff
if next_state == CMNT:
@ -356,13 +356,13 @@ def read_msgs( fname ):
raise CheckException( 'Unexpected %(next_state)s at %(fname)s:%(lineno)d' % vars() )
elif next_state == MSGSTR:
print 'WARNING: Wild msgstr at %(fname)s:%(lineno)d' % vars()
print('WARNING: Wild msgstr at %(fname)s:%(lineno)d' % vars())
state = MSGSTR
msg = create_new_Msgid( msgs, lineno ) # Start with an empty new item
msg.add_new_msgstr( line, lineno )
elif next_state == STR:
print 'WARNING: Wild string at %(fname)s:%(lineno)d' % vars()
print('WARNING: Wild string at %(fname)s:%(lineno)d' % vars())
elif next_state == OLD:
pass # Just skip
@ -390,13 +390,13 @@ def read_msgs( fname ):
raise CheckException( 'Unexpected %(next_state)s at %(fname)s:%(lineno)d' % vars() )
elif next_state == MSGSTR:
print 'WARNING: Wild msgstr at %(fname)s:%(lineno)d' % vars()
print('WARNING: Wild msgstr at %(fname)s:%(lineno)d' % vars())
state = MSGSTR
msg = create_new_Msgid( msgs, lineno ) # Start with an empty new item
msg.add_new_msgstr( line, lineno )
elif next_state == STR:
print 'WARNING: Wild string at %(fname)s:%(lineno)d' % vars()
print('WARNING: Wild string at %(fname)s:%(lineno)d' % vars())
elif next_state == OLD:
msg = None
@ -409,7 +409,7 @@ def read_msgs( fname ):
# Expect msgstr or msgid_plural or string
if next_state == CMNT:
# Hmmm. A comment here?
print 'WARNING: Unexpted comment at %(fname)s:%(lineno)d' % vars()
print('WARNING: Unexpted comment at %(fname)s:%(lineno)d' % vars())
elif next_state == MSGID:
raise CheckException( 'Unexpected %(next_state)s at %(fname)s:%(lineno)d' % vars() )
@ -437,7 +437,7 @@ def read_msgs( fname ):
# Expect msgstr or string or comment
if next_state == CMNT:
# Hmmm. A comment here?
print 'WARNING: Unexpted comment at %(fname)s:%(lineno)d' % vars()
print('WARNING: Unexpted comment at %(fname)s:%(lineno)d' % vars())
elif next_state == MSGID:
raise CheckException( 'Unexpected %(next_state)s at %(fname)s:%(lineno)d' % vars() )
@ -498,7 +498,7 @@ def read_msgs( fname ):
msgs1 = []
for m in msgs:
if not m.msgid and not m.msgstr:
#print "INFO: No msgid or msgstr at %s:%s" % ( fname, m.lineno )
#print("INFO: No msgid or msgstr at %s:%s" % ( fname, m.lineno ))
pass
else:
msgs1.append( m )
@ -523,8 +523,8 @@ def analyze_msgs( args, fname, msgs, nr_templates = None, nth = 0 ):
msgid = msg.msgid
msgstr = msg.msgstr
#print
#print "msgid: %(msgid)s" % vars()
#print "msgstr: %(msgstr)s" % vars()
#print("msgid: %(msgid)s" % vars())
#print("msgstr: %(msgstr)s" % vars())
if ''.join(msgstr) == '':
nr_untranslated += 1
@ -540,30 +540,30 @@ def analyze_msgs( args, fname, msgs, nr_templates = None, nth = 0 ):
nr_msgs = len(msgs)
if nth > 0:
print
print "====================================="
print "%-20s%s" % ( "File:", fname )
print "%-20s%d" % ( "Template total:", nr_templates )
print "%-20s%d" % ( "PO total:", nr_msgs )
print "%-20s%d" % ( "Fuzzy:", nr_fuzzy )
print "%-20s%d" % ( "Untranslated:", nr_untranslated )
print("=====================================")
print("%-20s%s" % ( "File:", fname ))
print("%-20s%d" % ( "Template total:", nr_templates ))
print("%-20s%d" % ( "PO total:", nr_msgs ))
print("%-20s%d" % ( "Fuzzy:", nr_fuzzy ))
print("%-20s%d" % ( "Untranslated:", nr_untranslated ))
for c in checks:
c.summary()
po_coverage = (1.0 - (float(nr_untranslated) / float(nr_msgs))) * 100
print "%-20s%5.2f%%" % ( "PO Coverage:", po_coverage )
print("%-20s%5.2f%%" % ( "PO Coverage:", po_coverage ))
template_coverage = po_coverage * float(nr_msgs) / float(nr_templates)
print "%-20s%5.2f%%" % ( "Template Coverage:", template_coverage )
print("%-20s%5.2f%%" % ( "Template Coverage:", template_coverage ))
not_displayed = nr_untranslated + nr_fuzzy
translation = (1.0 - (float(not_displayed) / float(nr_templates))) * 100
text = "%-20s%5.2f%%" % ( "Localized at:", translation)
if int(template_coverage*1000) == int(po_coverage*1000):
print text
print(text)
else:
print text + ' (previous gramps.pot)'
print(text + ' (previous gramps.pot)')
for c in checks:
c.diag()
@ -590,9 +590,9 @@ def main():
analyze_msgs( files, fname, msgs, nr_templates, nth )
nth += 1
except CheckException, e:
print 'Oops.', e
print 'Bailing out'
except CheckException as e:
print('Oops.', e)
print('Bailing out')
if __name__ == "__main__":
main()