Xqt has uploaded a new change for review.
https://gerrit.wikimedia.org/r/251837
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 pring of the dict.
Change-Id: I49d22cff2075dbbc36b21fc38a906b7dea504011
---
M scripts/maintenance/make_i18n_dict.py
1 file changed, 23 insertions(+), 8 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/37/251837/1
diff --git a/scripts/maintenance/make_i18n_dict.py
b/scripts/maintenance/make_i18n_dict.py
index 639864a..79f797d 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=True):
+ """
+ Run the bot, read the messages from source and print the dict.
+
+ @param quiet: print the result if True
+ @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=False):
+ """
+ Run the bot and create json files.
+
+ @param quiet: Print the result if True
+ @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: newchange
Gerrit-Change-Id: I49d22cff2075dbbc36b21fc38a906b7dea504011
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits