Skip to content

Commit

Permalink
updated handling of directory with user-defined configs
Browse files Browse the repository at this point in the history
  • Loading branch information
mtitov committed Oct 24, 2023
1 parent a633e4d commit 4abd74b
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/radical/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
module = 'module'
module_path = radical.utils.debug.find_module(module)
usr_base_dir = os.environ.get('RADICAL_CONFIG_USER_DIR') or \
os.environ.get('HOME', '/tmp/radical.%(user_id)')
sys_config_dir = '%s/configs' % (module_path)
usr_config_dir = '%s/.%s/configs' % (usr_base_dir, module.replace('.', '/'))
sys_config_dir = '%s/configs' % module_path
usr_base_dir = os.getenv('RADICAL_CONFIG_USER_DIR') or \
os.getenv('HOME')
if usr_base_dir:
usr_config_dir = '%s/.%s/configs' % \
(usr_base_dir, module.replace('.', '/'))
so the location of the module's `__init__.py` is used to derive the location
of the installed system config files, and the module name is used to derive
Expand Down Expand Up @@ -282,14 +284,18 @@ def __init__(self, module=None, category=None, name=None, cfg=None,
if not modpath:
raise ValueError("Cannot find module %s" % module)

home = os.environ.get('HOME', '/tmp/radical.%d' % os.getuid())
home = os.environ.get('RADICAL_CONFIG_USER_DIR', home)
sys_dir = "%s/configs" % (modpath)
usr_dir = "%s/.%s/configs" % (home, module.replace('.', '/'))
fname = '%s_%s.json' % (category.replace('.', '/'), name)
fname = '%s_%s.json' % (category.replace('.', '/'), name)

sys_fspec = '%s/%s' % (sys_dir, fname)
usr_fspec = '%s/%s' % (usr_dir, fname)
sys_dir = '%s/configs' % modpath
sys_fspec = '%s/%s' % (sys_dir, fname)

home = os.getenv('RADICAL_CONFIG_USER_DIR') or os.getenv('HOME')
if home:
usr_dir = '%s/.%s/configs' % (home, module.replace('.', '/'))
usr_fspec = '%s/%s' % (usr_dir, fname)
else:
usr_dir = None
usr_fspec = None

if '*' in fname: starred = True
else : starred = False
Expand Down Expand Up @@ -371,10 +377,13 @@ def __init__(self, module=None, category=None, name=None, cfg=None,

fname = '%s.json' % (category.replace('.', '/'))
sys_fname = '%s/%s' % (sys_dir, fname)
usr_fname = '%s/%s' % (usr_dir, fname)
if os.path.isfile(sys_fname):
sys_cfg = read_json(sys_fname)

if os.path.isfile(sys_fname): sys_cfg = read_json(sys_fname)
if os.path.isfile(usr_fname): usr_cfg = read_json(usr_fname)
if usr_dir:
usr_fname = '%s/%s' % (usr_dir, fname)
if os.path.isfile(usr_fname):
usr_cfg = read_json(usr_fname)


# merge sys, usr and app cfg before expansion
Expand Down

0 comments on commit 4abd74b

Please sign in to comment.