11from __future__ import annotations
22
33import argparse
4+ import logging
45import os
56import subprocess
67import zipfile
1112
1213_T = TypeVar ("_T" )
1314
15+ logger = logging .getLogger (__name__ )
16+
1417
1518def unique_by_index (sequence : Iterable [_T ]) -> list [_T ]:
1619 """unique elements in `sequence` in the order in which they occur
@@ -90,6 +93,7 @@ def zip2dir(zip_fname: Path, out_dir: Path) -> None:
9093 out_dir : str
9194 Directory path containing files to go in the zip archive
9295 """
96+ start = datetime .now ()
9397 with zipfile .ZipFile (zip_fname , "r" ) as z :
9498 for name in z .namelist ():
9599 member = z .getinfo (name )
@@ -102,6 +106,7 @@ def zip2dir(zip_fname: Path, out_dir: Path) -> None:
102106 attr &= 511 # only keep permission bits
103107 attr |= 6 << 6 # at least read/write for current user
104108 os .chmod (extracted_path , attr )
109+ logger .info (f"zip2dir from { zip_fname } to { out_dir } takes { datetime .now () - start } " )
105110
106111
107112def dir2zip (in_dir : Path , zip_fname : Path , date_time : datetime | None = None ) -> None :
@@ -120,6 +125,7 @@ def dir2zip(in_dir: Path, zip_fname: Path, date_time: datetime | None = None) ->
120125 date_time : Optional[datetime]
121126 Time stamp to set on each file in the archive
122127 """
128+ start = datetime .now ()
123129 in_dir = in_dir .resolve (strict = True )
124130 if date_time is None :
125131 st = in_dir .stat ()
@@ -141,6 +147,7 @@ def dir2zip(in_dir: Path, zip_fname: Path, date_time: datetime | None = None) ->
141147 zinfo .compress_type = compression
142148 with open (fname , "rb" ) as fp :
143149 z .writestr (zinfo , fp .read ())
150+ logger .info (f"dir2zip from { in_dir } to { zip_fname } takes { datetime .now () - start } " )
144151
145152
146153def tarbz2todir (tarbz2_fname : Path , out_dir : Path ) -> None :
0 commit comments