Skip to content

Commit

Permalink
Use cached nixmeta
Browse files Browse the repository at this point in the history
Signed-off-by: Henri Rosten <[email protected]>
  • Loading branch information
henrirosten committed Dec 18, 2023
1 parent 408704a commit ec3e90c
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/sbomnix/meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# SPDX-FileCopyrightText: 2022-2023 Technology Innovation Institute (TII)
#
# SPDX-License-Identifier: Apache-2.0

# pylint: disable=too-few-public-methods

"""Cache nixpkgs meta information"""

from dfdiskcache import DataFrameDiskCache

from common.utils import (
LOG,
df_from_csv_file,
)

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

_NIXMETA_CSV_URL = "https://github.com/henrirosten/nixmeta/raw/main/data/nixmeta.csv"
_NIXMETA_CSV_URL_TTL = 60 * 60 * 24

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


class NixMeta:
"""Cache nixpkgs meta information"""

def __init__(self):
LOG.debug("")
self.cache = DataFrameDiskCache()
self.df_nixmeta = self.cache.get(_NIXMETA_CSV_URL)
if self.df_nixmeta is None:
LOG.debug("nixmeta cache miss, downloading: %s", _NIXMETA_CSV_URL)
self.df_nixmeta = df_from_csv_file(_NIXMETA_CSV_URL)
self.cache.set(_NIXMETA_CSV_URL, self.df_nixmeta, ttl=_NIXMETA_CSV_URL_TTL)
else:
LOG.debug("read nixmeta from cache")

def get_df(self):
"""Return nix meta information as pandas dataframe"""
return self.df_nixmeta


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

0 comments on commit ec3e90c

Please sign in to comment.