From 4015174300bf5e15eee6c62f9bae84dc1ab17317 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Thu, 7 Nov 2024 16:26:55 +0100 Subject: 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 --- cli/utils.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'cli/utils.py') 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() -- cgit v1.2.3-18-g5258