diff options
| author | dd <dd@wx.tnyzeq.icu> | 2024-10-13 17:31:54 +0200 |
|---|---|---|
| committer | dd <dd@wx.tnyzeq.icu> | 2024-10-13 17:31:54 +0200 |
| commit | 748a1caad9bddcdae0e268fdff1c902dd0292ca9 (patch) | |
| tree | 10ecb2bba23345692b5e4f3001e6bf8178d00e19 | |
| parent | 4bf5d3bc31e74cefd84aed6868ab0d1adf445f24 (diff) | |
| download | vyos-jenkins-748a1caad9bddcdae0e268fdff1c902dd0292ca9.tar.gz vyos-jenkins-748a1caad9bddcdae0e268fdff1c902dd0292ca9.zip | |
circinus refactoring - updated cache/storage class
| -rw-r--r-- | new/lib/debranding.py | 4 | ||||
| -rw-r--r-- | new/lib/github.py | 4 | ||||
| -rw-r--r-- | new/lib/objectstorage.py (renamed from new/lib/cache.py) | 2 | ||||
| -rwxr-xr-x | new/package_builder.py | 17 |
4 files changed, 14 insertions, 13 deletions
diff --git a/new/lib/debranding.py b/new/lib/debranding.py index 86d2f82..39e5d4b 100644 --- a/new/lib/debranding.py +++ b/new/lib/debranding.py @@ -7,7 +7,7 @@ import shutil import tomlkit -from lib.cache import Cache +from lib.objectstorage import ObjectStorage from lib.helpers import resources_dir, data_dir @@ -20,7 +20,7 @@ class Debranding: logged = False def __init__(self): - self.cache = Cache(os.path.join(data_dir, "debranding-cache.json"), dict, {}) + self.cache = ObjectStorage(os.path.join(data_dir, "debranding-cache.json"), dict, {}) def populate_cli_parser(self, parser: argparse.ArgumentParser): parser.add_argument("--keep-branding", action="store_true", help="Keep VyOS branding as opposite to debranding") diff --git a/new/lib/github.py b/new/lib/github.py index 42ea3d7..fd111d1 100644 --- a/new/lib/github.py +++ b/new/lib/github.py @@ -12,7 +12,7 @@ import yaml sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))) from lib.helpers import setup_logging -from lib.cache import Cache +from lib.objectstorage import ObjectStorage from lib.helpers import refuse_root, data_dir @@ -171,7 +171,7 @@ if __name__ == "__main__": github = GitHub() - cache = Cache(os.path.join(data_dir, "github-vyos-cache.json"), dict, {}) + cache = ObjectStorage(os.path.join(data_dir, "github-vyos-cache.json"), dict, {}) repositories = cache.callback("repos", callback=lambda: github.find_org_repositories("vyos")) pprint(github.analyze_repositories_workflow("vyos", repositories, "circinus")) diff --git a/new/lib/cache.py b/new/lib/objectstorage.py index da68791..834fb57 100644 --- a/new/lib/cache.py +++ b/new/lib/objectstorage.py @@ -3,7 +3,7 @@ from json import JSONDecodeError import os -class Cache: +class ObjectStorage: _data = None _loaded = False diff --git a/new/package_builder.py b/new/package_builder.py index 05e816f..6921ca6 100755 --- a/new/package_builder.py +++ b/new/package_builder.py @@ -7,7 +7,7 @@ from shlex import quote from time import time, monotonic from lib.apt import Apt -from lib.cache import Cache +from lib.objectstorage import ObjectStorage from lib.debranding import Debranding from lib.docker import Docker from lib.git import Git @@ -39,7 +39,8 @@ class PackageBuilder: self.debranding = debranding self.github = GitHub() - self.cache = Cache(os.path.join(data_dir, "builder-cache-%s.json" % self.branch), dict, {}) + self.build_data = ObjectStorage(os.path.join(data_dir, "builder-data-%s.json" % self.branch), dict, {}) + self.package_cache = ObjectStorage(os.path.join(data_dir, "package-metadata-cache-%s.json" % self.branch), dict, {}) self.scripting = Scripting() self.terminal_title = TerminalTitle("Package builder: ") @@ -97,7 +98,7 @@ class PackageBuilder: def build_package(self, package): repo_name = package["repo_name"] - my_state = self.cache.get(package["package_name"], default={}, data_type=dict) + my_state = self.build_data.get(package["package_name"], default={}, data_type=dict) if "hash" not in my_state: my_state["hash"] = None @@ -199,11 +200,11 @@ class PackageBuilder: if not self.skip_apt or new: self.apt.fill_apt_repository(dsc_files, binary_files) - self.cache.set(package["package_name"], my_state) + self.build_data.set(package["package_name"], my_state) def get_packages_metadata(self): - packages_timestamp = self.cache.get("packages_timestamp") - packages = self.cache.get("packages") + packages_timestamp = self.package_cache.get("packages_timestamp") + packages = self.package_cache.get("packages") if not packages_timestamp or not packages or packages_timestamp <= time() - 3600 * 24 or self.rescan_packages: logging.info("Fetching vyos repository list") @@ -212,8 +213,8 @@ class PackageBuilder: logging.info("Analyzing package metadata") packages = self.github.analyze_repositories_workflow("vyos", repositories, self.branch) - self.cache.set("packages_timestamp", time()) - self.cache.set("packages", packages) + self.package_cache.set("packages_timestamp", time()) + self.package_cache.set("packages", packages) else: date = datetime.fromtimestamp(float(packages_timestamp)).astimezone().strftime("%Y-%m-%d %H:%M:%S") |
