summaryrefslogtreecommitdiffstats
path: root/cli/utils.py
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-11-07 16:26:55 +0100
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-11-11 12:16:04 +0100
commit38f373addb05b14abb8de6c29408a4fe215a5bbc (patch)
tree32a8d4204f24bc906944959bb668e92368248d3f /cli/utils.py
parenta219bc7ff729516aea7ddea8516b50d96e7d9363 (diff)
cli: add live management commands
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 live live --remote
Diffstat (limited to 'cli/utils.py')
-rw-r--r--cli/utils.py20
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()