Written skeleton for output analysis (#26). Renamed some arguments of ECG.

This commit is contained in:
antux18 2024-07-25 18:03:14 +02:00
parent e118cf3da1
commit 3c648c1a09
2 changed files with 120 additions and 4 deletions

115
analysis/output_analysis.py Executable file
View File

@ -0,0 +1,115 @@
#!/bin/python3
"""
This script will analyze the outputs from ECG to generate tables that will
be later plotted.
"""
import argparse
import csv
import os
def softenv_analysis(input_table):
"""
Analyzes the given package lists table to determine the number of artifacts
usinga package manager, Git packages or misc packages.
Parameters
----------
input_table: str
Table to analyse.
Returns
-------
list
Output table of the analysis.
"""
return []
def artifact_analysis(input_table):
"""
Analyzes the given artifact hash table to determine the number of artifacts
that change through time.
Parameters
----------
input_table: str
Table to analyse.
Returns
-------
list
Output table of the analysis.
"""
return []
def buildstatus_analysis(input_table):
"""
Analyzes the given build status table.
Parameters
----------
input_table: str
Table to analyse.
Returns
-------
list
Output table of the analysis.
"""
return []
def main():
# Command line arguments parsing:
parser = argparse.ArgumentParser(
prog = "output_analysis",
description = "This script analyzes the outputs from ECG to create " \
"tables."
)
parser.add_argument('-v', '--verbose',
action = 'store_true',
help = "Shows more details on what is being done."
)
parser.add_argument(
"-t", "--analysis-type",
help = "Specify the type of analysis to run.",
choices = ["soft-env", "artifact", "build-status"],
required = True
)
parser.add_argument(
"input_dir",
help = "Path to the directory where the CSV files used as input for " \
"the analysis function are stored. They must be all outputs from ECG."
)
parser.add_argument(
"output_path",
help = "Path to the output CSV file that will be created by the " \
"analysis function."
)
args = parser.parse_args()
analysis_type = args.analysis_type
input_dir = args.input_dir
output_path = args.output_path
# Parsing the inputs from the directory:
input_table = []
os.chdir(input_dir)
for input_path in os.listdir():
input_file = open(input_path)
input_table += list(csv.reader(input_file))
print(input_table)
input_file.close()
# Analyzing the inputs:
output_file = open(output_path, "w+")
if analysis_type == "soft-env":
output_file.writelines(softenv_analysis(input_table))
elif analysis_type == "artifact":
output_file.writelines(artifact_analysis(input_table))
elif analysis_type == "build-status":
output_file.writelines(buildstatus_analysis(input_table))
output_file.close()
if __name__ == "__main__":
main()

9
ecg.py
View File

@ -292,6 +292,7 @@ def check_env(config, src_dir, image_name, pkglist_path):
pkglist_file.write(f"{pkg_row}\n")
# Python venvs:
logging.info("Checking Python venvs")
for venv in config["python_venvs"]:
pipcmd = pkgmgr_cmd["pip"][0]
pipcmd_args = pkgmgr_cmd["pip"][1]
@ -325,7 +326,7 @@ def main():
# Paths:
config_path = ""
pkglist_path = "" # Package list being generated
buildstatus_path = "" # Summary of the build process of the image
buildstatus_path = "" # Status of the build process of the image, when it fails
arthashlog_path = "" # Log of the hash of the downloaded artifact
cache_dir = "" # Artifact cache directory, when using one. 'None' value indicates no cache.
use_cache = False
@ -355,8 +356,8 @@ def main():
required = True
)
parser.add_argument(
"-b", "--build-summary",
help = "Path to the file where to write the build summary of the Docker image given in the configuration file.",
"-b", "--build-status",
help = "Path to the file where to write the build status of the Docker image given in the configuration file.",
required = True
)
parser.add_argument(
@ -380,7 +381,7 @@ def main():
log_path = "log.txt" # Output of the program
pkglist_path = args.pkg_list
log_path = args.log_path
buildstatus_path = args.build_summary
buildstatus_path = args.build_status
arthashlog_path = args.artifact_hash
cache_dir = args.cache_dir