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.
This commit is contained in:
Valentin Lorentz 2019-11-24 12:04:21 +01:00
parent a8b6698849
commit 423a38770b
2 changed files with 5 additions and 6 deletions

View File

@ -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:

View File

@ -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"""