jenkins-bot has submitted this change and it was merged.
Change subject: [IMPR] Enable tabulators for json dump.
......................................................................
[IMPR] Enable tabulators for json dump.
In python >=3.2 json.dump allows strings for indent in addition to integers
but previous version does not. Use json.dumps and replace spaces with tabs.
Add an option to prevent pretty print of the dict.
Change-Id: I49d22cff2075dbbc36b21fc38a906b7dea504011
---
M scripts/maintenance/make_i18n_dict.py
1 file changed, 23 insertions(+), 8 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/maintenance/make_i18n_dict.py
b/scripts/maintenance/make_i18n_dict.py
index 639864a..5f2150b 100755
--- a/scripts/maintenance/make_i18n_dict.py
+++ b/scripts/maintenance/make_i18n_dict.py
@@ -107,16 +107,29 @@
if 'en' not in keys:
print('WARNING: "en" key missing for message %s' % newmsg)
- def run(self):
- """Run the bot, read the messages from source and print the
dict."""
+ def run(self, quiet=False):
+ """
+ Run the bot, read the messages from source and print the dict.
+
+ @param quiet: print the result if False
+ @type quiet: bool
+ """
for item in self.messages.items():
self.read(*item)
- self.print_all()
+ if not quiet:
+ self.print_all()
- def to_json(self):
- """Run the bot and create json files."""
+ def to_json(self, quiet=True):
+ """
+ Run the bot and create json files.
+
+ @param quiet: Print the result if False
+ @type quiet: bool
+ """
+ IDENT = 4
+
if not self.dict:
- self.run()
+ self.run(quiet)
json_dir = os.path.join(
config.base_dir, 'scripts/i18n', self.scriptname)
if not os.path.exists(json_dir):
@@ -131,8 +144,10 @@
new_dict['@metadata'] = new_dict.get('@metadata',
{'authors': []})
with codecs.open(file_name, 'w', 'utf-8') as json_file:
new_dict.update(self.dict[lang])
- json.dump(new_dict, json_file, ensure_ascii=False,
- sort_keys=True, indent=4, separators=(',', ':
'))
+ s = json.dumps(new_dict, ensure_ascii=False, sort_keys=True,
+ indent=IDENT, separators=(',', ': '))
+ s = s.replace(' ' * IDENT, '\t')
+ json_file.write(s)
if __name__ == '__main__':
print(__doc__)
--
To view, visit
https://gerrit.wikimedia.org/r/251837
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I49d22cff2075dbbc36b21fc38a906b7dea504011
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>