Skip to content

Commit

Permalink
2.9.067
Browse files Browse the repository at this point in the history
  • Loading branch information
chapmanjacobd committed Oct 19, 2024
1 parent 9dd5689 commit c0bf399
Show file tree
Hide file tree
Showing 209 changed files with 3,356 additions and 2,654 deletions.
58 changes: 33 additions & 25 deletions .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 (v2.9.066; 88 subcommands)
library (v2.9.067; 87 subcommands)

Create database subcommands:
╭─────────────────┬──────────────────────────────────────────╮
Expand Down Expand Up @@ -167,8 +167,6 @@ To stop playing press Ctrl+C in either the terminal or mpv
├─────────────────┼─────────────────────────────────────────────────────────────────────┤
│ merge-folders │ Merge two or more file trees, check for conflicts before merging │
├─────────────────┼─────────────────────────────────────────────────────────────────────┤
│ rel-mv │ Move files preserving parent folder hierarchy │
├─────────────────┼─────────────────────────────────────────────────────────────────────┤
│ mergerfs-cp │ cp files with reflink on mergerfs │
├─────────────────┼─────────────────────────────────────────────────────────────────────┤
│ scatter │ Scatter files between folders or disks │
Expand Down Expand Up @@ -1230,6 +1228,12 @@ BTW, for some cols like time_deleted you'll need to specify a where clause so th
$ library merge-mv -h
usage: library merge-mv SOURCE ... DEST [--simulate] [--ext EXT]

merging-move: combine file trees

The destination is ALWAYS a folder by default (`--dest-folder`).
Use `--dest-bsd` to mimick BSD/GNU default `mv` behavior
Use `--dest-file` to mimick BSD/GNU `mv --no-target-directory`

By default it won't matter if source folders end with a path separator or not

library merge-mv folder1 folder2/ # folder1 will be merged with folder2/
Expand All @@ -1248,6 +1252,18 @@ BTW, for some cols like time_deleted you'll need to specify a where clause so th

nb. This tool, like other library subcommands, only works on files. Empty folders will not be moved to the destination

Move files/folders without losing hierarchy metadata with --relative or relmv

Move fresh music to your phone every Sunday

# move last week music back to their source folders
library mv /mnt/d/sync/weekly/ /

# move new music for this week
library relmv (
library listen audio.db --local-media-only --where 'play_count=0' --random -L 600 -p f
) /mnt/d/sync/weekly/


</details>

Expand All @@ -1267,28 +1283,6 @@ BTW, for some cols like time_deleted you'll need to specify a where clause so th
The count of conflicts also includes trumps.


</details>

###### rel-mv

<details><summary>Move files preserving parent folder hierarchy</summary>

$ library rel-mv -h
usage: library rel-mv [--simulate] SOURCE ... DEST

Move files/folders without losing hierarchy metadata

Move fresh music to your phone every Sunday

# move last week music back to their source folders
library mv /mnt/d/sync/weekly/ /mnt/d/check/audio/

# move new music for this week
library relmv (
library listen audio.db --local-media-only --where 'play_count=0' --random -L 600 -p f
) /mnt/d/sync/weekly/


</details>

###### mergerfs-cp
Expand All @@ -1298,6 +1292,9 @@ BTW, for some cols like time_deleted you'll need to specify a where clause so th
$ library mergerfs-cp -h
usage: library mergerfs-cp SOURCE ... DEST [--simulate] [--ext EXT]

This command mirrors the behavior of BSD with regard to destination files and folders.
To force the destination to always be a folder, similar to `library mv`, use `--destination-folder`

Copy files with reflink and handle mergerfs mounts

library mergerfs-cp --dry-run d/files* d/folder2/
Expand Down Expand Up @@ -2086,6 +2083,17 @@ Inspired somewhat by https://nikkhokkho.sourceforge.io/?page=FileOptimizer
| /home/xk/github/xk/lb/__pypackages__/3.11/lib/jedi/third_party/typeshed/third_party/2and3/requests/packages/urllib3/packages/ssl_match_hostname/__init__.pyi | 88 Bytes |
| /home/xk/github/xk/lb/__pypackages__/3.11/lib/jedi/third_party/typeshed/third_party/2and3/requests/packages/urllib3/packages/ssl_match_hostname/_implementation.pyi | 81 Bytes |

Group by extension

library exts du.db
library disk-usage du.db --group-by-extension
path size count
------ -------- -------
avi 1.8 GiB 5
webm 14.3 GiB 47
mkv 49.2 GiB 159
mp4 86.7 GiB 613
4 file extensions


</details>
Expand Down
69 changes: 36 additions & 33 deletions tests/folders/test_merge_mv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

from tests.conftest import generate_file_tree_dict
from xklb.__main__ import library as lb
from xklb.utils import arggroups, devices, objects, path_utils
from xklb.utils import consts
from xklb.utils import arggroups, consts, devices, objects, path_utils

TEMP_DIR = consts.TEMP_DIR.lstrip('/')
TEMP_DIR = consts.TEMP_DIR.lstrip("/")


@pytest.mark.parametrize("file_over_file", objects.class_enum(arggroups.FileOverFile))
Expand Down Expand Up @@ -165,10 +164,14 @@ def test_merge(assert_unchanged, src_type, dest_type, dest_opt, mode, temp_file_
cmd += [src1_arg, dest_arg]
lb(cmd)

if os.path.exists(src1):
src1_inodes = generate_file_tree_dict(src1, inodes=False)
else:
src1_inodes = {}
target_inodes = generate_file_tree_dict(dest, inodes=False)
target_inodes = objects.replace_key_in_dict(target_inodes, path_utils.basename(src1), "src1")
target_inodes = objects.replace_key_in_dict(target_inodes, path_utils.basename(dest), "dest")
assert_unchanged(target_inodes)
assert_unchanged({"src": src1_inodes, "dest": target_inodes})


@pytest.mark.parametrize("subcommand", ["merge-mv", "merge-cp"])
Expand Down Expand Up @@ -220,10 +223,10 @@ def test_simulate_mkdirs(temp_file_tree):

assert generate_file_tree_dict(src1) == src1_inodes
assert generate_file_tree_dict(dest) == {
'folder1': {
'file4.txt': {},
"folder1": {
"file4.txt": {},
},
'folder2': {},
"folder2": {},
}


Expand Down Expand Up @@ -252,10 +255,10 @@ def test_filter_file(temp_file_tree):
@pytest.mark.parametrize("subcommand", ["merge-mv", "merge-cp"])
def test_same_file(subcommand, temp_file_tree):
src1 = temp_file_tree({"file4.txt": "4"}) + os.sep + "file4.txt"
src1_inodes = generate_file_tree_dict(src1, inodes=subcommand=='merge-mv')
src1_inodes = generate_file_tree_dict(src1, inodes=subcommand == "merge-mv")

lb([subcommand, src1, src1])
assert generate_file_tree_dict(src1, inodes=subcommand=='merge-mv') == src1_inodes
assert generate_file_tree_dict(src1, inodes=subcommand == "merge-mv") == src1_inodes


@pytest.mark.parametrize("subcommand", ["merge-mv", "merge-cp"])
Expand All @@ -267,25 +270,6 @@ def test_same_folder(subcommand, temp_file_tree):
assert generate_file_tree_dict(src1) == src1_inodes


@pytest.mark.parametrize("src", ['FILE', 'FOLDER'])
@pytest.mark.parametrize("use_parent", [True, False])
@pytest.mark.parametrize(
"relative_to", [':', '/', os.sep, 'TEMP_DIR', 'SRC_FILE', 'SRC_FOLDER', 'SRC_PARENT', 'TARGET']
)
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(TEMP_DIR).name: {Path(src1).name: src1_inodes}}
if relative_to in (':','TEMP_DIR'):
expected_results = {Path(src1).name: src1_inodes}
if relative_to in ('SRC_FOLDER',):
expected_results = src1_inodes
if src == 'FILE' and relative_to == 'SRC_FILE':
expected_results = {Path(target).name: src1_inodes['file4.txt']}

assert generate_file_tree_dict(target) == expected_results


def relmv_run(temp_file_tree, src, use_parent, relative_to):
file_tree = {"file4.txt": "4"}
src1 = temp_file_tree(file_tree)
Expand All @@ -300,22 +284,41 @@ def relmv_run(temp_file_tree, src, use_parent, relative_to):
command += ["--parent"]

command += ["--relative-to"]
if relative_to == 'TEMP_DIR':
if relative_to == "TEMP_DIR":
command += [consts.TEMP_DIR]
elif relative_to == 'SRC_FILE':
elif relative_to == "SRC_FILE":
command += [src1_file]
elif relative_to == 'SRC_FOLDER':
elif relative_to == "SRC_FOLDER":
command += [src1]
elif relative_to == 'TARGET':
elif relative_to == "TARGET":
command += [target]
else:
command += [relative_to]

if src == 'FILE':
if src == "FILE":
command += [src1_file]
else:
command += [src1]

command += [target]
lb(command)
return src1, src1_inodes, target


@pytest.mark.parametrize("src", ["FILE", "FOLDER"])
@pytest.mark.parametrize("use_parent", [True, False])
@pytest.mark.parametrize(
"relative_to", [":", "/", os.sep, "TEMP_DIR", "SRC_FILE", "SRC_FOLDER", "SRC_PARENT", "TARGET"]
)
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(TEMP_DIR).name: {Path(src1).name: src1_inodes}}
if relative_to in (":", "TEMP_DIR"):
expected_results = {Path(src1).name: src1_inodes}
if relative_to in ("SRC_FOLDER",):
expected_results = src1_inodes
if src == "FILE" and relative_to == "SRC_FILE":
expected_results = {Path(target).name: src1_inodes["file4.txt"]}

assert generate_file_tree_dict(target) == expected_results
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
file4.txt:
dest:
file4.txt:
- 0
- '4'
src1:
file4.txt:
- 0
- '5'
folder1:
file1.txt:
- 0
- '1'
- '4'
src1:
file4.txt:
file2.txt:
- 0
- '5'
folder1:
file1.txt:
- 0
- '1'
file4.txt:
file2.txt:
- 0
- '2'
folder2:
.hidden:
- 0
- '2'
folder2:
.hidden:
- '3'
folder1:
file1.txt:
- 0
- '1'
file4.txt:
file2.txt:
- 0
- '3'
folder1:
file1.txt:
- 0
- '1'
file4.txt:
file2.txt:
- '2'
folder2:
.hidden:
- 0
- '2'
folder2:
.hidden:
- 0
- '3'
- '3'
src: {}
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
file4.txt:
- 0
- '4'
file4_1.txt:
- 0
- '5'
folder1:
file1.txt:
- 0
- '1'
dest:
file4.txt:
file2.txt:
- 0
- '2'
folder2:
.hidden:
- 0
- '3'
- '4'
file4_1.txt:
- 0
- '5'
folder1:
file1.txt:
- 0
- '1'
file4.txt:
file2.txt:
- 0
- '2'
folder2:
.hidden:
- 0
- '3'
src: {}
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
file4.txt:
dest:
file4.txt:
- 0
- '4'
file4_1.txt:
- 0
- '5'
file4.txt:
- 0
- '4'
file4_1.txt:
- 0
- '5'
folder1:
file1.txt:
- 0
- '1'
file4.txt:
file2.txt:
- 0
- '2'
folder2:
.hidden:
- 0
- '3'
folder1:
file1.txt:
- 0
Expand All @@ -17,15 +30,4 @@ file4.txt:
.hidden:
- 0
- '3'
folder1:
file1.txt:
- 0
- '1'
file4.txt:
file2.txt:
- 0
- '2'
folder2:
.hidden:
- 0
- '3'
src: {}
Loading

0 comments on commit c0bf399

Please sign in to comment.