Skip to content

Commit e72e2e9

Browse files
authored
Merge pull request #957 from I2PC/agm_ScipionField
adding scipion Field and replacing architecture by CPUFlags
2 parents 37ca78f + 37a33e7 commit e72e2e9

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

installer/api.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import re, hashlib, http.client, json
3131
from typing import Dict, Optional
3232
from urllib.parse import urlparse
33+
import os
3334

3435
# Self imports
3536
from .cmake import parseCmakeVersions
@@ -48,25 +49,20 @@ def sendApiPOST(retCode: int=0):
4849
"""
4950
# Getting JSON data for curl command
5051
bodyParams = __getJSON(retCode=retCode)
51-
5252
# Send API POST request if there were no errors
5353
if bodyParams is not None:
5454
# Define the parameters for the POST request
5555
params = json.dumps(bodyParams)
5656
# Set up the headers
5757
headers = {"Content-type": "application/json"}
58-
59-
# Establish a connection
6058
parsedUrl = urlparse(API_URL)
61-
conn = http.client.HTTPSConnection(parsedUrl.hostname, parsedUrl.port, timeout=4)
62-
6359
try:
60+
# Establish a connection
61+
conn = http.client.HTTPSConnection(parsedUrl.hostname, parsedUrl.port, timeout=4)
6462
# Send the POST request
6563
conn.request("POST", parsedUrl.path, body=params, headers=headers)
66-
6764
# Get response from server
6865
conn.getresponse()
69-
7066
# Close the connection
7167
conn.close()
7268
except Exception:
@@ -127,14 +123,15 @@ def __getJSON(retCode: int=0) -> Optional[Dict]:
127123
data = parseCmakeVersions(VERSION_FILE)
128124
jsonData = runParallelJobs([
129125
(getOSReleaseName, ()),
130-
(__getArchitectureName, ()),
126+
(__getCPUFlags, ()),
131127
(getCurrentBranch, ()),
132128
(isBranchUpToDate, ()),
133129
(__getLogTail, ())
134130
])
135131

136132
# If branch is master or there is none, get release name
137133
branchName = XMIPP_VERSIONS[XMIPP][VERSION_KEY] if not jsonData[2] or jsonData[2] == MASTER_BRANCHNAME else jsonData[2]
134+
installedByScipion = bool(os.getenv("SCIPION_SOFTWARE"))
138135

139136
# Introducing data into a dictionary
140137
return {
@@ -157,7 +154,8 @@ def __getJSON(retCode: int=0) -> Optional[Dict]:
157154
},
158155
"xmipp": {
159156
"branch": branchName,
160-
"updated": jsonData[3]
157+
"updated": jsonData[3],
158+
"installedByScipion": installedByScipion
161159
},
162160
"returnCode": retCode,
163161
"logTail": jsonData[4] if retCode else None # Only needs log tail if something went wrong
@@ -236,22 +234,12 @@ def __getLogTail() -> Optional[str]:
236234
# Return content if it went right
237235
return output if retCode == 0 else None
238236

239-
def __getArchitectureName() -> str:
240-
"""
241-
### This function returns the name of the system's architecture name.
242-
243-
#### Returns:
244-
- (str): Architecture name.
245-
"""
246-
# Initializing to unknown value
247-
archName = UNKNOWN_VALUE
248-
249-
# Obtaining architecture name
250-
retCode, architecture = runJob('cat /sys/devices/cpu/caps/pmu_name')
251-
252-
# If command worked and returned info, extract it
253-
if retCode == 0 and architecture:
254-
archName = architecture
255-
256-
# Returing architecture name
257-
return archName
237+
def __getCPUFlags() -> str:
238+
"""
239+
### This function returns a string with the flags provided by lscpu.
240+
"""
241+
returnCode, outputStr = runJob('lscpu | grep Flags')
242+
if returnCode == 0:
243+
flagsCPU = outputStr.replace('Flags:', '').strip()
244+
return flagsCPU
245+
return UNKNOWN_VALUE

0 commit comments

Comments
 (0)