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() registryFilename = args.pop()
try: try:
# The registry *MUST* be opened before importing log or conf. # The registry *MUST* be opened before importing log or conf.
i18n.getLocaleFromRegistryFilename(registryFilename)
registry.open_registry(registryFilename) registry.open_registry(registryFilename)
shutil.copyfile(registryFilename, registryFilename + '.bak') shutil.copyfile(registryFilename, registryFilename + '.bak')
except registry.InvalidRegistryFile as e: except registry.InvalidRegistryFile as e:
@ -229,6 +228,8 @@ if __name__ == '__main__':
sys.stderr.write(os.linesep) sys.stderr.write(os.linesep)
sys.exit(-1) sys.exit(-1)
i18n.getLocaleFromRegistryCache()
try: try:
import supybot.log as log import supybot.log as log
except supybot.registry.InvalidRegistryValue as e: except supybot.registry.InvalidRegistryValue as e:

View File

@ -52,14 +52,12 @@ currentLocale = 'en'
class PluginNotFound(Exception): class PluginNotFound(Exception):
pass pass
def getLocaleFromRegistryFilename(filename): def getLocaleFromRegistryCache():
"""Called by the 'supybot' script. Gets the locale name before conf is """Called by the 'supybot' script. Gets the locale name before conf is
loaded.""" loaded."""
global currentLocale global currentLocale
with open(filename, 'r') as fd: import supybot.registry as registry
for line in fd: currentLocale = registry._cache['supybot.language']
if line.startswith('supybot.language: '):
currentLocale = line[len('supybot.language: '):]
def import_conf(): def import_conf():
"""Imports the conf into this module""" """Imports the conf into this module"""