mirror of
https://github.com/fergalmoran/picard.git
synced 2025-12-26 03:08:02 +00:00
PICARD-1066: Fix update_constants
This commit is contained in:
24
setup.py
24
setup.py
@@ -493,7 +493,7 @@ class picard_update_constants(Command):
|
||||
log.info('Parsing %s' % countries_potfile)
|
||||
po = pofile.read_po(f)
|
||||
for message in po:
|
||||
if not message.id or not isinstance(message.id, unicode):
|
||||
if not message.id or not isinstance(message.id, str):
|
||||
continue
|
||||
for comment in message.auto_comments:
|
||||
if comment.startswith(isocode_comment):
|
||||
@@ -516,7 +516,7 @@ class picard_update_constants(Command):
|
||||
log.info('Parsing %s' % attributes_potfile)
|
||||
po = pofile.read_po(f)
|
||||
for message in po:
|
||||
if not message.id or not isinstance(message.id, unicode):
|
||||
if not message.id or not isinstance(message.id, str):
|
||||
continue
|
||||
for loc, pos in message.locations:
|
||||
if loc in extract_attributes:
|
||||
@@ -536,13 +536,13 @@ class picard_update_constants(Command):
|
||||
footer = u"}}\n"
|
||||
filename = os.path.join('picard', 'const', 'countries.py')
|
||||
with open(filename, 'w') as countries_py:
|
||||
def write_utf8(s, **kwargs):
|
||||
countries_py.write(s.format(**kwargs).encode('utf-8'))
|
||||
def write(s, **kwargs):
|
||||
countries_py.write(s.format(**kwargs))
|
||||
|
||||
write_utf8(header, option=_get_option_name(self))
|
||||
write(header, option=_get_option_name(self))
|
||||
for code, name in sorted(countries.items(), key=lambda t: t[0]):
|
||||
write_utf8(line, code=code, name=name.replace("'", "\\'"))
|
||||
write_utf8(footer)
|
||||
write(line, code=code, name=name.replace("'", "\\'"))
|
||||
write(footer)
|
||||
log.info("%s was rewritten (%d countries)" % (filename,
|
||||
len(countries)))
|
||||
|
||||
@@ -556,13 +556,13 @@ class picard_update_constants(Command):
|
||||
footer = u"}}\n"
|
||||
filename = os.path.join('picard', 'const', 'attributes.py')
|
||||
with open(filename, 'w') as attributes_py:
|
||||
def write_utf8(s, **kwargs):
|
||||
attributes_py.write(s.format(**kwargs).encode('utf-8'))
|
||||
def write(s, **kwargs):
|
||||
attributes_py.write(s.format(**kwargs))
|
||||
|
||||
write_utf8(header, option=_get_option_name(self))
|
||||
write(header, option=_get_option_name(self))
|
||||
for key, value in sorted(attributes.items(), key=lambda i: i[0]):
|
||||
write_utf8(line, key=key, value=value.replace("'", "\\'"))
|
||||
write_utf8(footer)
|
||||
write(line, key=key, value=value.replace("'", "\\'"))
|
||||
write(footer)
|
||||
log.info("%s was rewritten (%d attributes)" % (filename,
|
||||
len(attributes)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user