From 53369aecb7a6a27f54f39385f6d6a415410015bd Mon Sep 17 00:00:00 2001 From: Jacob Chapman <7908073+chapmanjacobd@users.noreply.github.com> Date: Sun, 20 Oct 2024 01:03:41 +0800 Subject: [PATCH] 3.0.006 --- .github/README.md | 2 +- tests/folders/test_merge_mv.py | 2 +- tests/folders/test_rel_mv.py | 4 ++-- xklb/__main__.py | 2 +- xklb/folders/merge_mv.py | 4 ++-- xklb/utils/consts.py | 2 +- xklb/utils/path_utils.py | 12 ++++++++++-- 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.github/README.md b/.github/README.md index 5a4a0464..8812626e 100644 --- a/.github/README.md +++ b/.github/README.md @@ -99,7 +99,7 @@ To stop playing press Ctrl+C in either the terminal or mpv
List all subcommands $ library - library (v3.0.005; 87 subcommands) + library (v3.0.006; 87 subcommands) Create database subcommands: ╭─────────────────┬──────────────────────────────────────────╮ diff --git a/tests/folders/test_merge_mv.py b/tests/folders/test_merge_mv.py index 7e6d90e7..491e3767 100644 --- a/tests/folders/test_merge_mv.py +++ b/tests/folders/test_merge_mv.py @@ -318,7 +318,7 @@ def relmv_run(temp_file_tree, src, use_parent, relative_to): def test_relmv(temp_file_tree, src, use_parent, relative_to): src1, src1_inodes, target = relmv_run(temp_file_tree, src, use_parent, relative_to) - expected_results = path_utils.build_nested_dict(consts.TEMP_DIR, {Path(src1).name: src1_inodes}) + expected_results = path_utils.build_nested_dir_dict(consts.TEMP_DIR, {Path(src1).name: src1_inodes}) if relative_to in (":", "TEMP_DIR"): expected_results = {Path(src1).name: src1_inodes} if relative_to in ("SRC_FOLDER",): diff --git a/tests/folders/test_rel_mv.py b/tests/folders/test_rel_mv.py index ad3cc91a..0c4104e4 100644 --- a/tests/folders/test_rel_mv.py +++ b/tests/folders/test_rel_mv.py @@ -23,7 +23,7 @@ def test_simple_file(temp_file_tree): target = temp_file_tree({}) lb(["rel-mv", src1, target]) - assert generate_file_tree_dict(target) == path_utils.build_nested_dict( + assert generate_file_tree_dict(target) == path_utils.build_nested_dir_dict( consts.TEMP_DIR, {Path(src1).name: src1_inodes} ) @@ -37,7 +37,7 @@ def test_two_simple_folders_root(temp_file_tree): target = temp_file_tree({}) lb(["rel-mv", src1, src2, target]) - assert generate_file_tree_dict(target) == path_utils.build_nested_dict( + assert generate_file_tree_dict(target) == path_utils.build_nested_dir_dict( consts.TEMP_DIR, {Path(src1).name: src1_inodes} | {Path(src2).name: src2_inodes} ) diff --git a/xklb/__main__.py b/xklb/__main__.py index a4d7ef4e..46141fb7 100644 --- a/xklb/__main__.py +++ b/xklb/__main__.py @@ -5,7 +5,7 @@ from xklb.utils import argparse_utils, iterables from xklb.utils.log_utils import log -__version__ = "3.0.005" +__version__ = "3.0.006" progs = { "Create database subcommands": { diff --git a/xklb/folders/merge_mv.py b/xklb/folders/merge_mv.py index 3c31f86e..5dba9f50 100644 --- a/xklb/folders/merge_mv.py +++ b/xklb/folders/merge_mv.py @@ -123,9 +123,9 @@ def gen_rel_path(source, dest, relative_to): relpath = str(abspath.relative_to(rel)) log.debug("abspath %s relative to %s = %s", abspath, rel, relpath) except ValueError: - if abspath.drive and abspath.drive.endswith(":"): # Windows Drives + if abspath.drive.endswith(":"): # Windows Drives relpath = str(Path(abspath.drive.strip(":")) / abspath.relative_to(abspath.drive + "\\")) - elif abspath.drive.startswith("\\\\"): # Handle UNC paths + elif abspath.drive.startswith("\\\\"): # UNC paths server_share = abspath.parts[0] relpath = str(Path(server_share.lstrip("\\").replace("\\", "/")) / "/".join(abspath.parts[1:])) else: diff --git a/xklb/utils/consts.py b/xklb/utils/consts.py index 3791c55a..2b18ad46 100644 --- a/xklb/utils/consts.py +++ b/xklb/utils/consts.py @@ -27,7 +27,7 @@ def random_string() -> str: ) -TEMP_DIR = gettempdir() +TEMP_DIR = str(Path(gettempdir()).resolve()) TEMP_SCRIPT_DIR = os.getenv("XDG_RUNTIME_DIR") or TEMP_DIR CAST_NOW_PLAYING = str(Path(TEMP_DIR) / "catt_playing") SUB_TEMP_DIR = str(Path(TEMP_DIR) / "library_temp_subtitles" / random_string()) diff --git a/xklb/utils/path_utils.py b/xklb/utils/path_utils.py index b30cd00a..53144024 100644 --- a/xklb/utils/path_utils.py +++ b/xklb/utils/path_utils.py @@ -152,8 +152,16 @@ def basename(path): return os.path.basename(path.rstrip(sep)) -def build_nested_dict(path_str, nested_value): - segments = path_str.strip(os.sep).split(os.sep) +def build_nested_dir_dict(path_str, nested_value): + p = Path(path_str) + if p.drive.endswith(":"): # Windows Drives + drive = Path(p.drive.strip(":")) + segments = (drive, *p.parts[1:]) + elif p.drive.startswith("\\\\"): # UNC paths + server_share = p.parts[0] + segments = (*server_share.lstrip("\\").split("\\"), *p.parts[1:]) + else: + segments = p.parts[1:] def _build_dict(segments): if not segments: