diff options
author | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-11-07 16:26:55 +0100 |
---|---|---|
committer | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-11-21 11:36:29 +0100 |
commit | 4015174300bf5e15eee6c62f9bae84dc1ab17317 (patch) | |
tree | b5bd4e3dbe8d0aae5ac6ac1cec196413df381c85 /cli/utils.py | |
parent | a219bc7ff729516aea7ddea8516b50d96e7d9363 (diff) |
cli: add live management commands
Add new parameters to the config file ogcli.json with the
following default values:
'local_live': '/var/www/html/ogrelive'
'server_live': 'https://opengnsys.soleta.eu/ogrelive'
Add command to install the files of a live system. Example:
ogcli install live --name ogrelive-6.1.0-26
Perform an update if live files are already present.
Add command to delete the files of a live system. Example:
ogcli delete live --name ogrelive-6.1.0-26
Update ogcli list live to show the lives in the server when
invoked with the --remote flag. Example:
ogcli list live --remote
Diffstat (limited to 'cli/utils.py')
-rw-r--r-- | cli/utils.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/cli/utils.py b/cli/utils.py index 3825583..380bd5b 100644 --- a/cli/utils.py +++ b/cli/utils.py @@ -8,7 +8,9 @@ import unicodedata import json import ipaddress +import hashlib import re +import os def scope_lookup(scope_id, scope_type, d): if scope_id == d.get('id') and scope_type == d.get('type'): @@ -69,3 +71,21 @@ def check_mac_address(addr): def remove_accents(text): normalized_text = unicodedata.normalize('NFD', text) return ''.join(c for c in normalized_text if unicodedata.category(c) != 'Mn') + +def compute_md5(path, bs=2**20): + if not os.path.exists(path): + print(f"Failed to calculate checksum, image file {path} does not exist") + return None + + m = hashlib.md5() + try: + with open(path, 'rb') as f: + while True: + buf = f.read(bs) + if not buf: + break + m.update(buf) + except Exception as e: + print(f'Failed to calculate checksum for {path}: {e}') + return None + return m.hexdigest() |