diff options
author | louiz’ <louiz@louiz.org> | 2018-05-23 19:40:40 +0200 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2018-05-23 19:40:40 +0200 |
commit | 25df5ef410e66d96bfd6dac081a073b20e57f4e2 (patch) | |
tree | cf7c282f5b2f6c88b7c8f521c56fd87effe98850 | |
parent | 76b6d414e5465e444d903779dcbf185604056366 (diff) | |
parent | 7d20ddbfc4970df258d7408e8b4f95b9c4297af6 (diff) | |
download | poezio-25df5ef410e66d96bfd6dac081a073b20e57f4e2.tar.gz poezio-25df5ef410e66d96bfd6dac081a073b20e57f4e2.tar.bz2 poezio-25df5ef410e66d96bfd6dac081a073b20e57f4e2.tar.xz poezio-25df5ef410e66d96bfd6dac081a073b20e57f4e2.zip |
Merge remote-tracking branch 'lab/master'
-rw-r--r-- | poezio/config.py | 35 | ||||
-rw-r--r-- | poezio/poezio.py | 1 |
2 files changed, 28 insertions, 8 deletions
diff --git a/poezio/config.py b/poezio/config.py index 22662c13..e90cac8b 100644 --- a/poezio/config.py +++ b/poezio/config.py @@ -44,6 +44,7 @@ DEFAULT_CONFIG = { 'create_gaps': False, 'custom_host': '', 'custom_port': '', + 'data_dir': '', 'default_nick': '', 'deterministic_nick_colors': True, 'nick_color_aliases': True, @@ -612,20 +613,35 @@ def create_global_config(): sys.exit(1) -def check_create_log_dir(): - "Create the poezio logging directory if it doesn’t exist" - global LOG_DIR - LOG_DIR = config.get('log_dir') - - if not LOG_DIR: +def check_create_data_dir(): + """Create the poezio data directory if it doesn't exist""" + global DATA_DIR + DATA_DIR = config.get('data_dir') + if not DATA_DIR: data_home = environ.get('XDG_DATA_HOME') if data_home is None or not Path(data_home).is_absolute(): data_home = path.join(environ.get('HOME'), '.local', 'share') - LOG_DIR = path.join(data_home, 'poezio', 'logs') + DATA_DIR = path.join(data_home, 'poezio') + + DATA_DIR = path.expanduser(DATA_DIR) + try: + makedirs(DATA_DIR) + except: + pass - LOG_DIR = path.expanduser(LOG_DIR) + +def check_create_log_dir(): + "Create the poezio logging directory if it doesn’t exist" + global LOG_DIR + LOG_DIR = config.get('log_dir') + + if not LOG_DIR and not DATA_DIR: + check_create_data_dir() + + if not LOG_DIR: + LOG_DIR = path.join(DATA_DIR, 'logs') try: makedirs(LOG_DIR) @@ -705,6 +721,9 @@ options = None # delayed import from common.py safeJID = None +# the global data dir +DATA_DIR = '' + # the global log dir LOG_DIR = '' diff --git a/poezio/poezio.py b/poezio/poezio.py index a3dac78e..841e706f 100644 --- a/poezio/poezio.py +++ b/poezio/poezio.py @@ -63,6 +63,7 @@ def main(): config_path = config.check_create_config_dir() config.run_cmdline_args(config_path) config.create_global_config() + config.check_create_data_dir() config.check_create_log_dir() config.check_create_cache_dir() config.setup_logging() |