mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 14:04:34 +00:00
Support file shares in NC manifest
This commit is contained in:
@@ -32,7 +32,7 @@ def query_rows(args: argparse.Namespace) -> list[list[str]]:
|
|||||||
password = args.password_file.read_text(encoding="utf-8").strip()
|
password = args.password_file.read_text(encoding="utf-8").strip()
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env["PGPASSWORD"] = password
|
env["PGPASSWORD"] = password
|
||||||
sql = f"SELECT share_id, display_name, storage_id, source_path FROM {args.view} ORDER BY share_id"
|
sql = f"SELECT share_id, item_type, display_name, storage_id, source_path FROM {args.view} ORDER BY share_id"
|
||||||
command = [
|
command = [
|
||||||
"psql", "-X", "-A", "-F", "\t", "-t",
|
"psql", "-X", "-A", "-F", "\t", "-t",
|
||||||
"-h", args.host, "-p", str(args.port), "-U", args.user, "-d", args.database,
|
"-h", args.host, "-p", str(args.port), "-U", args.user, "-d", args.database,
|
||||||
@@ -57,15 +57,25 @@ def build(args: argparse.Namespace) -> dict[str, object]:
|
|||||||
|
|
||||||
manifest: list[str] = []
|
manifest: list[str] = []
|
||||||
errors: list[str] = []
|
errors: list[str] = []
|
||||||
|
folder_count = 0
|
||||||
|
file_count = 0
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
if len(row) != 4:
|
if len(row) != 5:
|
||||||
errors.append(f"invalid database row with {len(row)} columns")
|
errors.append(f"invalid database row with {len(row)} columns")
|
||||||
continue
|
continue
|
||||||
share_id, display_name, storage_id, source_path = row
|
|
||||||
|
share_id, item_type, display_name, storage_id, source_path = row
|
||||||
|
item_type = item_type.strip().lower()
|
||||||
|
if item_type not in {"folder", "file"}:
|
||||||
|
errors.append(f"share {share_id}: unsupported item_type {item_type!r}")
|
||||||
|
continue
|
||||||
|
|
||||||
adapter = adapters.get(storage_id)
|
adapter = adapters.get(storage_id)
|
||||||
if not adapter:
|
if not adapter:
|
||||||
errors.append(f"share {share_id}: unknown storage {storage_id}")
|
errors.append(f"share {share_id}: unknown storage {storage_id}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
prefix, mount = adapter
|
prefix, mount = adapter
|
||||||
relative = source_path.strip("/")
|
relative = source_path.strip("/")
|
||||||
if prefix:
|
if prefix:
|
||||||
@@ -74,14 +84,24 @@ def build(args: argparse.Namespace) -> dict[str, object]:
|
|||||||
errors.append(f"share {share_id}: path does not match configured prefix")
|
errors.append(f"share {share_id}: path does not match configured prefix")
|
||||||
continue
|
continue
|
||||||
relative = relative[len(prefix):].lstrip("/")
|
relative = relative[len(prefix):].lstrip("/")
|
||||||
|
|
||||||
source = contained_join(mount, relative)
|
source = contained_join(mount, relative)
|
||||||
if not mount.is_mount():
|
if not mount.is_mount():
|
||||||
errors.append(f"share {share_id}: storage mount unavailable: {mount}")
|
errors.append(f"share {share_id}: storage mount unavailable: {mount}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if item_type == "folder":
|
||||||
if not source.is_dir():
|
if not source.is_dir():
|
||||||
errors.append(f"share {share_id}: source directory unavailable: {source}")
|
errors.append(f"share {share_id}: source directory unavailable: {source}")
|
||||||
continue
|
continue
|
||||||
manifest.append(f"{share_id}\t{display_name.lstrip('/')}\t{source}")
|
folder_count += 1
|
||||||
|
else:
|
||||||
|
if not source.is_file():
|
||||||
|
errors.append(f"share {share_id}: source file unavailable: {source}")
|
||||||
|
continue
|
||||||
|
file_count += 1
|
||||||
|
|
||||||
|
manifest.append(f"{share_id}\t{item_type}\t{display_name.lstrip('/')}\t{source}")
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
raise RuntimeError("; ".join(errors))
|
raise RuntimeError("; ".join(errors))
|
||||||
@@ -93,7 +113,13 @@ def build(args: argparse.Namespace) -> dict[str, object]:
|
|||||||
handle.write("\n".join(manifest) + ("\n" if manifest else ""))
|
handle.write("\n".join(manifest) + ("\n" if manifest else ""))
|
||||||
temporary = Path(handle.name)
|
temporary = Path(handle.name)
|
||||||
temporary.replace(args.output)
|
temporary.replace(args.output)
|
||||||
return {"shares": len(manifest), "manifest": str(args.output)}
|
|
||||||
|
return {
|
||||||
|
"shares": len(manifest),
|
||||||
|
"folders": folder_count,
|
||||||
|
"files": file_count,
|
||||||
|
"manifest": str(args.output),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
|
|||||||
Reference in New Issue
Block a user