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