mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-26 10:05:19 +00:00
Improvements to the new UI class and improve how ConfigManager handles
setting the config directory
This commit is contained in:
parent
62bc9d1844
commit
df21107e3f
@ -45,18 +45,31 @@ class _ConfigManager:
|
|||||||
del self.config_files
|
del self.config_files
|
||||||
|
|
||||||
def set_config_dir(self, directory):
|
def set_config_dir(self, directory):
|
||||||
"""Sets the config directory"""
|
"""
|
||||||
if directory == None:
|
Sets the config directory.
|
||||||
return
|
|
||||||
|
:param directory: str, the directory where the config info should be
|
||||||
|
|
||||||
|
:returns bool: True if successfully changed directory, False if not
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not directory:
|
||||||
|
return False
|
||||||
|
|
||||||
log.info("Setting config directory to: %s", directory)
|
log.info("Setting config directory to: %s", directory)
|
||||||
if not os.path.exists(directory):
|
if not os.path.exists(directory):
|
||||||
# Try to create the config folder if it doesn't exist
|
# Try to create the config folder if it doesn't exist
|
||||||
try:
|
try:
|
||||||
os.makedirs(directory)
|
os.makedirs(directory)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.warning("Unable to make config directory: %s", e)
|
log.error("Unable to make config directory: %s", e)
|
||||||
|
return False
|
||||||
|
elif not os.path.isdir(directory):
|
||||||
|
log.error("Config directory needs to be a directory!")
|
||||||
|
return False
|
||||||
|
|
||||||
self.__config_directory = directory
|
self.__config_directory = directory
|
||||||
|
return True
|
||||||
|
|
||||||
def get_config_dir(self):
|
def get_config_dir(self):
|
||||||
return self.config_directory
|
return self.config_directory
|
||||||
|
@ -71,32 +71,19 @@ class _UI(object):
|
|||||||
def start(self):
|
def start(self):
|
||||||
(self.__options, self.__args) = self.__parser.parse_args()
|
(self.__options, self.__args) = self.__parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
if self.__options.quiet:
|
if self.__options.quiet:
|
||||||
self.__options.loglevel = "none"
|
self.__options.loglevel = "none"
|
||||||
|
|
||||||
if self.__options.config:
|
|
||||||
if not os.path.isdir(self.__options.config):
|
|
||||||
print "Config option needs to be a directory!"
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if not os.path.exists(self.__options.config):
|
|
||||||
# Try to create the config folder if it doesn't exist
|
|
||||||
try:
|
|
||||||
os.makedirs(self.__options.config)
|
|
||||||
except Exception, e:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
if not os.path.exists(deluge.common.get_default_config_dir()):
|
|
||||||
os.makedirs(deluge.common.get_default_config_dir())
|
|
||||||
|
|
||||||
# Setup the logger
|
# Setup the logger
|
||||||
deluge.log.setupLogger(level=self.__options.loglevel, filename=self.__options.logfile)
|
deluge.log.setupLogger(level=self.__options.loglevel, filename=self.__options.logfile)
|
||||||
|
|
||||||
version = deluge.common.get_version()
|
|
||||||
|
|
||||||
log = deluge.log.LOG
|
log = deluge.log.LOG
|
||||||
log.info("Deluge ui %s", version)
|
|
||||||
|
if self.__options.config:
|
||||||
|
if not deluge.configmanager.set_config_dir(self.__options.config):
|
||||||
|
log.error("There was an error setting the config dir! Exiting..")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
log.info("Deluge ui %s", deluge.common.get_version())
|
||||||
log.debug("options: %s", self.__options)
|
log.debug("options: %s", self.__options)
|
||||||
log.debug("args: %s", self.__args)
|
log.debug("args: %s", self.__args)
|
||||||
log.info("Starting ui..")
|
log.info("Starting ui..")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user