summaryrefslogtreecommitdiffstats
path: root/cli/utils.py
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-11-07 16:26:55 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-11-21 17:05:26 +0100
commit85d910d0203370311ef3eba134dafbc49bd46ac1 (patch)
treebf49860ab61dfdc832de8b6f50f3e0e49cdfd95e /cli/utils.py
parentc4eb5d165a00fbe7e5ec2e9a1e7f2123ce09bcd5 (diff)
cli: add live management commandsv0.3.3-14
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.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()