diff --git a/python/nav/config.py b/python/nav/config.py index b55dd402ca..4fe1f00d5e 100644 --- a/python/nav/config.py +++ b/python/nav/config.py @@ -30,7 +30,7 @@ from pathlib import Path from nav.errors import GeneralException -from nav.util import files, resource_bytes +from nav.util import resource_files, resource_bytes from . import buildconf _logger = logging.getLogger(__name__) @@ -250,11 +250,11 @@ def _config_resource_walk(source=''): """ source = Path(source) current_path = Path('etc') / source - for path in files('nav').joinpath(current_path).iterdir(): + for path in resource_files('nav').joinpath(current_path).iterdir(): name = path.name full_name = current_path / name relative_name = str(source / name) - if files('nav').joinpath(full_name).is_dir(): + if resource_files('nav').joinpath(full_name).is_dir(): for path in _config_resource_walk(source=relative_name): yield str(path) else: diff --git a/python/nav/pgsync.py b/python/nav/pgsync.py index 7ca81143cc..54d0a8c50a 100755 --- a/python/nav/pgsync.py +++ b/python/nav/pgsync.py @@ -31,7 +31,7 @@ from nav.db import ConnectionParameters from nav.colors import colorize, print_color from nav.colors import COLOR_CYAN, COLOR_YELLOW, COLOR_RED, COLOR_GREEN -from nav.util import files, resource_bytes +from nav.util import resource_files, resource_bytes def main(): @@ -565,7 +565,7 @@ def __init__(self, resource_module): def _find_change_scripts(self): changes_dir = Path('sql/changes') scripts = [] - sql_path = files(self.resource_module).joinpath(changes_dir) + sql_path = resource_files(self.resource_module).joinpath(changes_dir) for path in sql_path.iterdir(): filename = path.name if self.script_pattern.match(str(filename)): diff --git a/python/nav/util.py b/python/nav/util.py index c10f7d28f4..ece1da4558 100644 --- a/python/nav/util.py +++ b/python/nav/util.py @@ -36,6 +36,11 @@ from importlib_resources import files, as_file +# rename to a better name +resource_files = files +del files + + def gradient(start, stop, steps): """Create and return a sequence of steps representing an integer gradient from the start value to the stop value. @@ -517,11 +522,11 @@ def _range_to_str(x, y): def resource_filename(package, filename): - ref = files(package) / filename + ref = resource_files(package) / filename with as_file(ref) as path: return str(path) def resource_bytes(package, filename): - ref = files(package) / filename + ref = resource_files(package) / filename return ref.read_bytes()