Skip to content

Commit

Permalink
fix disk-usage, allow override for skipping deleted files by default
Browse files Browse the repository at this point in the history
  • Loading branch information
chapmanjacobd committed Nov 7, 2024
1 parent b07cd8c commit 3eebabb
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 170 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.13"

- uses: FedericoCarboni/setup-ffmpeg@v3

Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.11"

- run: |
python -m pip install pdm
Expand Down
336 changes: 174 additions & 162 deletions pdm.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ dependencies = [
"python-dateutil",
"python-mpv-jsonipc",
"regex",
"requests",
"urllib3>2",
"rich",
"screeninfo",
"sqlite-utils",
Expand All @@ -35,7 +37,7 @@ requires-python = ">=3.11"

[project.optional-dependencies]
dev = ["black", "isort", "ssort"]
test = ["ruff", "pytest", "pytest-regressions", "freezegun", "pyfakefs"]
test = ["ruff", "pytest", "pytest-regressions", "freezegun", "pandas", "pyfakefs"]
deluxe = [
"aiohttp",
"annoy",
Expand Down
6 changes: 5 additions & 1 deletion xklb/createdb/web_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ def web_add(args=None) -> None:
if db_media.exists(args, p):
media_known.add(p)
else:
add_media(args, [consolidate_media(args, p)])
if isinstance(p, dict):
m = consolidate_media(args, p['path']) | p
else:
m = consolidate_media(args, p)
add_media(args, [m])
media_new.add(p)
printing.print_overwrite(f"Link import: {len(media_new)} new [{len(media_known)} known]")
else:
Expand Down
3 changes: 2 additions & 1 deletion xklb/fsdb/disk_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def get_data(args) -> list[dict]:
if args.database:
media = list(args.db.query(*sqlgroups.fs_sql(args, limit=None)))
else:
args.paths = [p for p in args.paths if os.path.exists(p)]
if args.hide_deleted:
args.paths = [p for p in args.paths if os.path.exists(p)]
media = arg_utils.gen_d(args)
media = [d if "size" in d else file_utils.get_filesize(d) for d in media]

Expand Down
26 changes: 23 additions & 3 deletions xklb/utils/arg_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import argparse, operator, random
import argparse, operator, os.path, random
from collections import defaultdict
from copy import copy
from pathlib import Path

from xklb.utils import consts, file_utils, iterables, nums, processes, strings
from xklb.utils.consts import SC
from xklb.utils.log_utils import log


def gen_paths(args, default_exts=None):
Expand All @@ -26,6 +27,11 @@ def gen_paths(args, default_exts=None):
p = Path(path)
if p.is_dir():
yield from file_utils.rglob(str(p), args.ext or default_exts, getattr(args, "exclude", None))[0]
elif getattr(args, "hide_deleted", False):
if os.path.exists(p):
yield {"path": path}
else:
log.info("Skipping non-existent file %s", path)
else:
yield path

Expand All @@ -38,9 +44,18 @@ def gen_d(args, default_exts=None):
for path in args.paths:
json_data = strings.safe_json_loads(path)
if isinstance(json_data, list):
yield from json_data
for json_item in json_data:
if getattr(args, "hide_deleted", False):
if os.path.exists(json_item["path"]):
yield json_item
else:
yield json_item
elif isinstance(json_data, dict):
yield json_data
if getattr(args, "hide_deleted", False):
if os.path.exists(json_data["path"]):
yield json_data
else:
yield json_data
else:
raise TypeError
else:
Expand All @@ -50,6 +65,11 @@ def gen_d(args, default_exts=None):
if p.is_dir():
for sp in file_utils.rglob(str(p), args.ext or default_exts, getattr(args, "exclude", None))[0]:
yield {"path": sp}
elif getattr(args, "hide_deleted", False):
if os.path.exists(p):
yield {"path": path}
else:
log.info("Skipping non-existent file %s", path)
else:
yield {"path": path}

Expand Down

0 comments on commit 3eebabb

Please sign in to comment.