-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
janitor: automatically refresh branches.json
For SNAPSHOTS the targets and architectures likely change over time. Automatically create the overview file to lower manual maintenance. Signed-off-by: Paul Spooren <[email protected]>
- Loading branch information
Showing
8 changed files
with
77 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
import json | ||
|
||
# from msilib.schema import Registry | ||
from os import getenv | ||
from pathlib import Path | ||
|
||
|
@@ -95,48 +92,13 @@ def store_path(path="index.html"): | |
filter(lambda b: b.get("enabled"), app.config["BRANCHES"].values()), | ||
) | ||
) | ||
latest = list( | ||
map( | ||
lambda b: b["versions"][0], | ||
filter( | ||
lambda b: b.get("enabled"), | ||
app.config["BRANCHES"].values(), | ||
), | ||
) | ||
) | ||
|
||
app.config["OVERVIEW"] = { | ||
"latest": latest, | ||
"branches": branches, | ||
"server": { | ||
"version": __version__, | ||
"contact": "[email protected]", | ||
"allow_defaults": app.config["ALLOW_DEFAULTS"], | ||
}, | ||
} | ||
|
||
# legacy | ||
(app.config["JSON_PATH"] / "branches.json").write_text( | ||
json.dumps(list(branches.values())) | ||
) | ||
|
||
# tdb | ||
(app.config["JSON_PATH"] / "latest.json").write_text(json.dumps({"latest": latest})) | ||
|
||
(app.config["JSON_PATH"] / "overview.json").write_text( | ||
json.dumps( | ||
app.config["OVERVIEW"], | ||
indent=2, | ||
) | ||
) | ||
|
||
@app.route("/") | ||
def overview(): | ||
return render_template( | ||
"overview.html", | ||
branches=branches, | ||
defaults=app.config["ALLOW_DEFAULTS"], | ||
latest=latest, | ||
version=__version__, | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
from rq.exceptions import NoSuchJobError | ||
from rq.registry import FinishedJobRegistry | ||
|
||
from asu import __version__ | ||
from asu.common import get_redis, is_modified | ||
|
||
bp = Blueprint("janitor", __name__) | ||
|
@@ -86,8 +87,6 @@ def get_packages_arch_repo(branch, arch, repo): | |
|
||
|
||
def update_branch(branch): | ||
r = get_redis() | ||
|
||
version_path = branch["path"].format(version=branch["versions"][0]) | ||
targets = list( | ||
filter( | ||
|
@@ -374,6 +373,64 @@ def update_target_profiles(branch: dict, version: str, target: str) -> str: | |
return metadata["arch_packages"] | ||
|
||
|
||
def update_meta_json(): | ||
latest = list( | ||
map( | ||
lambda b: b["versions"][0], | ||
filter( | ||
lambda b: b.get("enabled"), | ||
current_app.config["BRANCHES"].values(), | ||
), | ||
) | ||
) | ||
|
||
branches = dict( | ||
map( | ||
lambda b: ( | ||
b["name"], | ||
{ | ||
**b, | ||
"targets": dict( | ||
map( | ||
lambda a: (a[0].decode(), a[1].decode()), | ||
get_redis().hgetall(f"architecture:{b['name']}").items(), | ||
) | ||
), | ||
}, | ||
), | ||
filter( | ||
lambda b: b.get("enabled"), | ||
current_app.config["BRANCHES"].values(), | ||
), | ||
) | ||
) | ||
|
||
current_app.config["OVERVIEW"] = { | ||
"latest": latest, | ||
"branches": branches, | ||
"server": { | ||
"version": __version__, | ||
"contact": "[email protected]", | ||
"allow_defaults": current_app.config["ALLOW_DEFAULTS"], | ||
}, | ||
} | ||
|
||
(current_app.config["JSON_PATH"] / "overview.json").write_text( | ||
json.dumps( | ||
current_app.config["OVERVIEW"], | ||
indent=2, | ||
) | ||
) | ||
|
||
(current_app.config["JSON_PATH"] / "branches.json").write_text( | ||
json.dumps(list(branches.values())) | ||
) | ||
|
||
(current_app.config["JSON_PATH"] / "latest.json").write_text( | ||
json.dumps({"latest": latest}) | ||
) | ||
|
||
|
||
@bp.cli.command("update") | ||
@click.option("-i", "--interval", default=10, type=int) | ||
def update(interval): | ||
|
@@ -397,6 +454,8 @@ def update(interval): | |
current_app.logger.info(f"Update {branch['name']}") | ||
update_branch(branch) | ||
|
||
update_meta_json() | ||
|
||
if interval > 0: | ||
current_app.logger.info(f"Next reload in { interval } minutes") | ||
sleep(interval * 60) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters