From 22ef62202a51bf4fa205750dce312583e1137719 Mon Sep 17 00:00:00 2001 From: ducklet Date: Sat, 11 Feb 2023 14:59:31 +0100 Subject: [PATCH] fix typing issue --- metadex/__main__.py | 4 ++-- metadex/models.py | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/metadex/__main__.py b/metadex/__main__.py index 65aca88..e6567d3 100644 --- a/metadex/__main__.py +++ b/metadex/__main__.py @@ -201,9 +201,9 @@ def getargs() -> argparse.Namespace: elif args.mode == "ingest-db": args.infile = utils.abspath(args.infile) elif args.mode == "ingest-ls": - config.hostname = None + config.hostname = "" elif args.mode == "ingest-rclone-json": - config.hostname = None + config.hostname = "" args.remote_base = args.remote_base[0] elif args.mode is None: parser.print_help() diff --git a/metadex/models.py b/metadex/models.py index 8c6b85d..0b968ed 100644 --- a/metadex/models.py +++ b/metadex/models.py @@ -17,10 +17,15 @@ asdict = asdict StatType = Literal["d", "f", "l", "-"] +def _mode(st_mode: int) -> StatType: + mode: StatType = _modes.get(S_IFMT(st_mode), "-") # type: ignore[assignment] + return mode + + @dataclass class File: - id: int - parent_id: int + id: "int | None" + parent_id: "int | None" added: datetime updated: datetime location: str @@ -35,6 +40,8 @@ class File: now = datetime.now() pstat = entry.stat(follow_symlinks=False) return cls( + id=None, + parent_id=None, added=now, updated=now, location=entry.path, @@ -42,7 +49,7 @@ class File: stat_bytes=pstat.st_size, # stat_changed=datetime.fromtimestamp(pstat.st_ctime), stat_modified=datetime.fromtimestamp(pstat.st_mtime), - stat_type=_modes.get(S_IFMT(pstat.st_mode), "-"), # type: ignore + stat_type=_mode(pstat.st_mode), ) @classmethod @@ -50,6 +57,8 @@ class File: now = datetime.now() pstat = os.stat(path, follow_symlinks=False) return cls( + id=None, + parent_id=None, added=now, updated=now, location=os.path.abspath(path), @@ -57,7 +66,7 @@ class File: stat_bytes=pstat.st_size, # stat_changed=datetime.fromtimestamp(pstat.st_ctime), stat_modified=datetime.fromtimestamp(pstat.st_mtime), - stat_type=_modes.get(S_IFMT(pstat.st_mode), "-"), # type: ignore + stat_type=_mode(pstat.st_mode), ) @staticmethod @@ -82,5 +91,5 @@ class File: hostname=config.hostname, stat_bytes=pstat.st_size, stat_modified=datetime.fromtimestamp(pstat.st_mtime), - stat_type=_modes.get(S_IFMT(pstat.st_mode), "-"), + stat_type=_mode(pstat.st_mode), )