Skip to content

Commit

Permalink
Add comment to zip file with used Annif version
Browse files Browse the repository at this point in the history
  • Loading branch information
juhoinkinen committed Mar 4, 2024
1 parent d5b4abe commit a1e7605
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions annif/cli_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import binascii
import collections
import configparser
import importlib
import io
import itertools
import os
Expand Down Expand Up @@ -252,6 +253,10 @@ def archive_dir(data_dir):
path = pathlib.Path(data_dir)
fpaths = [fpath for fpath in path.glob("**/*") if not _is_train_file(fpath.name)]
with zipfile.ZipFile(fp, mode="w") as zfile:
zfile.comment = bytes(
f"Archived by Annif {importlib.metadata.version('annif')}",
encoding="utf-8",
)
for fpath in fpaths:
logger.debug(f"Adding {fpath}")
zfile.write(fpath)
Expand Down Expand Up @@ -321,6 +326,10 @@ def download_from_hf_hub(filename, repo_id, token, revision):

def unzip(src_path, force):
with zipfile.ZipFile(src_path, "r") as zfile:
logger.debug(
f"Extracting archive {src_path}; archive comment: "
f"\"{str(zfile.comment, encoding='utf-8')}\""
)
for member in zfile.infolist():
if os.path.exists(member.filename) and not force:
if _is_existing_identical(member):
Expand Down

0 comments on commit a1e7605

Please sign in to comment.