only try and load the old config if the file exists

This commit is contained in:
Damien Churchill 2009-09-24 15:55:21 +00:00
commit 5c5a0712b0

View file

@ -450,27 +450,28 @@ class DelugeWeb(component.Component):
super(DelugeWeb, self).__init__("DelugeWeb") super(DelugeWeb, self).__init__("DelugeWeb")
self.config = configmanager.ConfigManager("web.conf", CONFIG_DEFAULTS) self.config = configmanager.ConfigManager("web.conf", CONFIG_DEFAULTS)
old_config = configmanager.ConfigManager("webui06.conf") if os.path.exists(configmanager.get_config_dir("webui06.conf")):
if old_config.config: old_config = configmanager.ConfigManager("webui06.conf")
# we have an old config file here to handle so we should move if old_config.config:
# all the values across to the new config file, and then remove # we have an old config file here to handle so we should move
# it. # all the values across to the new config file, and then remove
for key in OLD_CONFIG_KEYS: # it.
self.config[key] = old_config[key] for key in OLD_CONFIG_KEYS:
self.config[key] = old_config[key]
# We need to base64 encode the passwords since utf-8 can't handle
# them otherwise. # We need to base64 encode the passwords since json can't handle
from base64 import encodestring # them otherwise.
self.config["old_pwd_md5"] = encodestring(old_config["pwd_md5"]) from base64 import encodestring
self.config["old_pwd_salt"] = encodestring(old_config["pwd_salt"]) self.config["old_pwd_md5"] = encodestring(old_config["pwd_md5"])
self.config["old_pwd_salt"] = encodestring(old_config["pwd_salt"])
# Save our config and if it saved successfully then rename the
# old configuration file. # Save our config and if it saved successfully then rename the
if self.config.save(): # old configuration file.
config_dir = os.path.dirname(old_config.config_file) if self.config.save():
backup_path = os.path.join(config_dir, 'web.conf.old') config_dir = os.path.dirname(old_config.config_file)
os.rename(old_config.config_file, backup_path) backup_path = os.path.join(config_dir, 'web.conf.old')
del old_config os.rename(old_config.config_file, backup_path)
del old_config
self.socket = None self.socket = None
self.top_level = TopLevel() self.top_level = TopLevel()