Skip to content

Commit

Permalink
Reduce sbomnix DEBUG log verbosity
Browse files Browse the repository at this point in the history
Signed-off-by: Henri Rosten <[email protected]>
  • Loading branch information
henrirosten committed Dec 22, 2023
1 parent 7c34c17 commit ec4c4de
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
5 changes: 2 additions & 3 deletions src/sbomnix/derivation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@

def load(path):
"""Load derivation from path"""
LOG.debug("")
with open(path, encoding="utf-8") as f:
d_obj = eval(f.read(), {"__builtins__": {}, "Derive": Derive}, {})
d_obj.store_path = path
LOG.debug("load derivation: %s", d_obj)
LOG.log(LOG_SPAM, "load derivation: %s", d_obj)
LOG.log(LOG_SPAM, "deivation attrs: %s", d_obj.to_dict())
return d_obj

Expand Down Expand Up @@ -96,7 +95,7 @@ def __repr__(self):
def add_output_path(self, path):
"""Add an output path to derivation"""
if path not in self.outputs and path != self.store_path:
LOG.debug("adding outpath to %s:%s", self, path)
LOG.log(LOG_SPAM, "adding outpath to %s:%s", self, path)
bisect.insort(self.outputs, path)

def to_dict(self):
Expand Down
29 changes: 15 additions & 14 deletions src/sbomnix/nix.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ def _get_cached(self, path):
return self.derivations[path] if path in self.derivations else None

def _update(self, drv_path, nixpath=None):
LOG.debug("drv_path=%s, nixpath=%s", drv_path, nixpath)
LOG.log(LOG_SPAM, "drv_path=%s, nixpath=%s", drv_path, nixpath)
if not drv_path.endswith(".drv"):
LOG.debug("Not a derivation, skipping: '%s'", drv_path)
LOG.log(LOG_SPAM, "Not a derivation, skipping: '%s'", drv_path)
self._add_cached(drv_path, drv=None)
return
if nixpath and self._is_cached(nixpath):
LOG.debug("Skipping redundant nixpath '%s'", nixpath)
LOG.log(LOG_SPAM, "Skipping redundant nixpath '%s'", nixpath)
return
if not nixpath and self._is_cached(drv_path):
LOG.debug("Skipping redundant drvpath '%s'", drv_path)
LOG.log(LOG_SPAM, "Skipping redundant drvpath '%s'", drv_path)
return
drv_obj = self._get_cached(drv_path)
if not drv_obj:
Expand All @@ -63,9 +63,9 @@ def _update(self, drv_path, nixpath=None):

def add_path(self, nixpath):
"""Add the derivation referenced by a store path (nixpath)"""
LOG.debug(nixpath)
LOG.log(LOG_SPAM, nixpath)
if self._is_cached(nixpath):
LOG.debug("Skipping redundant path '%s'", nixpath)
LOG.log(LOG_SPAM, "Skipping redundant path '%s'", nixpath)
return
if not os.path.exists(nixpath):
raise RuntimeError(
Expand All @@ -74,7 +74,7 @@ def add_path(self, nixpath):
)
drv_path = find_deriver(nixpath)
if not drv_path:
LOG.debug("No deriver found for: '%s", nixpath)
LOG.log(LOG_SPAM, "No deriver found for: '%s", nixpath)
self._add_cached(nixpath, drv=None)
return
self._update(drv_path, nixpath)
Expand All @@ -85,7 +85,6 @@ def add_path(self, nixpath):

def to_dataframe(self):
"""Return store derivations as pandas dataframe"""
LOG.debug("")
drv_dicts = [drv.to_dict() for drv in self.derivations.values() if drv]
return pd.DataFrame.from_records(drv_dicts)

Expand All @@ -95,25 +94,27 @@ def to_dataframe(self):

def find_deriver(path):
"""Return drv path for the given nix store artifact path"""
LOG.debug(path)
LOG.log(LOG_SPAM, path)
if path.endswith(".drv"):
return path
# Deriver from QueryValidDerivers
ret = exec_cmd(["nix", "derivation", "show", path], raise_on_error=False)
ret = exec_cmd(
["nix", "derivation", "show", path], raise_on_error=False, loglevel=LOG_SPAM
)
if not ret:
LOG.debug("Deriver not found for '%s'", path)
LOG.log(LOG_SPAM, "Deriver not found for '%s'", path)
return None
qvd_json_keys = list(json.loads(ret.stdout).keys())
if not qvd_json_keys or len(qvd_json_keys) < 1:
LOG.debug("Not qvd_deriver for '%s'", path)
LOG.log(LOG_SPAM, "Not qvd_deriver for '%s'", path)
return None
qvd_deriver = qvd_json_keys[0]
LOG.debug("qvd_deriver: %s", qvd_deriver)
LOG.log(LOG_SPAM, "qvd_deriver: %s", qvd_deriver)
if qvd_deriver and os.path.exists(qvd_deriver):
return qvd_deriver
# Deriver from QueryPathInfo
qpi_deriver = exec_cmd(["nix-store", "-qd", path]).stdout.strip()
LOG.debug("qpi_deriver: %s", qpi_deriver)
LOG.log(LOG_SPAM, "qpi_deriver: %s", qpi_deriver)
if qpi_deriver and qpi_deriver != "unknown-deriver" and os.path.exists(qpi_deriver):
return qpi_deriver

Expand Down
4 changes: 2 additions & 2 deletions src/sbomnix/sbomdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from nixgraph.graph import NixDependencies
from sbomnix.nix import Store, find_deriver
from sbomnix.meta import Meta
from common.utils import LOG, df_to_csv_file, get_py_pkg_version
from common.utils import LOG, LOG_SPAM, df_to_csv_file, get_py_pkg_version

###############################################################################

Expand Down Expand Up @@ -359,7 +359,7 @@ def _cdx_component_add_licenses(component, drv):
licenses = _drv_to_cdx_licenses_entry(drv, "meta_license_short", "name")
# Give up if package does not have license information associated
if not licenses:
LOG.debug("No license info found for '%s'", drv.name)
LOG.log(LOG_SPAM, "No license info found for '%s'", drv.name)
return
# Otherwise, add the licenses entry
component["licenses"] = licenses
Expand Down

0 comments on commit ec4c4de

Please sign in to comment.