zipseq ignore _archive
This commit is contained in:
@@ -59,24 +59,42 @@ def log(mode: str, message: str, *, verbose_only: bool = False, verbose: bool =
|
||||
print(f"[{mode}] {message}")
|
||||
|
||||
|
||||
def is_archive_path(path: Path) -> bool:
|
||||
return any(part == "_archive" for part in path.parts)
|
||||
|
||||
|
||||
def find_sequence_dirs(root: Path) -> Iterator[Path]:
|
||||
for dirpath, dirnames, filenames in os.walk(root):
|
||||
path = Path(dirpath)
|
||||
if ARCHIVE_ROOT in path.parents or path == ARCHIVE_ROOT:
|
||||
dirnames.clear()
|
||||
dirnames[:] = [d for d in dirnames if d != "_archive"]
|
||||
if is_archive_path(path):
|
||||
continue
|
||||
has_frames = any(Path(dirpath, f).suffix.lower() in SEQUENCE_EXTENSIONS for f in filenames)
|
||||
if has_frames:
|
||||
yield path
|
||||
|
||||
|
||||
def iter_sequence_files(seq_dir: Path) -> Iterator[Path]:
|
||||
for dirpath, dirnames, filenames in os.walk(seq_dir):
|
||||
path = Path(dirpath)
|
||||
dirnames[:] = [d for d in dirnames if d != "_archive"]
|
||||
if is_archive_path(path):
|
||||
continue
|
||||
for filename in filenames:
|
||||
yield path / filename
|
||||
|
||||
|
||||
def compute_state(seq_dir: Path) -> dict:
|
||||
entries = []
|
||||
for file_path in sorted(p for p in seq_dir.iterdir() if p.is_file()):
|
||||
files = sorted(
|
||||
iter_sequence_files(seq_dir),
|
||||
key=lambda p: p.relative_to(seq_dir).as_posix(),
|
||||
)
|
||||
for file_path in files:
|
||||
stat = file_path.stat()
|
||||
entries.append(
|
||||
{
|
||||
"path": file_path.name,
|
||||
"path": file_path.relative_to(seq_dir).as_posix(),
|
||||
"size": stat.st_size,
|
||||
"mtime_ns": stat.st_mtime_ns,
|
||||
}
|
||||
@@ -124,10 +142,8 @@ def zip_sequence(seq_dir: Path, zip_path: Path) -> None:
|
||||
|
||||
zip_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with ZipFile(zip_path, "w", compression=ZIP_STORED) as archive:
|
||||
for file_path in sorted(seq_dir.iterdir()):
|
||||
if not file_path.is_file():
|
||||
continue
|
||||
archive.write(file_path, arcname=file_path.name)
|
||||
for file_path in iter_sequence_files(seq_dir):
|
||||
archive.write(file_path, arcname=file_path.relative_to(seq_dir).as_posix())
|
||||
|
||||
|
||||
def expand_sequence(zip_path: Path, seq_state: dict) -> None:
|
||||
|
||||
Reference in New Issue
Block a user