mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-03 08:04:07 +01:00
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:
parent
a8b6698849
commit
423a38770b
@ -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:
|
||||
|
@ -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"""
|
||||
|
Loading…
Reference in New Issue
Block a user