diff options
author | Alan Verdugo <alan.verdugo.munoz1@ibm.com> | 2020-10-10 22:48:52 -0500 |
---|---|---|
committer | Muhammet Kara <mrkara@users.noreply.github.com> | 2020-10-12 12:15:43 +0300 |
commit | 5452c205e6d570aff90c1199119093874d801b60 (patch) | |
tree | 7ac5abd6eaf47f907a60ace80b5763bf20aff6ba | |
parent | document broker, tile combined handling: warn only once without tile cache (diff) | |
download | online-5452c205e6d570aff90c1199119093874d801b60.tar.gz online-5452c205e6d570aff90c1199119093874d801b60.zip |
Fixing pycodestyle checks
Author: Alan Verdugo <alan.verdugo.munoz1@ibm.com>
Date: Sat Oct 10 22:48:52 2020 -0500
Changes to be committed:
modified: loleaflet/util/po2json.py
Change-Id: I5bc796a88b7d2d7f33da470ce9ba76ae658a331c
-rwxr-xr-x | loleaflet/util/po2json.py | 74 |
1 files changed, 41 insertions, 33 deletions
diff --git a/loleaflet/util/po2json.py b/loleaflet/util/po2json.py index a3284573b7..3d8d295a64 100755 --- a/loleaflet/util/po2json.py +++ b/loleaflet/util/po2json.py @@ -1,60 +1,68 @@ #!/usr/bin/env python3 -# -# convert .po to .json -# +"""Convert .po to .json.""" import json import optparse import os -import polib -import re -import string import sys import errno +import re +import polib parser = optparse.OptionParser(usage="usage: %prog [options] pofile...") -parser.add_option("--quiet", action="store_false", default=True, dest="verbose", help="don't print status messages to stdout") -parser.add_option("-o", type="string", default="", dest="destfile", help="output file name (if there is exactly one input file)") +parser.add_option("--quiet", + action="store_false", + default=True, + dest="verbose", + help="don't print status messages to stdout") +parser.add_option("-o", + type="string", + default="", + dest="destfile", + help="output file name (if there is exactly one input file)") (options, args) = parser.parse_args() -if args == None or len(args) == 0: - print("ERROR: you must specify at least one po file to translate"); - sys.exit(1) +if args is None or len(args) == 0: + print("ERROR: you must specify at least one po file to translate") + sys.exit(1) if options.destfile != '' and len(args) != 1: - print("ERROR: when -o is provided, there has to be exactly 1 input file") - sys.exit(1) + print("ERROR: when -o is provided, there has to be exactly 1 input file") + sys.exit(1) paramFix = re.compile("(\\(([0-9])\\))") for srcfile in args: - destfile = os.path.splitext(srcfile)[0] + ".json" - if options.destfile != '': - destfile = options.destfile + destfile = os.path.splitext(srcfile)[0] + ".json" + if options.destfile != '': + destfile = options.destfile - if options.verbose: - print("INFO: converting %s to %s" % (srcfile, destfile)) + if options.verbose: + print("INFO: converting %s to %s" % (srcfile, destfile)) - xlate_map = {} + xlate_map = {} - po = polib.pofile(srcfile, autodetect_encoding=False, encoding="utf-8", wrapwidth=-1) - for entry in po.translated_entries(): - if entry.msgstr == '': - continue + po = polib.pofile(srcfile, + autodetect_encoding=False, + encoding="utf-8", + wrapwidth=-1) + for entry in po.translated_entries(): + if entry.msgstr == '': + continue - xlate_map[entry.msgid] = entry.msgstr; + xlate_map[entry.msgid] = entry.msgstr - if not os.path.exists(os.path.dirname(destfile)): - try: - os.makedirs(os.path.dirname(destfile)) - except OSError as exc: # Guard against race condition - if exc.errno != errno.EEXIST: - raise + if not os.path.exists(os.path.dirname(destfile)): + try: + os.makedirs(os.path.dirname(destfile)) + except OSError as exc: # Guard against race condition + if exc.errno != errno.EEXIST: + raise - dest = open(destfile, "w") + dest = open(destfile, "w") - dest.write(json.dumps(xlate_map, sort_keys = True)); + dest.write(json.dumps(xlate_map, sort_keys=True)) - dest.close() + dest.close() |