Skip to content

Commit

Permalink
check for missing installations
Browse files Browse the repository at this point in the history
  • Loading branch information
jkerpe committed Jun 28, 2024
1 parent 6b87014 commit c2a8978
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
37 changes: 24 additions & 13 deletions src/pyMetricCli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,13 @@ def _process_jira(adapter: AdapterInterface) -> Ret:
adapter.jira_config["filter"])

jira_instance = Jira(adapter.jira_config)
jira_results = jira_instance.search()

if adapter.handle_jira(jira_results) is False:
ret_status = Ret.ERROR_ADAPTER_HANDLER_JIRA
if jira_instance.is_installed is False:
LOG.error("pyJiraCli is not installed!")
ret_status = Ret.ERROR_NOT_INSTALLED_JIRA
else:
jira_results = jira_instance.search()
if adapter.handle_jira(jira_results) is False:
ret_status = Ret.ERROR_ADAPTER_HANDLER_JIRA

return ret_status

Expand All @@ -217,9 +220,13 @@ def _process_polarion(adapter: AdapterInterface) -> Ret:
adapter.polarion_config["query"])

polarion_instance = Polarion(adapter.polarion_config)
polarion_results = polarion_instance.search()
if adapter.handle_polarion(polarion_results) is False:
ret_status = Ret.ERROR_ADAPTER_HANDLER_POLARION
if polarion_instance.is_installed is False:
LOG.error("pyPolarionCli is not installed!")
ret_status = Ret.ERROR_NOT_INSTALLED_POLARION
else:
polarion_results = polarion_instance.search()
if adapter.handle_polarion(polarion_results) is False:
ret_status = Ret.ERROR_ADAPTER_HANDLER_POLARION

return ret_status

Expand Down Expand Up @@ -258,13 +265,17 @@ def _process_superset(adapter: AdapterInterface) -> Ret:

# Send the temporary file to the metric server using Superset.
superset_instance = Superset(adapter.superset_config)
ret = superset_instance.upload(_TEMP_FILE_PATH)

if 0 != ret:
ret_status = Ret.ERROR_SUPERSET_UPLOAD
LOG.error("Error while uploading to Superset!")
if superset_instance.is_installed is False:
LOG.error("pySupersetCli is not installed!")
ret_status = Ret.ERROR_NOT_INSTALLED_SUPERSET
else:
LOG.info("Successfully uploaded to Superset!")
ret = superset_instance.upload(_TEMP_FILE_PATH)

if 0 != ret:
ret_status = Ret.ERROR_SUPERSET_UPLOAD
LOG.error("Error while uploading to Superset!")
else:
LOG.info("Successfully uploaded to Superset!")

return ret_status

Expand Down
5 changes: 3 additions & 2 deletions src/pyMetricCli/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@

class Jira: # pylint: disable=too-few-public-methods
"""
Wrapper for the pyPolarionCli Tool.
Wrapper for the pyJiraCli Tool.
"""

def __init__(self, jira_config: dict) -> None:
self.config = jira_config
self.is_installed = self.__check_if_is_installed()

def __run_pyjiracli(self, arguments) -> subprocess.CompletedProcess:
"""
Expand All @@ -69,6 +70,7 @@ def __run_pyjiracli(self, arguments) -> subprocess.CompletedProcess:
subprocess.CompletedProcess[bytes]: The result of the command.
Includes return code, stdout and stderr.
"""
# pylint: disable=duplicate-code
args = ["pyJiraCli"] # The executable to run.
args.extend(arguments) # Add the arguments to the command.
return subprocess.run(args,
Expand Down Expand Up @@ -100,7 +102,6 @@ def search(self) -> dict:
dict: Search results.
"""
output = {}
self.__check_if_is_installed()
command_list: list = ["--server", self.config["server"],
"--token", self.config["token"],
"search",
Expand Down
4 changes: 2 additions & 2 deletions src/pyMetricCli/polarion.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Polarion: # pylint: disable=too-few-public-methods

def __init__(self, polarion_config: dict) -> None:
self.config = polarion_config
print(self.config)
self.is_installed = self.__check_if_is_installed()

def __run_pypolarioncli(self, arguments) -> subprocess.CompletedProcess:
"""
Expand Down Expand Up @@ -86,6 +86,7 @@ def __check_if_is_installed(self) -> bool:
Returns:
bool: True if pyPolarionCli is installed, False otherwise.
"""
# pylint: disable=duplicate-code
is_installed = True
try:
ret = self.__run_pypolarioncli(["--help"])
Expand All @@ -103,7 +104,6 @@ def search(self) -> dict:
dict: Search results.
"""
output = {}
self.__check_if_is_installed()

output_file_name = os.path.join(self.config['output'],
f"{self.config['project']}_search_results.json")
Expand Down
3 changes: 3 additions & 0 deletions src/pyMetricCli/ret.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class Ret(IntEnum):
ERROR_ADAPTER_HANDLER_JIRA = 4
ERROR_ADAPTER_HANDLER_POLARION = 5
ERROR_SUPERSET_UPLOAD = 6
ERROR_NOT_INSTALLED_JIRA = 7
ERROR_NOT_INSTALLED_POLARION = 8
ERROR_NOT_INSTALLED_SUPERSET = 9

################################################################################
# Functions
Expand Down
3 changes: 2 additions & 1 deletion src/pyMetricCli/superset.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Superset: # pylint: disable=too-few-public-methods

def __init__(self, superset_config: dict) -> None:
self.config = superset_config
self.is_installed = self.__check_if_is_installed()

def __run_pysupersetcli(self, arguments) -> subprocess.CompletedProcess:
"""
Expand All @@ -68,6 +69,7 @@ def __run_pysupersetcli(self, arguments) -> subprocess.CompletedProcess:
subprocess.CompletedProcess[bytes]: The result of the command.
Includes return code, stdout and stderr.
"""
# pylint: disable=duplicate-code
args = ["pySupersetCli"] # The executable to run.
args.extend(arguments) # Add the arguments to the command.
return subprocess.run(args,
Expand Down Expand Up @@ -101,7 +103,6 @@ def upload(self, input_file) -> int:
Returns:
int: Return Code of the command.
"""
self.__check_if_is_installed()
command_list: list = ["--verbose",
"--server", self.config["server"],
"--user", self.config["user"],
Expand Down

0 comments on commit c2a8978

Please sign in to comment.