From 4a325cca7171d8a1af4b0ad320730822b536bdc4 Mon Sep 17 00:00:00 2001 From: albertmena <12760268+albertmena@users.noreply.github.com> Date: Wed, 4 Dec 2024 14:32:37 +0100 Subject: [PATCH 01/12] adding scipion Field --- installer/api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/installer/api.py b/installer/api.py index d65449b65..b638bf80b 100644 --- a/installer/api.py +++ b/installer/api.py @@ -29,7 +29,7 @@ # General imports import re, hashlib, http.client, json, ssl from typing import Dict, Optional - +import os # Self imports from .cmake import parseCmakeVersions from .utils import runJob, getCurrentBranch, isBranchUpToDate, runParallelJobs @@ -136,6 +136,7 @@ def __getJSON(retCode: int=0) -> Optional[Dict]: # If branch is master or there is none, get release name branchName = XMIPP_VERSIONS[XMIPP][VERSION_KEY] if not jsonData[2] or jsonData[2] == MASTER_BRANCHNAME else jsonData[2] + isScipionUp = True if os.getenv("SCIPION_SOFTWARE") else isScipionUp = False # Introducing data into a dictionary return { @@ -158,7 +159,8 @@ def __getJSON(retCode: int=0) -> Optional[Dict]: }, "xmipp": { "branch": branchName, - "updated": jsonData[3] + "updated": jsonData[3], + "ScipionUp": isScipionUp }, "returnCode": retCode, "logTail": jsonData[4] if retCode else None # Only needs log tail if something went wrong From d4cb52e28cb474e65af6778150310d98be92669b Mon Sep 17 00:00:00 2001 From: albertmena <12760268+albertmena@users.noreply.github.com> Date: Thu, 5 Dec 2024 06:46:37 +0100 Subject: [PATCH 02/12] minor fix --- installer/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/api.py b/installer/api.py index b638bf80b..b375aa614 100644 --- a/installer/api.py +++ b/installer/api.py @@ -136,7 +136,7 @@ def __getJSON(retCode: int=0) -> Optional[Dict]: # If branch is master or there is none, get release name branchName = XMIPP_VERSIONS[XMIPP][VERSION_KEY] if not jsonData[2] or jsonData[2] == MASTER_BRANCHNAME else jsonData[2] - isScipionUp = True if os.getenv("SCIPION_SOFTWARE") else isScipionUp = False + isScipionUp = True if os.getenv("SCIPION_SOFTWARE") else False # Introducing data into a dictionary return { From 7ed648d457c2da89ca7ffcddc42949bb488a0d48 Mon Sep 17 00:00:00 2001 From: albertmena <12760268+albertmena@users.noreply.github.com> Date: Thu, 5 Dec 2024 07:00:36 +0100 Subject: [PATCH 03/12] CPUFlags --- installer/api.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/installer/api.py b/installer/api.py index b375aa614..ba40052d9 100644 --- a/installer/api.py +++ b/installer/api.py @@ -128,7 +128,7 @@ def __getJSON(retCode: int=0) -> Optional[Dict]: data = parseCmakeVersions(VERSION_FILE) jsonData = runParallelJobs([ (getOSReleaseName, ()), - (__getArchitectureName, ()), + (__getCPUFlags, ()), (getCurrentBranch, ()), (isBranchUpToDate, ()), (__getLogTail, ()) @@ -145,7 +145,7 @@ def __getJSON(retCode: int=0) -> Optional[Dict]: }, "version": { "os": jsonData[0], - "architecture": jsonData[1], + "CPUFlags": jsonData[1], "cuda": data.get(CMAKE_CUDA), "cmake": data.get(CMAKE_CMAKE), "gcc": data.get(CMAKE_GCC), @@ -239,22 +239,20 @@ def __getLogTail() -> Optional[str]: # Return content if it went right return output if retCode == 0 else None -def __getArchitectureName() -> str: - """ - ### This function returns the name of the system's architecture name. - #### Returns: - - (str): Architecture name. - """ - # Initializing to unknown value - archName = UNKNOWN_VALUE - # Obtaining architecture name - retCode, architecture = runJob('cat /sys/devices/cpu/caps/pmu_name') +def __getCPUFlags(lscpu_output) -> str: + lines = lscpu_output.splitlines() + flags = [] + capture = False - # If command worked and returned info, extract it - if retCode == 0 and architecture: - archName = architecture - - # Returing architecture name - return archName + for line in lines: + if "Flags:" in line: + capture = True + flags.append(line.split("Flags:")[1].strip()) + elif capture: + if line.startswith(" "): + flags.append(line.strip()) + else: + break + return " ".join(flags) From c330ec34a082cc2b40e93fcadf1515a64da8e1b5 Mon Sep 17 00:00:00 2001 From: alberto Date: Thu, 5 Dec 2024 10:05:46 +0100 Subject: [PATCH 04/12] Update api.py --- installer/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/installer/api.py b/installer/api.py index ba40052d9..43ff99bde 100644 --- a/installer/api.py +++ b/installer/api.py @@ -136,7 +136,7 @@ def __getJSON(retCode: int=0) -> Optional[Dict]: # If branch is master or there is none, get release name branchName = XMIPP_VERSIONS[XMIPP][VERSION_KEY] if not jsonData[2] or jsonData[2] == MASTER_BRANCHNAME else jsonData[2] - isScipionUp = True if os.getenv("SCIPION_SOFTWARE") else False + installedByScipion = True if os.getenv("SCIPION_SOFTWARE") else False # Introducing data into a dictionary return { @@ -160,7 +160,7 @@ def __getJSON(retCode: int=0) -> Optional[Dict]: "xmipp": { "branch": branchName, "updated": jsonData[3], - "ScipionUp": isScipionUp + "installedByScipion": installedByScipion }, "returnCode": retCode, "logTail": jsonData[4] if retCode else None # Only needs log tail if something went wrong From 311c9de7137b098a3f77634624daa36d3463c69b Mon Sep 17 00:00:00 2001 From: Martin Salinas Date: Thu, 5 Dec 2024 12:02:30 +0100 Subject: [PATCH 05/12] Simplified --- installer/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/api.py b/installer/api.py index 43ff99bde..fc9225899 100644 --- a/installer/api.py +++ b/installer/api.py @@ -136,7 +136,7 @@ def __getJSON(retCode: int=0) -> Optional[Dict]: # If branch is master or there is none, get release name branchName = XMIPP_VERSIONS[XMIPP][VERSION_KEY] if not jsonData[2] or jsonData[2] == MASTER_BRANCHNAME else jsonData[2] - installedByScipion = True if os.getenv("SCIPION_SOFTWARE") else False + installedByScipion = bool(os.getenv("SCIPION_SOFTWARE")) # Introducing data into a dictionary return { From 31008558c2be2adfdada805408c1fe7a718c8a9a Mon Sep 17 00:00:00 2001 From: albertmena <12760268+albertmena@users.noreply.github.com> Date: Thu, 5 Dec 2024 13:58:53 +0100 Subject: [PATCH 06/12] refactoring --- installer/api.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/installer/api.py b/installer/api.py index fc9225899..05cf74842 100644 --- a/installer/api.py +++ b/installer/api.py @@ -241,18 +241,14 @@ def __getLogTail() -> Optional[str]: -def __getCPUFlags(lscpu_output) -> str: - lines = lscpu_output.splitlines() - flags = [] - capture = False - - for line in lines: - if "Flags:" in line: - capture = True - flags.append(line.split("Flags:")[1].strip()) - elif capture: - if line.startswith(" "): - flags.append(line.strip()) - else: - break - return " ".join(flags) +def __getCPUFlags() -> str: + """ + ### This function returns a string with the flags provided by lscpu. + """ + log = [] + returnCode, outputStr = runJob('lscpu | grep Flags', logOutput=log) + if returnCode == 0: + flagsCPU = outputStr.replace('Flags:', '').replace(' ', '') + return flagsCPU + else: + return'Unknow' From 592bed15a797a93944c3078e4e421e4dd15d6ff7 Mon Sep 17 00:00:00 2001 From: albertmena <12760268+albertmena@users.noreply.github.com> Date: Thu, 5 Dec 2024 14:01:00 +0100 Subject: [PATCH 07/12] refactoring --- installer/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/api.py b/installer/api.py index 3e8a828f4..38f92f207 100644 --- a/installer/api.py +++ b/installer/api.py @@ -30,8 +30,8 @@ import re, hashlib, http.client, json from typing import Dict, Optional from urllib.parse import urlparse - import os + # Self imports from .cmake import parseCmakeVersions from .utils import runJob, getCurrentBranch, isBranchUpToDate, runParallelJobs From c0e53b69bca52125a5e7cb9e2b9a6b6675a5b248 Mon Sep 17 00:00:00 2001 From: albertmena <12760268+albertmena@users.noreply.github.com> Date: Mon, 9 Dec 2024 07:30:11 +0100 Subject: [PATCH 08/12] renaming architecture and minor fixing --- installer/api.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/installer/api.py b/installer/api.py index 38f92f207..b075d6a62 100644 --- a/installer/api.py +++ b/installer/api.py @@ -66,8 +66,8 @@ def sendApiPOST(retCode: int=0): conn.request("POST", parsedUrl.path, body=params, headers=headers) # Get response from server - conn.getresponse() - + response = conn.getresponse() + # response.reason # Close the connection conn.close() except TimeoutError: @@ -145,7 +145,7 @@ def __getJSON(retCode: int=0) -> Optional[Dict]: }, "version": { "os": jsonData[0], - "CPUFlags": jsonData[1], + "architecture": jsonData[1], "cuda": data.get(CMAKE_CUDA), "cmake": data.get(CMAKE_CMAKE), "gcc": data.get(CMAKE_GCC), @@ -239,16 +239,12 @@ def __getLogTail() -> Optional[str]: # Return content if it went right return output if retCode == 0 else None - - def __getCPUFlags() -> str: """ ### This function returns a string with the flags provided by lscpu. """ - log = [] - returnCode, outputStr = runJob('lscpu | grep Flags', logOutput=log) + returnCode, outputStr = runJob('lscpu | grep Flags') if returnCode == 0: - flagsCPU = outputStr.replace('Flags:', '').replace(' ', '') - return flagsCPU - else: - return'Unknow' + flagsCPU = outputStr.replace('Flags:', '').strip() + return flagsCPU + return UNKNOWN_VALUE From 1515cd29c9f0b37fd65d9d7b813ca373e45cd4e7 Mon Sep 17 00:00:00 2001 From: albertmena <12760268+albertmena@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:27:55 +0100 Subject: [PATCH 09/12] minor --- installer/api.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/installer/api.py b/installer/api.py index a558ff432..8be199986 100644 --- a/installer/api.py +++ b/installer/api.py @@ -49,7 +49,6 @@ def sendApiPOST(retCode: int=0): """ # Getting JSON data for curl command bodyParams = __getJSON(retCode=retCode) - # Send API POST request if there were no errors if bodyParams is not None: # Define the parameters for the POST request @@ -66,8 +65,7 @@ def sendApiPOST(retCode: int=0): conn.request("POST", parsedUrl.path, body=params, headers=headers) # Get response from server - response = conn.getresponse() - # response.reason + conn.getresponse() # Close the connection conn.close() except Exception: From 60e2a12c6f8a432996cb2d376337f90741be59b8 Mon Sep 17 00:00:00 2001 From: albertmena <12760268+albertmena@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:29:58 +0100 Subject: [PATCH 10/12] minor --- installer/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/api.py b/installer/api.py index 8be199986..83c1f4de5 100644 --- a/installer/api.py +++ b/installer/api.py @@ -243,6 +243,6 @@ def __getCPUFlags() -> str: """ returnCode, outputStr = runJob('lscpu | grep Flags') if returnCode == 0: - flagsCPU = outputStr.replace('Flags:', '').strip() + flagsCPU = outputStr.replace('Flags:', '').strip().split(" ") return flagsCPU return UNKNOWN_VALUE From 4a5a4cec498cbfad33fa130dfefd09233a120f18 Mon Sep 17 00:00:00 2001 From: albertmena <12760268+albertmena@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:30:28 +0100 Subject: [PATCH 11/12] minor --- installer/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/api.py b/installer/api.py index 83c1f4de5..8be199986 100644 --- a/installer/api.py +++ b/installer/api.py @@ -243,6 +243,6 @@ def __getCPUFlags() -> str: """ returnCode, outputStr = runJob('lscpu | grep Flags') if returnCode == 0: - flagsCPU = outputStr.replace('Flags:', '').strip().split(" ") + flagsCPU = outputStr.replace('Flags:', '').strip() return flagsCPU return UNKNOWN_VALUE From 37a33e7f5f5ccd8fdad0cab32e0d8c1b17267a19 Mon Sep 17 00:00:00 2001 From: Martin Salinas Date: Tue, 10 Dec 2024 11:35:20 +0100 Subject: [PATCH 12/12] Establish connection inside try block --- installer/api.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/installer/api.py b/installer/api.py index 8be199986..0f196804e 100644 --- a/installer/api.py +++ b/installer/api.py @@ -55,15 +55,12 @@ def sendApiPOST(retCode: int=0): params = json.dumps(bodyParams) # Set up the headers headers = {"Content-type": "application/json"} - - # Establish a connection parsedUrl = urlparse(API_URL) - conn = http.client.HTTPSConnection(parsedUrl.hostname, parsedUrl.port, timeout=4) - try: + # Establish a connection + conn = http.client.HTTPSConnection(parsedUrl.hostname, parsedUrl.port, timeout=4) # Send the POST request conn.request("POST", parsedUrl.path, body=params, headers=headers) - # Get response from server conn.getresponse() # Close the connection