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

Fix missing API calls #913

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion installer/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ def sendApiPOST(retCode: int=0):
url = API_URL.split("/", maxsplit=1)
path = f"/{url[1]}"
url = url[0]
conn = http.client.HTTPSConnection(url, context=ssl._create_unverified_context()) # Unverified context because url does not have an ssl certificate
conn = http.client.HTTPSConnection(url, timeout=2, context=ssl._create_unverified_context()) # Unverified context because url does not have an ssl certificate

# Send the POST request
conn.request("POST", path, params, headers)

# Get response from server
conn.getresponse()

# Close the connection
conn.close()

Expand Down
14 changes: 6 additions & 8 deletions installer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,36 +54,34 @@ def getSources(branch: str=None):
logger(f"Cloning {source}...", forceConsoleOutput=True)
retCode, output = __cloneSourceRepo(REPOSITORIES[source][0], path=SOURCES_PATH, branch=branch)
message = output if retCode else ''
handleRetCode(retCode, predefinedErrorCode=SOURCE_CLONE_ERROR, message=message)
handleRetCode(retCode, predefinedErrorCode=SOURCE_CLONE_ERROR, message=message, sendAPI=False)

def exitXmipp(retCode: int=0, sendAPI: bool=True):
def exitXmipp(retCode: int=0):
"""
### This function exits Xmipp with the given return code, processing it as a success or an error.

#### Params:
- retCode (int): Optional. Error code.
- sendAPI (bool): Optional. If True, API message will be sent.
"""
# Send API message
if sendAPI and os.path.exists(VERSION_FILE) and retCode != INTERRUPTED_ERROR:
sendApiPOST(retCode=retCode)

# End execution
sys.exit(retCode)

def handleRetCode(realRetCode: int, predefinedErrorCode: int=0, message: str=''):
def handleRetCode(realRetCode: int, predefinedErrorCode: int=0, message: str='', sendAPI: bool=True):
"""
### This function checks the given return code and handles the appropiate actions.

#### Params:
- realRetCode (int): Real return code of the called function.
- predefinedErrorCode (int): Optional. Predefined error code for the caller code block in case of error.
- message (str): Optional. Message that will be displayed if there is an error th
- sendAPI (bool): Optional. If True, API message will be sent.
"""
if realRetCode:
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:
sendApiPOST(resultCode)
exitXmipp(retCode=resultCode)
else:
if message:
Expand Down
11 changes: 8 additions & 3 deletions xmipp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ from installer.constants import (MODE_ALL, MODE_COMPILE_AND_INSTALL, MODE_CONFIG
CMAKE_CONFIGURE_ERROR, CMAKE_COMPILE_ERROR, CMAKE_INSTALL_ERROR, PARAM_LOGIN, PARAM_SHORT,
PARAM_JOBS, PARAM_BRANCH, PARAM_GIT_COMMAND, PARAM_MODEL_PATH, PARAM_MODELS_DIRECTORY, PARAM_KEEP_OUTPUT,
PARAM_SHOW_TESTS, PARAM_TEST_NAME, PARAM_UPDATE, PARAM_OVERWRITE, BUILD_PATH, INSTALL_PATH,
BUILD_TYPE, SOURCES_PATH, XMIPP_SOURCES, XMIPP, LOG_FILE, CMAKE_ERROR, MODE_GET_SOURCES)
BUILD_TYPE, SOURCES_PATH, XMIPP_SOURCES, XMIPP, LOG_FILE, CMAKE_ERROR, MODE_GET_SOURCES, VERSION_FILE)
from installer.utils import runStreamingJob, runJob
from installer.parser import ModeHelpFormatter, GeneralHelpFormatter, ErrorHandlerArgumentParser, getParamNames
from installer.config import readConfig, writeConfig
from installer.cmake import getCMake, getCMakeVarsStr
from installer.main import getSources, exitXmipp, handleRetCode, getSectionMessage, getSuccessMessage, getVersionMessage
from installer.logger import logger, yellow, red, blue
from installer.api import sendApiPOST

####################### EXECUTION MODES #######################
def __getProjectRootDir() -> str:
Expand Down Expand Up @@ -294,12 +295,16 @@ def runSelectedMode(parser: ErrorHandlerArgumentParser, args: argparse.Namespace
else:
# If method was none of the above, exit with error
logger(red(f"Mode \"{args.mode}\" not recognized. {COMMON_USAGE_HELP_MESSAGE}"), forceConsoleOutput=True)
exitXmipp(retCode=1, sendAPI=False)
exitXmipp(retCode=1)

# Send API message
if sendAPI and os.path.exists(VERSION_FILE):
sendApiPOST()

MartinSalinas98 marked this conversation as resolved.
Show resolved Hide resolved
# Print success message for specific modes
if args.mode == MODE_ALL or args.mode == MODE_COMPILE_AND_INSTALL:
logger(getSuccessMessage(), forceConsoleOutput=True)
exitXmipp(sendAPI=sendAPI)
exitXmipp()

####################### MAIN EXECUTION THREAD #######################
if __name__ == "__main__":
Expand Down