diff --git a/bin/configuration.py b/bin/configuration.py index 481f0b0..a84d750 100644 --- a/bin/configuration.py +++ b/bin/configuration.py @@ -12,6 +12,18 @@ surveys should be under $HOME/etc/surveys/*.yaml. In both cases, $HOME is the home directory of the user running this script. """ +def is_relative_to(it, other): + """ + is_relative_to() is not present version Python 3.9, so we + need this kludge to get Dougal to run on OpenSUSE 15.4 + """ + + if "is_relative_to" in dir(it): + return it.is_relative_to(other) + + return str(it.absolute()).startswith(str(other.absolute())) + + prefix = os.environ.get("DOUGAL_ROOT", os.environ.get("HOME", ".")+"/software") DOUGAL_ROOT = os.environ.get("DOUGAL_ROOT", os.environ.get("HOME", ".")+"/software") @@ -142,7 +154,7 @@ def untranslate_path (file): if filepath.is_absolute(): if type(import_paths) == str: - if filepath.is_relative_to(import_paths): + if is_relative_to(filepath, import_paths): physical_root = pathlib.Path("/") physical_prefix = pathlib.Path(import_paths) return str(root.joinpath(filepath.relative_to(physical_prefix))) @@ -152,7 +164,7 @@ def untranslate_path (file): for key, value in import_paths.items(): value = dougal_root.joinpath(value) physical_prefix = pathlib.Path(value) - if filepath.is_relative_to(physical_prefix): + if is_relative_to(filepath, physical_prefix): logical_prefix = physical_root.joinpath(pathlib.Path(key)).resolve() return str(logical_prefix.joinpath(filepath.relative_to(physical_prefix)))