Skip to content

Commit

Permalink
FIXUP: Also hash the current date
Browse files Browse the repository at this point in the history
  • Loading branch information
almet authored and apyrgio committed Sep 27, 2024
1 parent 6acba26 commit 3af1745
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions dev_scripts/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import subprocess
import sys
import urllib.request
from datetime import date

DEFAULT_GUI = True
DEFAULT_USER = "user"
Expand Down Expand Up @@ -292,29 +293,24 @@ def distro_build(distro, version):

def image_name_build_dev(distro, version):
"""Get the container image for the dev variant of a Dangerzone environment."""
hash = get_files_hash(
[
git_root() / "dev_scripts/env.py", # ? dev_scripts/** ?
hash = hash_files(
get_files_in("dev_scripts")
+ [
git_root() / "pyproject.toml",
git_root() / "poetry.lock",
]
],
include_current_date=True,
)

return IMAGE_NAME_BUILD_DEV_FMT.format(distro=distro, version=version, hash=hash)


def get_folders_files(folders: list[str]) -> list[pathlib.Path]:
"""Return the list of all files present in the given folders"""
files = []
for folder in folders:
files.extend([p for p in (git_root() / folder).glob("**") if p.is_file()])
return files


def image_name_build_enduser(distro, version):
"""Get the container image for the Dangerzone end-user environment."""

hash = get_files_hash(get_folders_files(["install/linux", "debian"]))
hash = hash_files(
get_files_in("install/linux", "debian"), include_current_date=True
)
return IMAGE_NAME_BUILD_ENDUSER_FMT.format(
distro=distro, version=version, hash=hash
)
Expand All @@ -326,17 +322,34 @@ def dz_version():
return f.read().strip()


def get_files_hash(file_paths: list[pathlib.Path]) -> str:
"""Returns the hash value of a list of files using the sha256 hashing algorithm."""
def hash_files(
file_paths: list[pathlib.Path], include_current_date: bool = False
) -> str:
"""Returns the hash value of a list of files using the sha256 hashing algorithm.
If specified, also adds the current date in the hash.
"""
hash_obj = hashlib.new("sha256")
for path in file_paths:
with open(path, "rb") as file:
file_data = file.read()
hash_obj.update(file_data)

if include_current_date:
current_date = date.today().strftime("%Y-%m-%d")
hash_obj.update(current_date.encode())

return hash_obj.hexdigest()


def get_files_in(*folders: list[str]) -> list[pathlib.Path]:
"""Return the list of all files present in the given folders"""
files = []
for folder in folders:
files.extend([p for p in (git_root() / folder).glob("**") if p.is_file()])
return files


class PySide6Manager:
"""Provision PySide6 RPMs in our Dangerzone environments.
Expand Down

0 comments on commit 3af1745

Please sign in to comment.