From 423a38770b49f3a85ccc87ed19f261a0bd9e4487 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 24 Nov 2019 12:04:21 +0100 Subject: [PATCH] Get locale name on startup from registry cache instead of parsing config file. Parsing the config file needlessly requires an extra read of it, and is brittle (extra spaces, etc.) It was especially broken as there was a newline character at the end of currentLocale, which made everything fail shamefully. --- scripts/supybot | 3 ++- src/i18n.py | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/scripts/supybot b/scripts/supybot index c3e17b1b8..1a91a28e9 100644 --- a/scripts/supybot +++ b/scripts/supybot @@ -213,7 +213,6 @@ if __name__ == '__main__': registryFilename = args.pop() try: # The registry *MUST* be opened before importing log or conf. - i18n.getLocaleFromRegistryFilename(registryFilename) registry.open_registry(registryFilename) shutil.copyfile(registryFilename, registryFilename + '.bak') except registry.InvalidRegistryFile as e: @@ -229,6 +228,8 @@ if __name__ == '__main__': sys.stderr.write(os.linesep) sys.exit(-1) + i18n.getLocaleFromRegistryCache() + try: import supybot.log as log except supybot.registry.InvalidRegistryValue as e: diff --git a/src/i18n.py b/src/i18n.py index 4eaf00c24..1b702035f 100644 --- a/src/i18n.py +++ b/src/i18n.py @@ -52,14 +52,12 @@ currentLocale = 'en' class PluginNotFound(Exception): pass -def getLocaleFromRegistryFilename(filename): +def getLocaleFromRegistryCache(): """Called by the 'supybot' script. Gets the locale name before conf is loaded.""" global currentLocale - with open(filename, 'r') as fd: - for line in fd: - if line.startswith('supybot.language: '): - currentLocale = line[len('supybot.language: '):] + import supybot.registry as registry + currentLocale = registry._cache['supybot.language'] def import_conf(): """Imports the conf into this module"""