diff --git a/frappy_psi/sea.py b/frappy_psi/sea.py index f95f27b7..7bcaae41 100644 --- a/frappy_psi/sea.py +++ b/frappy_psi/sea.py @@ -83,16 +83,22 @@ def get_sea_port(instance): class SeaConfig: @lazy_property - def dir(self): - seaconfdir = os.environ.get('FRAPPY_SEA_DIR') - if seaconfdir is None or not Path(seaconfdir).expanduser().absolute().exists(): + def dirs(self): + seaconfdirs = os.environ.get('FRAPPY_SEA_DIR', '').replace(':', ' ').replace(',', ' ') + result = [Path(v) for v in seaconfdirs.split() if Path(v).expanduser().is_dir()] + if not result: for confdir in generalConfig.confdir: seaconfdir = confdir / 'sea' - if seaconfdir.exists(): - break - else: - seaconfdir = Path(seaconfdir).expanduser().absolute() - return seaconfdir + if seaconfdir.is_dir(): + result.append(seaconfdir) + return result + + def load_json(self, json_file): + for dir in self.dirs: + file = dir / json_file + if file.is_file(): + return json.load(file.read_text()) + raise FileNotFoundError(f'{json_file} not found') seaconfig = SeaConfig() @@ -385,7 +391,7 @@ class SeaConfigCreator(SeaClient): stripped, _, ext = filename.rpartition('.') service = SERVICE_NAMES[ext] seaconn = 'sea_' + service - cfgfile = seaconfig.dir / (stripped + '_cfg.py') + cfgfile = seaconfig.dirs[0] / (stripped + '_cfg.py') with cfgfile.open('w', encoding='utf-8') as fp: fp.write(CFG_HEADER % {'config': filename, 'seaconn': seaconn, 'service': service, 'nodedescr': description.get(filename, filename)}) @@ -393,7 +399,7 @@ class SeaConfigCreator(SeaClient): fp.write(CFG_MODULE % {'modcls': modcls[obj], 'module': obj, 'seaconn': seaconn}) content = json.dumps(descr).replace('}, {', '},\n{').replace('[{', '[\n{').replace('}]}, ', '}]},\n\n') result.append('%s\n' % cfgfile) - fpath = seaconfig.dir / (filename + '.json') + fpath = seaconfig.dirs[0] / (filename + '.json') fpath.write_text(content + '\n', encoding='utf-8') result.append('%s: %s' % (filename, ','.join(n for n in descr))) raise SystemExit('; '.join(result)) @@ -529,9 +535,7 @@ class SeaModule(Module): cfgdict['description'] = '%s@%s%s' % ( name, json_file, '' if rel_paths is None else f' (rel_paths={rel_paths})') - with (seaconfig.dir / json_file).open(encoding='utf-8') as fp: - content = json.load(fp) - descr = content[sea_object] + descr = seaconfig.load_json(json_file)[sea_object] # filter by relative paths if rel_paths: