Commit 06cf43fe authored by Matthieu Boileau's avatar Matthieu Boileau
Browse files

update zip_files definition

parent f6b766b7
......@@ -311,8 +311,8 @@ class NbCourse:
'targets': [self.zip_file],
'clean': True,
'actions': [(zip_files, (self.zip_file, paths_to_zip),
{'refpath': self.conf['output_path'],
'arcdir': self.conf['slug_title']})],
{'ref_to_arc': (self.conf['output_path'],
self.conf['slug_title'])})],
}
def run(self, args: list):
......
......@@ -40,11 +40,20 @@ def update_dict(current: dict, new: dict):
current[k] = v
def zip_files(zip_file_name: Path, paths_to_zip: list, refpath: Path = None,
arcdir: str = None):
"""Archive files_to_zip in zip file"""
def zip_files(zip_file_name: Path, paths_to_zip: list,
ref_to_arc: tuple = None):
"""
Archive files_to_zip in zip file
:param ref_to_arc: a ('refpath', 'arcdir') tuple
"""
if ref_to_arc:
refpath = ref_to_arc[0]
arcdir = ref_to_arc[1]
with ZipFile(zip_file_name, 'w') as zf:
for path in paths_to_zip:
# Convert refpath/file in arcdir/file if asked
arcpath = arcdir / path.relative_to(refpath) if refpath else None
arcpath = arcdir / path.relative_to(refpath) \
if ref_to_arc else None
zf.write(path, arcname=arcpath)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment