shorten po/check_po lines (indent=4-chars, etc.)

This commit is contained in:
Paul Franklin 2015-03-05 16:23:33 -08:00
parent 9f843464b3
commit 9335a21e3a

View File

@ -241,7 +241,8 @@ 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 ) )
@ -344,21 +345,25 @@ def read_msgs( fname ):
# expect msgid or comment or old stuff # expect msgid or comment or old stuff
if next_state == CMNT: if next_state == CMNT:
state = CMNT state = CMNT
msg = create_new_Msgid( msgs, lineno ) # Start with an empty new item # Start with an empty new item
msg = create_new_Msgid( msgs, lineno )
msg.add_cmnt( line ) msg.add_cmnt( line )
elif next_state == MSGID: elif next_state == MSGID:
state = MSGID state = MSGID
msg = create_new_Msgid( msgs, lineno ) # Start with an empty new item # Start with an empty new item
msg = create_new_Msgid( msgs, lineno )
msg.add_msgid( line, lineno ) msg.add_msgid( line, lineno )
elif next_state == MSGIDP: elif next_state == MSGIDP:
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 # Start with an empty new item
msg = create_new_Msgid( msgs, lineno )
msg.add_new_msgstr( line, lineno ) msg.add_new_msgstr( line, lineno )
elif next_state == STR: elif next_state == STR:
@ -368,10 +373,12 @@ def read_msgs( fname ):
pass # Just skip pass # Just skip
else: else:
raise CheckException( 'Unexpected state in po parsing (state = %(state)s)' % vars() ) raise CheckException( 'Unexpected state in po parsing '
'(state = %(state)s)' % vars() )
elif state == CMNT: elif state == CMNT:
# Expect more comment, or msgid. If msgstr or string it is flagged as error. # Expect more comment, or msgid.
# If msgstr or string it is flagged as error.
if next_state == CMNT: if next_state == CMNT:
if msg: if msg:
msg.add_cmnt( line ) msg.add_cmnt( line )
@ -383,16 +390,19 @@ def read_msgs( fname ):
elif next_state == MSGID: elif next_state == MSGID:
state = MSGID state = MSGID
if not msg: if not msg:
msg = create_new_Msgid( msgs, lineno ) # Start with an empty new item # Start with an empty new item
msg = create_new_Msgid( msgs, lineno )
msg.add_msgid( line, lineno ) msg.add_msgid( line, lineno )
elif next_state == MSGIDP: elif next_state == MSGIDP:
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 # Start with an empty new item
msg = create_new_Msgid( msgs, lineno )
msg.add_new_msgstr( line, lineno ) msg.add_new_msgstr( line, lineno )
elif next_state == STR: elif next_state == STR:
@ -403,16 +413,19 @@ def read_msgs( fname ):
pass # Just skip pass # Just skip
else: else:
raise CheckException( 'Unexpected state in po parsing (state = %(state)s)' % vars() ) raise CheckException( 'Unexpected state in po parsing '
'(state = %(state)s)' % vars() )
elif state == MSGID: elif state == MSGID:
# 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() )
elif next_state == MSGIDP: elif next_state == MSGIDP:
state = MSGIDP state = MSGIDP
@ -431,19 +444,23 @@ def read_msgs( fname ):
pass # Just skip pass # Just skip
else: else:
raise CheckException( 'Unexpected state in po parsing (state = %(state)s)' % vars() ) raise CheckException( 'Unexpected state in po parsing '
'(state = %(state)s)' % vars() )
elif state == MSGIDP: elif state == MSGIDP:
# 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: Unexpected 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() )
elif next_state == MSGIDP: elif next_state == MSGIDP:
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:
state = MSGSTR state = MSGSTR
@ -458,7 +475,8 @@ def read_msgs( fname ):
pass # Just skip pass # Just skip
else: else:
raise CheckException( 'Unexpected state in po parsing (state = %(state)s)' % vars() ) raise CheckException( 'Unexpected state in po parsing '
'(state = %(state)s)' % vars() )
elif state == MSGSTR: elif state == MSGSTR:
# Expect comment, or msgid, or string. # Expect comment, or msgid, or string.
@ -474,7 +492,8 @@ def read_msgs( fname ):
msg.add_msgid( line, lineno ) msg.add_msgid( line, lineno )
elif next_state == MSGIDP: elif next_state == MSGIDP:
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:
# New msgstr, probably for plural form # New msgstr, probably for plural form
@ -489,10 +508,12 @@ def read_msgs( fname ):
pass # Just skip pass # Just skip
else: else:
raise CheckException( 'Unexpected state in po parsing (state = %(state)s)' % vars() ) raise CheckException( 'Unexpected state in po parsing '
'(state = %(state)s)' % vars() )
else: else:
raise CheckException( 'Unexpected state in po parsing (state = %(state)s)' % vars() ) raise CheckException( 'Unexpected state in po parsing '
'(state = %(state)s)' % vars() )
# Strip items with just comments. (Can this happen?) # Strip items with just comments. (Can this happen?)
msgs1 = [] msgs1 = []
@ -570,11 +591,15 @@ def analyze_msgs( args, fname, msgs, nr_templates = None, nth = 0 ):
def main(): def main():
parser = ArgumentParser( description='This program validates a PO file for GRAMPS.') parser = ArgumentParser(description='This program validates '
'a PO file for GRAMPS.')
parser.add_argument("-s", dest="summary", parser.add_argument("-s", dest="summary",
choices=[file for file in os.listdir('.') if file.endswith('.po')], choices=[file for file in os.listdir('.')
default=False, help="the summary of check, and if need, it gives details") if file.endswith('.po')],
default=False,
help="the summary of check, "
"and if need, it gives details")
args = parser.parse_args() args = parser.parse_args()