diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2019-10-24 00:01:13 +0200 |
---|---|---|
committer | Michael Stahl <michael.stahl@cib.de> | 2019-10-24 14:07:47 +0200 |
commit | c1e04e406955c6f3bf186019ffee459c93f03330 (patch) | |
tree | 1f1ff8779089bd65d66129cf6ea3a03a2f570f72 | |
parent | 411c5d79b1cdb5bf959af970d4f7a955353ed9c5 (diff) |
scripts/unocommands.py: Switch to python3
Files not explicitly opened in binary mode are text files and thus
expect a 'str' arg for their write() method.
Python 2 is nearing its EOL and e.g. Debian has already
removed the python2-based 'python-polib' package previously
used here from its testing distribution.
I checked that running the commands
./scripts/unocommands.py --update . ../libreoffice
./scripts/unocommands.py --translate . ../libreoffice/translations
./scripts/unocommands.py --check .
still yields the same results as previously.
Change-Id: I39e1785d3c78416009420dd4c2be58bd1c3647c3
Reviewed-on: https://gerrit.libreoffice.org/81422
Reviewed-by: Michael Stahl <michael.stahl@cib.de>
Tested-by: Michael Stahl <michael.stahl@cib.de>
-rwxr-xr-x | scripts/unocommands.py | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/scripts/unocommands.py b/scripts/unocommands.py index a28c3ab5d..e4dc45ef4 100755 --- a/scripts/unocommands.py +++ b/scripts/unocommands.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- # # This file is part of the LibreOffice project. @@ -201,20 +201,19 @@ def writeUnocommandsJS(onlineDir, lofficeDir, menuCommands, contextCommands, too descriptions = collectCommandsFromXCU(os.path.join(dir, file), descriptions, toolbarCommands, 'Label', type) # output the unocommands.js - f = open(onlineDir + '/loleaflet/src/unocommands.js', 'w') + f = open(onlineDir + '/loleaflet/src/unocommands.js', 'w', encoding='utf-8') f.write('''// Don't modify, generated using unocommands.py var unoCommandsArray = {\n''') for key in sorted(descriptions.keys()): - #f.write((' ' + key + ": _('" + descriptions[key] + "'),\n").encode('utf-8')) - f.write(('\t' + key + ':{').encode('utf-8')) + f.write('\t' + key + ':{') for type in sorted(descriptions[key].keys()): - f.write((type + ':{').encode('utf-8')) + f.write(type + ':{') for menuType in sorted(descriptions[key][type].keys()): - f.write((menuType + ":_('" + descriptions[key][type][menuType] + "'),").encode('utf-8')) - f.write(('},').encode('utf-8')) - f.write(('},\n').encode('utf-8')) + f.write(menuType + ":_('" + descriptions[key][type][menuType] + "'),") + f.write('},') + f.write('},\n') f.write('''}; @@ -258,10 +257,9 @@ window._UNO = function(string, component, isContext) { def parseUnocommandsJS(onlineDir): strings = {} - f = open(onlineDir + '/loleaflet/src/unocommands.js', 'r') + f = open(onlineDir + '/loleaflet/src/unocommands.js', 'r', encoding='utf-8') readingCommands = False for line in f: - line = line.decode('utf-8') m = re.match(r"\t([^:]*):.*", line) if m: command = m.group(1) @@ -296,7 +294,7 @@ def writeTranslations(onlineDir, translationsDir, strings): if text == entry.msgid: translations[entry.msgid] = entry.msgstr - f = open(onlineDir + '/loleaflet/l10n/uno/' + lang + '.json', 'w') + f = open(onlineDir + '/loleaflet/l10n/uno/' + lang + '.json', 'w', encoding='utf-8') f.write('{\n') writeComma = False @@ -305,7 +303,7 @@ def writeTranslations(onlineDir, translationsDir, strings): f.write(',\n') else: writeComma = True - f.write(('"' + key.replace('"','\\\"') + '":"' + translations[key].replace('"','\\\"') + '"').encode('utf-8')) + f.write('"' + key.replace('"','\\\"') + '":"' + translations[key].replace('"','\\\"') + '"') f.write('\n}\n') |