Skip to content

Commit

Permalink
3.0.006
Browse files Browse the repository at this point in the history
  • Loading branch information
chapmanjacobd committed Oct 19, 2024
1 parent e0ca180 commit 53369ae
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ To stop playing press Ctrl+C in either the terminal or mpv
<details><summary>List all subcommands</summary>

$ library
library (v3.0.005; 87 subcommands)
library (v3.0.006; 87 subcommands)

Create database subcommands:
╭─────────────────┬──────────────────────────────────────────╮
Expand Down
2 changes: 1 addition & 1 deletion tests/folders/test_merge_mv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",):
Expand Down
4 changes: 2 additions & 2 deletions tests/folders/test_rel_mv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)

Expand All @@ -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}
)

Expand Down
2 changes: 1 addition & 1 deletion xklb/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions xklb/folders/merge_mv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion xklb/utils/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
12 changes: 10 additions & 2 deletions xklb/utils/path_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 53369ae

Please sign in to comment.