]> git.ipfire.org Git - pbs.git/commitdiff
repos: Make configuration downloadable
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 24 Jun 2022 15:18:12 +0000 (15:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 24 Jun 2022 15:18:12 +0000 (15:18 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/jobs.py
src/buildservice/repository.py
src/templates/repos/show.html
src/web/__init__.py
src/web/handlers.py
src/web/repos.py

index 63235e6399dc773f03178ea6471616e891a0f1d7..a070406dd73c939562d64b10f82b2465ae4dedf0 100644 (file)
@@ -540,7 +540,7 @@ class Job(base.DataObject):
 
                # Then add all repositories for this build.
                for repo in self.get_build_repos():
-                       conf = repo.get_conf(local=local)
+                       conf = repo.get_config(local=local)
                        confs.append(conf)
 
                return "\n\n".join(confs)
index 8c30a2e644b9974b0c07ab7893e4fb138356b75b..67838bb34d9e316796e2b48bdd7aa26aebcce3d5 100644 (file)
@@ -196,9 +196,9 @@ class Repository(base.DataObject):
                        "mirrorlist?arch=%{arch}"
                ))
 
-       def get_conf(self, local=False):
+       def get_config(self, local=False):
                lines = [
-                       "[repo:%s]" % self.identifier,
+                       "[repo:%s]" % self.slug,
                        "description = %s - %s" % (self.distro.name, self.summary),
                        "enabled = 1",
                        "baseurl = %s/%%{arch}" % (self.path if local else self.url),
@@ -445,16 +445,16 @@ class RepositoryAux(base.DataObject):
                return self.data.url
 
        @property
-       def identifier(self):
+       def slug(self):
                return self.name.lower()
 
        @property
        def distro(self):
                return self.pakfire.distros.get_by_id(self.data.distro_id)
 
-       def get_conf(self, local=False):
+       def get_config(self, local=False):
                lines = [
-                       "[repo:%s]" % self.identifier,
+                       "[repo:%s]" % self.slug,
                        "description = %s - %s" % (self.distro.name, self.name),
                        "enabled = 1",
                        "baseurl = %s" % self.url,
index 9644997cd70e814cce334789097ee1fb1b6ef99f..1110742fff8c3a1889788dd723aa87f254683b7a 100644 (file)
                </div>
        {% end %}
 
+       <a class="secondary small expanded button" href="/distros/{{ distro.slug }}/repos/{{ repo.slug }}.repo">
+               {{ _("Download Configuration") }}
+       </a>
+
        <div class="callout">
                <h5>{{ _("Statistics") }}</h5>
 
index c1f7e9842950c0b493002b44144c1a3e2bd54a26..cef1554b7ab9ca091faa02c6776e53fe17835a88 100644 (file)
@@ -157,10 +157,9 @@ class Application(tornado.web.Application):
                        (r"/distros", distributions.IndexHandler),
                        (r"/distros/([A-Za-z0-9\-\.]+)", distributions.ShowHandler),
                        (r"/distros/([A-Za-z0-9\-\.]+)/repos/([A-Za-z0-9\-]+)", repos.ShowHandler),
+                       (r"/distros/([A-Za-z0-9\-\.]+)/repos/([A-Za-z0-9\-]+)\.repo", repos.ConfigHandler),
                        (r"/distros/([A-Za-z0-9\-\.]+)/repos/([A-Za-z0-9\-]+)/builds", repos.BuildsHandler),
 
-                       (r"/distro/([A-Za-z0-9\-\.]+)/repo/([A-Za-z0-9\-]+)\.repo",
-                               RepositoryConfHandler),
                        (r"/distro/([A-Za-z0-9\-\.]+)/repo/([A-Za-z0-9\-]+)/mirrorlist",
                                RepositoryMirrorlistHandler),
                        (r"/distro/([A-Za-z0-9\-\.]+)/repo/([A-Za-z0-9\-]+)/edit",
index 802dd8f67c0360cfff941b6c7f694e2241a809fb..caa17a1547ef60e46450534d70cfd4f11993181e 100644 (file)
@@ -49,26 +49,6 @@ class RepositoryEditHandler(base.BaseHandler):
                self.render("repository-edit.html", distro=distro, repo=repo)
 
 
-class RepositoryConfHandler(base.BaseHandler):
-       def get(self, distro, repo):
-               distro = self.backend.distros.get_by_slug(distro)
-               if not distro:
-                       raise tornado.web.HTTPError(404)
-
-               repo = distro.get_repo(repo)
-               if not repo:
-                       raise tornado.web.HTTPError(404)
-
-               # This is a plaintext file.
-               self.set_header("Content-Type", "text/plain")
-
-               # Write the header.
-               self.write("# Downloaded from the pakfire build service on %s.\n\n" \
-                       % datetime.datetime.utcnow())
-               self.write(repo.get_conf())
-               self.finish()
-
-
 class RepositoryMirrorlistHandler(base.BaseHandler):
        def get(self, distro, repo):
                distro = self.backend.distros.get_by_slug(distro)
index d3b9dfda2d9a8f51848007401d8522e952eeb5d5..0c3cfd48ea7badc4128972940dd4dd4335d1556b 100644 (file)
@@ -54,6 +54,28 @@ class BuildsHandler(base.BaseHandler):
                self.render("repos/builds.html", repo=repo, distro=repo.distro)
 
 
+class ConfigHandler(base.BaseHandler):
+       def get(self, distro_slug, repo_slug):
+               # Find the distribution
+               distro = self.backend.distros.get_by_slug(distro_slug)
+               if not distro:
+                       raise tornado.web.HTTPError(404, "Could not find distro: %s" % distro_slug)
+
+               # Find the repository
+               repo = distro.get_repo(repo_slug)
+               if not repo:
+                       raise tornado.web.HTTPError(404, "Could not find repo: %s" % repo_slug)
+
+               # This is plain text
+               self.set_header("Content-Type", "text/plain")
+
+               # Generate configuration
+               config = repo.get_config()
+
+               # Send it to the client
+               self.finish(config)
+
+
 class ListModule(ui_modules.UIModule):
        def render(self, repos):
                return self.render_string("repos/modules/list.html", repos=repos)