From af672d10ebd59442018827370585fda79e14db94 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Wed, 13 Sep 2023 16:10:29 -0400 Subject: [PATCH] fix paths with data-dir --- modules/paths.py | 8 +++++--- modules/styles.py | 23 ++++++++++++----------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/modules/paths.py b/modules/paths.py index 18dea2fb1..c0d7cbd11 100644 --- a/modules/paths.py +++ b/modules/paths.py @@ -62,10 +62,12 @@ def create_paths(opts, log=None): def fix_path(folder): tgt = opts.data.get(folder, None) or opts.data_labels[folder].default if tgt is None or tgt == '': - return - if os.path.isabs(tgt) or (len(data_path) > 0 and tgt.startswith(data_path)) and not tgt.startswith(script_path): - return + return + if len(data_path) > 0 and tgt.startswith(data_path): # path is already relative to data_path + return tgt fullpath = os.path.join(data_path, tgt) + if len(data_path) > 0 and os.path.isabs(data_path): + return fullpath relpath = os.path.relpath(fullpath, script_path) opts.data[folder] = relpath return relpath diff --git a/modules/styles.py b/modules/styles.py index 54815350f..94052d548 100644 --- a/modules/styles.py +++ b/modules/styles.py @@ -41,22 +41,19 @@ class StyleDatabase: def __init__(self, opts): self.no_style = Style("None") self.styles = {} - self.path = opts.styles_dir - if os.path.isfile(opts.styles_dir): + if os.path.isfile(opts.styles_dir) or opts.styles_dir.endswith(".csv"): legacy_file = opts.styles_dir self.load_csv(legacy_file) opts.styles_dir = os.path.join(paths.models_path, "styles") self.path = opts.styles_dir - self.mkdir() + os.makedirs(opts.styles_dir, exist_ok=True) self.save_styles(opts.styles_dir, verbose=True) - log.debug(f'Migrated styles: file={legacy_file} folder={self.path}') + log.debug(f'Migrated styles: file={legacy_file} folder={opts.styles_dir}') self.reload() - self.mkdir() - - def mkdir(self): - if not os.path.isdir(self.path): - os.makedirs(self.path, exist_ok=True) - log.debug(f'Created styles: folder={self.path}') + if not os.path.isdir(opts.styles_dir): + opts.styles_dir = os.path.join(paths.models_path, "styles") + self.path = opts.styles_dir + os.makedirs(opts.styles_dir, exist_ok=True) def reload(self): self.styles.clear() @@ -108,9 +105,13 @@ class StyleDatabase: log.debug(f'Saved style: name={name} file={fn}') except Exception as e: log.error(f'Failed to save style: name={name} file={path} error={e}') - log.debug(f'Saved styles: {path} {len(self.styles.keys())}') + count = len(list(self.styles)) + if count > 0: + log.debug(f'Saved styles: {path} {count}') def load_csv(self, legacy_file): + if not os.path.isfile(legacy_file): + return with open(legacy_file, "r", encoding="utf-8-sig", newline='') as file: reader = csv.DictReader(file, skipinitialspace=True) for row in reader: