Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow posting without the versions file #951

Merged
merged 10 commits into from
Nov 29, 2024
49 changes: 34 additions & 15 deletions installer/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"""
Module containing all functions needed for the metric's API request.
"""

import os.path
# General imports
import re, hashlib, http.client, json, ssl
from typing import Dict, Optional
Expand All @@ -47,7 +47,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
Expand All @@ -59,6 +58,7 @@ def sendApiPOST(retCode: int=0):
url = API_URL.split("/", maxsplit=1)
path = f"/{url[1]}"
url = url[0]

conn = http.client.HTTPSConnection(url, timeout=2, context=ssl._create_unverified_context()) # Unverified context because url does not have an ssl certificate

try:
Expand Down Expand Up @@ -124,25 +124,18 @@ def __getJSON(retCode: int=0) -> Optional[Dict]:
if userId is None:
return

# Obtaining variables in parallel
data = parseCmakeVersions(VERSION_FILE)
jsonData = runParallelJobs([
(getOSReleaseName, ()),
(__getArchitectureName, ()),
(getCurrentBranch, ()),
(isBranchUpToDate, ()),
(__getLogTail, ())
])

# 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]

# Introducing data into a dictionary
return {
"user": {
"userId": userId
},
"version": {

# Obtaining variables in parallel
if os.path.isfile(VERSION_FILE):
data = parseCmakeVersions(VERSION_FILE)
version = {
"os": jsonData[0],
"architecture": jsonData[1],
"cuda": data.get(CMAKE_CUDA),
Expand All @@ -155,15 +148,41 @@ def __getJSON(retCode: int=0) -> Optional[Dict]:
"java": data.get(CMAKE_JAVA),
"hdf5": data.get(CMAKE_HDF5),
"jpeg": data.get(CMAKE_JPEG)
}
else:
version = {
"os": jsonData[0],
"architecture": jsonData[1],
"cuda": '',
"cmake": '',
"gcc": '',
"gpp": '',
"mpi": '',
"python": '',
"sqlite": '',
"java": '',
"hdf5": '',
"jpeg": ''
}
MartinSalinas98 marked this conversation as resolved.
Show resolved Hide resolved


# 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]

# Introducing data into a dictionary
return {
"user": {
"userId": userId
},
"version": version,
"xmipp": {
"branch": branchName,
"updated": jsonData[3]
},
"returnCode": retCode,
"logTail": jsonData[4] if retCode else None # Only needs log tail if something went wrong
}

def __getMACAddress() -> Optional[str]:
"""
### This function returns a physical MAC address for this machine. It prioritizes ethernet over wireless.
Expand Down
3 changes: 2 additions & 1 deletion installer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def handleRetCode(realRetCode: int, predefinedErrorCode: int=0, message: str='',
resultCode = __getPredefinedError(realRetCode=realRetCode, desiredRetCode=predefinedErrorCode)
message = message if resultCode != realRetCode else ''
logger.logError(message, retCode=resultCode, addPortalLink=resultCode != realRetCode)
if sendAPI and os.path.exists(VERSION_FILE) and resultCode != INTERRUPTED_ERROR:

if sendAPI and resultCode != INTERRUPTED_ERROR:
sendApiPOST(resultCode)
exitXmipp(retCode=resultCode)
else:
Expand Down