From 54cdfa4685aa03139154625d53996c862f0a7173 Mon Sep 17 00:00:00 2001 From: ducklet Date: Sat, 11 Feb 2023 18:30:31 +0100 Subject: [PATCH] minor clean up --- metadex/db.py | 1 + metadex/metadex.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/metadex/db.py b/metadex/db.py index f5b558a..34f7d57 100644 --- a/metadex/db.py +++ b/metadex/db.py @@ -342,6 +342,7 @@ def _add_parents(conn: Connection, *, location: str, hostname: str) -> "int | No d = _fake_entry(p, hostname=hostname, now=datetime.now(), parent_id=p_id) d = get_or_add(conn, d) if isinstance(d, dict): + log.warning("Added forged parent: %a:%a", hostname, str(p)) p_id = d["id"] else: p_id = d.id diff --git a/metadex/metadex.py b/metadex/metadex.py index 3bb4283..eed2db6 100644 --- a/metadex/metadex.py +++ b/metadex/metadex.py @@ -245,14 +245,15 @@ def _parse_pathspec(pathspec: str) -> "tuple[str | None, str]": def _clean_dirname(loc: str, *, force_absolute: bool = True) -> str: + """Ensure the given location ends with a single `/`. + + If `force_absolute` is `True`, also ensure the location starts with `/`. + """ if force_absolute and not loc.startswith("/"): loc = "/" + loc if not loc.endswith("/"): loc += "/" return loc - # if loc != "/" and loc.endswith("/"): - # return loc[:-1] - # return loc _Hostname = str @@ -456,6 +457,11 @@ def _ingest_ls_add_only( def _dict_from_lsfile(f: ls_parser.File) -> "dict[str, Any]": + """Create a dict compatible with `models.File`. + + This avoids creating a dataclass instance and calling `asdict` on it, which + is a relatively expensive operation. + """ mode = f.mode[0] if mode == "-": mode = "f"