1
1
from __future__ import annotations
2
2
3
3
import argparse
4
+ import logging
4
5
import os
5
6
import subprocess
6
7
import zipfile
11
12
12
13
_T = TypeVar ("_T" )
13
14
15
+ logger = logging .getLogger (__name__ )
16
+
14
17
15
18
def unique_by_index (sequence : Iterable [_T ]) -> list [_T ]:
16
19
"""unique elements in `sequence` in the order in which they occur
@@ -90,6 +93,7 @@ def zip2dir(zip_fname: Path, out_dir: Path) -> None:
90
93
out_dir : str
91
94
Directory path containing files to go in the zip archive
92
95
"""
96
+ start = datetime .now ()
93
97
with zipfile .ZipFile (zip_fname , "r" ) as z :
94
98
for name in z .namelist ():
95
99
member = z .getinfo (name )
@@ -102,6 +106,7 @@ def zip2dir(zip_fname: Path, out_dir: Path) -> None:
102
106
attr &= 511 # only keep permission bits
103
107
attr |= 6 << 6 # at least read/write for current user
104
108
os .chmod (extracted_path , attr )
109
+ logger .info (f"zip2dir from { zip_fname } to { out_dir } takes { datetime .now () - start } " )
105
110
106
111
107
112
def 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) ->
120
125
date_time : Optional[datetime]
121
126
Time stamp to set on each file in the archive
122
127
"""
128
+ start = datetime .now ()
123
129
in_dir = in_dir .resolve (strict = True )
124
130
if date_time is None :
125
131
st = in_dir .stat ()
@@ -141,6 +147,7 @@ def dir2zip(in_dir: Path, zip_fname: Path, date_time: datetime | None = None) ->
141
147
zinfo .compress_type = compression
142
148
with open (fname , "rb" ) as fp :
143
149
z .writestr (zinfo , fp .read ())
150
+ logger .info (f"dir2zip from { in_dir } to { zip_fname } takes { datetime .now () - start } " )
144
151
145
152
146
153
def tarbz2todir (tarbz2_fname : Path , out_dir : Path ) -> None :
0 commit comments