Finished the package changes analysis.
This commit is contained in:
parent
4b91a6cb5d
commit
56c3682124
@ -42,7 +42,47 @@ def sources_stats(input_table):
|
|||||||
pkgmgr[row[2]] += 1
|
pkgmgr[row[2]] += 1
|
||||||
return pkgmgr
|
return pkgmgr
|
||||||
|
|
||||||
# def pkg_changed(pkgname, )
|
def pkg_changed(table, artifact_name, pkgname, pkgsource):
|
||||||
|
"""
|
||||||
|
Analyzes the given package lists table to determine if the given package
|
||||||
|
changed for the given artifact.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
table: str
|
||||||
|
Table to analyse.
|
||||||
|
|
||||||
|
artifact_name: str
|
||||||
|
Name of the artifact for which we want to analyze package changes.
|
||||||
|
|
||||||
|
pkgname: str
|
||||||
|
The package we want to track changes.
|
||||||
|
|
||||||
|
pkgsource: str
|
||||||
|
Source of the package, in case there is multiple packages with the
|
||||||
|
same name but different sources.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
changed: bool
|
||||||
|
True if the version number of the package changed over time, False
|
||||||
|
otherwise.
|
||||||
|
"""
|
||||||
|
changed = False
|
||||||
|
i = 0
|
||||||
|
pkgver = ""
|
||||||
|
while i < len(table) and not changed:
|
||||||
|
row = table[i]
|
||||||
|
# Artifact name is in the 4th column, package name in the first,
|
||||||
|
# and package source in the 3rd:
|
||||||
|
if row[3] == artifact_name and row[0] == pkgname and row[2] == pkgsource:
|
||||||
|
# If the first version number has not been saved yet:
|
||||||
|
if pkgver == "":
|
||||||
|
pkgver = row[1] # Package version is in the 2nd column
|
||||||
|
elif row[1] != pkgver:
|
||||||
|
changed = True
|
||||||
|
i += 1
|
||||||
|
return changed
|
||||||
|
|
||||||
def pkgs_changes(input_table):
|
def pkgs_changes(input_table):
|
||||||
"""
|
"""
|
||||||
@ -59,15 +99,27 @@ def pkgs_changes(input_table):
|
|||||||
dict
|
dict
|
||||||
Output table of the analysis in the form of a dict with headers as keys.
|
Output table of the analysis in the form of a dict with headers as keys.
|
||||||
"""
|
"""
|
||||||
pkgmgr = {}
|
pkgchanges_dict = {}
|
||||||
|
# Key is the artifact name, and value is a list of tuples constituted
|
||||||
|
# of the package that has been checked and its source for this artifact:
|
||||||
|
# FIXME: Memory usage?
|
||||||
|
checked_artifacts = {}
|
||||||
i = 0
|
i = 0
|
||||||
for row in input_table:
|
for row in input_table:
|
||||||
# Third column is the package source:
|
artifact_name = row[3] # Artifact name is in the 4th column
|
||||||
if row[2] not in pkgmgr:
|
if artifact_name not in checked_artifacts.keys():
|
||||||
pkgmgr[row[2]] = 1
|
checked_artifacts[artifact_name] = []
|
||||||
else:
|
pkgname = row[0] # Package name is in the first column
|
||||||
pkgmgr[row[2]] += 1
|
pkgsource = row[2] # Package source is in the 3rd column
|
||||||
return pkgmgr
|
if (pkgname, pkgsource) not in checked_artifacts[artifact_name]:
|
||||||
|
if pkg_changed(input_table, artifact_name, pkgname, pkgsource):
|
||||||
|
# Third column is the package source:
|
||||||
|
if row[2] not in pkgchanges_dict:
|
||||||
|
pkgchanges_dict[row[2]] = 1
|
||||||
|
else:
|
||||||
|
pkgchanges_dict[row[2]] += 1
|
||||||
|
checked_artifacts[artifact_name].append((pkgname, pkgsource))
|
||||||
|
return pkgchanges_dict
|
||||||
|
|
||||||
def pkgs_per_container(input_table):
|
def pkgs_per_container(input_table):
|
||||||
"""
|
"""
|
||||||
|
6
ecg.py
6
ecg.py
@ -201,7 +201,6 @@ def buildresult_saver(result, buildstatus_path, config_path):
|
|||||||
-------
|
-------
|
||||||
None
|
None
|
||||||
"""
|
"""
|
||||||
file_exists = os.path.exists(buildstatus_path)
|
|
||||||
buildstatus_file = open(buildstatus_path, "a")
|
buildstatus_file = open(buildstatus_path, "a")
|
||||||
artifact_name = os.path.basename(config_path).split(".")[0]
|
artifact_name = os.path.basename(config_path).split(".")[0]
|
||||||
# # Writing header in case file didn't exist:
|
# # Writing header in case file didn't exist:
|
||||||
@ -244,7 +243,6 @@ def build_image(config, src_dir, image_name, docker_cache = False):
|
|||||||
build_command = f"docker build{cache_arg} -t {image_name} ."
|
build_command = f"docker build{cache_arg} -t {image_name} ."
|
||||||
build_process = subprocess.run(build_command.split(" "), cwd=path, capture_output=True)
|
build_process = subprocess.run(build_command.split(" "), cwd=path, capture_output=True)
|
||||||
build_output = f"stdout:\n{build_process.stdout.decode('utf-8')}\nstderr:\n{build_process.stderr.decode('utf-8')}"
|
build_output = f"stdout:\n{build_process.stdout.decode('utf-8')}\nstderr:\n{build_process.stderr.decode('utf-8')}"
|
||||||
# build_output = build_process.stderr.decode("utf-8")
|
|
||||||
logging.info(f"Output of '{build_command}':")
|
logging.info(f"Output of '{build_command}':")
|
||||||
logging.info(build_output)
|
logging.info(build_output)
|
||||||
return_code = build_process.returncode
|
return_code = build_process.returncode
|
||||||
@ -284,7 +282,7 @@ def check_env(config, src_dir, artifact_name, pkglist_path):
|
|||||||
# of the package manager, depending on the package managers.
|
# of the package manager, depending on the package managers.
|
||||||
# Each package manager is associated with a tuple, the first item being
|
# Each package manager is associated with a tuple, the first item being
|
||||||
# the package manager's command, the second being the arguments for the
|
# the package manager's command, the second being the arguments for the
|
||||||
# query (they must be separate for the "--entrypoint" argument of Docker
|
# query (they must be separated for the "--entrypoint" argument of Docker
|
||||||
# 'run', see below), and the third one being the command that will format
|
# 'run', see below), and the third one being the command that will format
|
||||||
# the output of the query command (this one can be an empty string in case
|
# the output of the query command (this one can be an empty string in case
|
||||||
# the formatting part is already done using the options of the first command).
|
# the formatting part is already done using the options of the first command).
|
||||||
@ -453,8 +451,6 @@ def main():
|
|||||||
try:
|
try:
|
||||||
config_file = open(config_path, "r")
|
config_file = open(config_path, "r")
|
||||||
config = json.loads(config_file.read())
|
config = json.loads(config_file.read())
|
||||||
# config = yaml.safe_load(config_file)
|
|
||||||
# print(config)
|
|
||||||
config_file.close()
|
config_file.close()
|
||||||
|
|
||||||
dl_dir = None
|
dl_dir = None
|
||||||
|
Loading…
Reference in New Issue
Block a user