Verified Commit 7a1990b7 authored by Max Rees's avatar Max Rees

Overhaul and reorganize the configuration system

parent 4e18dbff
......@@ -44,10 +44,47 @@ def _ConfigParser(**kwargs):
parser.BOOLEAN_STATES = {"true": True, "false": False}
return parser
_DEFAULT_CONFIG = {
"@default": {
# distro (str)
# repos (maplist)
# index (str)
"ignore": "", # list
"startdirs": "", # map
"bz.api": "", # str
# bz.product (str)
# bz.component (str)
# bz.field (str)
"bz.status": "", # list
"gl.api": "", # str
# gl.branch (str)
# cgi.default_version (str)
# cgi.data (str)
"cgi.cache": "", # str
"web.pagination": "25", # int
"web.url.rev": "", # str
"web.url.tree": "", # str
"web.url.bug": "", # str
"web.url.mr": "", # str
"web.repology.link": "", # str
"web.repology.badge": "", # str
},
# [@builders] gl.token (str)
# [@builders] gl.api (str - override)
}
def config(version=None):
config = _ConfigParser()
files = sorted(SYSCONFDIR.glob("*.ini"))
config = _ConfigParser()
config.read_dict(_DEFAULT_CONFIG)
config.read(files)
if version:
return config[version]
return config
......@@ -82,7 +82,7 @@ def pull_indices(conf, version):
# Noisy
logging.disable(logging.INFO)
index = Index(
url=conf["url"].format(version=version, repo=repo, arch=arch),
url=conf["index"].format(version=version, repo=repo, arch=arch),
)
logging.disable(logging.NOTSET)
......@@ -235,24 +235,24 @@ def populate_deps(db, pkgs, pkgids, provs):
def populate_bugs(conf, db, pkgids, main_startdirs):
# TODO: match on version
if not conf.get("bz_api_url"):
if not conf.get("bz.api"):
return
logging.info("Building bug tables...")
field = conf["bz_field"]
field = conf["bz.field"]
query = urllib.parse.urlencode([
("product", conf["bz_product"]),
("component", conf["bz_component"]),
("product", conf["bz.product"]),
("component", conf["bz.component"]),
("include_fields", ",".join((
"id", "status", "summary", "keywords",
field, "last_change_time",
))),
("status", conf.getlist(
"bz_status", ["UNCONFIRMED", "CONFIRMED", "IN_PROGRESS"]
"bz.status", ["UNCONFIRMED", "CONFIRMED", "IN_PROGRESS"]
)),
], doseq=True)
request = urllib.request.Request(
url=f"{conf['bz_api_url']}/bug?{query}",
url=f"{conf['bz.api']}/bug?{query}",
method="GET",
headers={
"Accept": "application/json",
......@@ -309,22 +309,22 @@ def populate_bugs(conf, db, pkgids, main_startdirs):
db.commit()
def populate_merges(conf, db, pkgids, main_startdirs):
if not conf.get("gl_api_url"):
if not conf.get("gl.api"):
return
logging.info("Building merge request tables...")
query = urllib.parse.urlencode({
"state": "opened",
"target_branch": conf["gl_branch"],
"target_branch": conf["gl.branch"],
}, doseq=True)
url = f"{conf['gl_api_url']}/merge_requests?{query}"
url = f"{conf['gl.api']}/merge_requests?{query}"
with urllib.request.urlopen(url) as response:
gl_merges = json.load(response)
merges = []
mergelinks = []
for merge in gl_merges:
url = f"{conf['gl_api_url']}/merge_requests/{merge['iid']}/changes"
url = f"{conf['gl.api']}/merge_requests/{merge['iid']}/changes"
with urllib.request.urlopen(url) as response:
gl_changes = json.load(response)["changes"]
......
......@@ -46,7 +46,7 @@ def init_db(app, branch):
return None
def pkg_paginate(conf, query, db, sql):
query["limit"] = conf.getint("pagination")
query["limit"] = conf.getint("web.pagination")
try:
query["page"] = int(query.get("page", "1"))
except ValueError:
......@@ -85,40 +85,35 @@ def page_builders(app):
if apkvitrine.BUILDERS not in app.conf:
return app.notfound()
bconf = app.conf[apkvitrine.BUILDERS]
if not bconf.get("gl.token") or not bconf.get("gl.api"):
return app.notfound()
builders = gl_runner_info(
bconf["gl_api_token"],
bconf["gl_api_url"],
"runners",
)
token = bconf["gl.token"]
api = bconf["gl.api"]
builders = gl_runner_info(token, api, "runners")
builders = [i["id"] for i in builders]
for i, builder in enumerate(builders):
builders[i] = apkvitrine.models.Builder(gl_runner_info(
bconf["gl_api_token"],
bconf["gl_api_url"],
f"../../runners/{builder}",
token, api, f"../../runners/{builder}",
))
jobs = gl_runner_info(
bconf["gl_api_token"],
bconf["gl_api_url"],
token, api,
f"../../runners/{builder}/jobs?status=running&order_by=id&per_page=1",
)
if jobs:
builders[i].running_job = apkvitrine.models.Job(jobs[0])
jobs = gl_runner_info(
bconf["gl_api_token"],
bconf["gl_api_url"],
token, api,
f"../../runners/{builder}/jobs?status=success&order_by=id&per_page=1",
)
if jobs:
builders[i].success_job = apkvitrine.models.Job(jobs[0])
jobs = gl_runner_info(
bconf["gl_api_token"],
bconf["gl_api_url"],
token, api,
f"../../runners/{builder}/jobs?status=failed&order_by=id&per_page=1",
)
if jobs:
......@@ -282,7 +277,7 @@ def page_search(app):
return [page]
def page_home(app):
return app.redirect(app.conf[apkvitrine.DEFAULT]["default_version"])
return app.redirect(app.conf[apkvitrine.DEFAULT]["cgi.default_version"])
def page_notfound(app):
return app.notfound()
......@@ -324,13 +319,13 @@ class APKVitrineApp: # pylint: disable=too-many-instance-attributes
self.conf = apkvitrine.config()
if "cache_dir" in self.conf[apkvitrine.DEFAULT]:
self.cache = Path(self.conf[apkvitrine.DEFAULT]["cache_dir"])
if self.conf[apkvitrine.DEFAULT].get("cgi.cache"):
self.cache = Path(self.conf[apkvitrine.DEFAULT]["cgi.cache"])
else:
self.cache = None
self.jinja.globals["cache"] = bool(self.cache)
self.data = Path(self.conf[apkvitrine.DEFAULT]["data_dir"])
self.data = Path(self.conf[apkvitrine.DEFAULT]["cgi.data"])
self._response = self.env = None
self.base = self.path = self.query = None
......
......@@ -22,10 +22,10 @@
# block content
<h3 class="title is-3">Latest version availability by architecture</h3>
# if "repology_link" in conf and "repology_badge" in conf
# if conf.get("web.repology.link") and conf.get("web.repology.badge")
<p>
<a href="{{ conf["repology_link"] ~ repology_name }}">
<img src="{{ conf["repology_badge"] ~ repology_name }}" onerror="this.style.display='none'" alt="Repology version information">
<a href="{{ conf["web.repology.link"] ~ repology_name }}">
<img src="{{ conf["web.repology.badge"] ~ repology_name }}" onerror="this.style.display='none'" alt="Repology version information">
</a>
</p>
# endif
......@@ -82,11 +82,15 @@
# set revision = revision.replace("-dirty", "", 1)
# set tag = " <span class='tag is-danger'>dirty</span>"
# endif
# set url = conf["gl_rev_url"].format(revision=revision)
# if conf.get("web.url.rev")
# set url = conf["web.url.rev"].format(revision=revision)
<tr><th>Revision</th> <td><a href="{{ url }}">{{ revision ~ (tag|safe) }}</a></td></tr>
# endif
# set url = conf["gl_url"].format(startdir=pkg.startdir)
# endif
# if conf.get("web.url.tree")
# set url = conf["web.url.tree"].format(startdir=pkg.startdir)
<tr><th>Source files</th><td><a href="{{ url }}">View git repository</a></td></tr>
# endif
</table>
</div>
......@@ -161,7 +165,7 @@
# endif
</div>
# if bugs
# if bugs and conf.get("web.url.bug")
<h3 class="title is-3">Open issues</h3>
<table class="table" id="bugs">
<tr>
......@@ -170,7 +174,7 @@
<th>Tags</th>
</tr>
# for bug in bugs|sort(attribute="id")
# set url = conf["bz_url"].format(id=bug.id)
# set url = conf["web.url.bug"].format(id=bug.id)
<tr>
<td><a href="{{ url }}">{{ bug.id }}</a></td>
<td><a href="{{ url }}">{{ bug.summary }}</a></td>
......@@ -180,7 +184,7 @@
</table>
# endif
# if merges
# if merges and conf.get("web.url.mr")
<h3 class="title is-3">Open merge requests</h3>
<table class="table" id="merges">
<tr>
......@@ -189,7 +193,7 @@
<th>Tags</th>
</tr>
# for merge in merges|sort(attribute="id")
# set url = conf["gl_mr_url"].format(id=merge.id)
# set url = conf["web.url.mr"].format(id=merge.id)
<tr>
<td><a href="{{ url }}">{{ merge.id }}</a></td>
<td><a href="{{ url }}">{{ merge.summary }}</a></td>
......
; The settings in the @default section serve as global settings or
; fallback settings for every OS version.
[@default]
; =========================================================
; *****************
; * Main settings *
; *****************
;;;;;;;;;;;;;;;;;;;
;; Main settings ;;
;;;;;;;;;;;;;;;;;;;
; Required: OS distribution name
;
distro = Adélie
; Required: APKINDEX locations
; Substitutions: {version}, {repo}, {arch}
url = https://mirrormaster.adelielinux.org/adelie/{version}/{repo}/{arch}/APKINDEX.tar.gz
; Required: list of repositories and the architectures they support
;
repos = system aarch64 ppc ppc64 pmmx x86_64
user aarch64 ppc ppc64 pmmx x86_64
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Database builder settings ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Required: APKINDEX locations
; Substitutions: {version}, {repo}, {arch}
;
index = https://mirrormaster.adelielinux.org/adelie/{version}/{repo}/{arch}/APKINDEX.tar.gz
; Optional: packages to exclude when building a database
;
;ignore = console-fonts
; console-keymaps
; Optional: override the STARTDIR for each package name (one package
; name / STARTDIR pair per line)
;
;startdirs = easy-kernel-5.4.66-mc1 system/easy-kernel
; easy-kernel-5.4.5-mc0 system/easy-kernel
; Required: URL for revision links
; Substitutions: {revision}
gl_rev_url = https://code.foxkit.us/adelie/packages/-/commit/{revision}
; Optional: enables bug tracking - API endpoint for Bugzilla
;
;bz.api = https://bts.adelielinux.org/rest.cgi
; Required for bug tracking: Bugzilla product
;
;bz.product = Adélie Linux
; Required for bug tracking: Bugzilla component
;
;bz.component = Packaging
; Required for bug tracking: custom bug field for STARTDIR on which to
; match
;
;bz.field = cf_package
; Optional: filter by bug status
;
;bz.status = UNCONFIRMED
; CONFIRMED
; IN_PROGRESS
; Optional: enables merge request tracking - Gitlab API endpoint for the
; project
;gl.api = https://code.foxkit.us/api/v4/projects/45
; Required for merge request tracking: branch for this OS version on
; Gitlab
;gl.branch = master
;;;;;;;;;;;;;;;;;;
;; CGI settings ;;
;;;;;;;;;;;;;;;;;;
; Required: default OS version
; This is the OS version that the main page of the application (e.g.
; /pkg/) will redirect to (e.g. /pkg/current).
;
cgi.default_version = current
; Required: data directory
; This is the directory in which the web application looks for the SQL
; database files.
;
; This option should only be specified in the @default section.
data_dir = /var/db/apkvitrine
;
cgi.data = /var/db/apkvitrine
; Optional: enable static HTML caching
; Each page that the web application believes to be static (for the
......@@ -38,81 +100,72 @@ data_dir = /var/db/apkvitrine
; which the web application runs.
;
; This option should only be specified in the @default section.
;cache_dir = /var/tmp/apkvitrine
;
;cgi.cache = /var/tmp/apkvitrine
; *********************
; * Bugzilla settings *
; *********************
; Optional: enables bug tracking - API endpoint for Bugzilla
bz_api_url = https://bts.adelielinux.org/rest.cgi
; Required for bug tracking: Bugzilla bug URL
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Web application settings ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Optional: number of packages per page (default: 25)
;
;web.pagination = 25
; Optional: URL for revision links (default: not shown)
; Substitutions: {revision}
;
;web.url.rev = https://code.foxkit.us/adelie/packages/-/commit/{revision}
; Optional: URL for source directory for this OS version (default: not shown)
; Substitutions: {startdir}
;
;web.url.tree = https://code.foxkit.us/adelie/packages/-/tree/master/{startdir}
; Optional: URL for bug (default: not shown)
; Substitutions: {id}
bz_url = https://bts.adelielinux.org/show_bug.cgi?id={id}
; Required for bug tracking: Bugzilla product
bz_product = Adélie Linux
; Required for bug tracking: Bugzilla component
bz_component = Packaging
; Optional: filter by bug status
bz_status = UNCONFIRMED
CONFIRMED
IN_PROGRESS
; Required for bug tracking: custom bug field for startdir on which to
; match
bz_field = cf_package
;
;web.url.bug = https://bts.adelielinux.org/show_bug.cgi?id={id}
; *******************
; * Gitlab settings *
; *******************
; Optional: enables merge request tracking - Gitlab API endpoint for the
; project
gl_api_url = https://code.foxkit.us/api/v4/projects/45
; Required for merge request tracking: URL for merge request
; Optional: URL for merge request (default: not shown)
; Substitutions: {id}
gl_mr_url = https://code.foxkit.us/adelie/packages/-/merge_requests/{id}
;
;web.url.mr = https://code.foxkit.us/adelie/packages/-/merge_requests/{id}
; ****************
; * Web settings *
; ****************
; Required: number of packages per page
pagination = 25
; Required: default OS version
default_version = current
; Optional: add a Repology badge with a link (specify both; default: not
; shown)
;
;web.repology.link = https://repology.org/tools/project-by?repo=adelie_current&name_type=binname&target_page=project_history&name=
;web.repology.badge = https://repology.org/tools/project-by?repo=adelie_current&name_type=binname&target_page=badge_version_for_repo&name=
; Optional: enable builders page
; Include the following section name to enable the web application's
; builder monitoring page. This requires the specification of a Gitlab
; API token below.
;
;[@builders]
; Optional: override Gitlab API endpoint to query builder status
; ("runners" API endpoint)
;gl_api_url = https://code.foxkit.us/api/v4/projects/76
; Required for builders page: Gitlab API token (PRIVATE-TOKEN) that can
; view the above project's runners list
;gl_api_token = YOUR-TOKEN-HERE
;
;gl.token = YOUR-TOKEN-HERE
[current]
; =========================================================
; *******************
; * Gitlab settings *
; *******************
; Required for merge request tracking: branch for this OS version on
; Gitlab
gl_branch = master
; Required: URL for APKBUILD startdirs for this OS version
; Substitutions: {startdir}
gl_url = https://code.foxkit.us/adelie/packages/-/tree/master/{startdir}
; Required for the builders page: Gitlab API endpoint for the project
; with which the runners are associated
;
;gl.api = https://code.foxkit.us/api/v4/projects/76
; Optional: packages to exclude when building a database
ignore = console-fonts
console-keymaps
; Optional: add a Repology badge with a link (specify both)
repology_link = https://repology.org/tools/project-by?repo=adelie_current&name_type=binname&target_page=project_history&name=
repology_badge = https://repology.org/tools/project-by?repo=adelie_current&name_type=binname&target_page=badge_version_for_repo&name=
[1.0-beta4]
gl_branch = 1.0-BETA4
gl_url = https://code.foxkit.us/adelie/packages/-/tree/1.0-BETA4/{startdir}
;;;;;;;;;;;;;;;;;;;;;;;;;;
;; OS version overrides ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;
; Add a section for each OS version. Any options can be overridden
; within, or only specified for a particular version, and so on.
[current]
; FIXME this should not be needed
ignore =
bz_api_url =
gl_api_url =
[1.0-beta4]
;web.tree_url = https://code.foxkit.us/adelie/packages/-/tree/1.0-BETA4/{startdir}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment