| |
@@ -3,7 +3,10 @@
|
| |
import string
|
| |
|
| |
from six import with_metaclass
|
| |
- from six.moves.urllib.parse import urljoin
|
| |
+ from six.moves.urllib.parse import urljoin, urlparse
|
| |
+ import pipes
|
| |
+ from textwrap import dedent
|
| |
+ import re
|
| |
|
| |
import flask
|
| |
from flask import url_for
|
| |
@@ -548,3 +551,62 @@
|
| |
rv = t.stream(context)
|
| |
rv.enable_buffering(2)
|
| |
return rv
|
| |
+
|
| |
+
|
| |
+ def generate_repo_name(repo_url):
|
| |
+ """ based on url, generate repo name """
|
| |
+ repo_url = re.sub("[^a-zA-Z0-9]", '_', repo_url)
|
| |
+ repo_url = re.sub("(__*)", '_', repo_url)
|
| |
+ repo_url = re.sub("(_*$)|^_*", '', repo_url)
|
| |
+ return repo_url
|
| |
+
|
| |
+
|
| |
+ def pre_process_repo_url(chroot, repo_url):
|
| |
+ """
|
| |
+ Expands variables and sanitize repo url to be used for mock config
|
| |
+ """
|
| |
+ parsed_url = urlparse(repo_url)
|
| |
+ if parsed_url.scheme == "copr":
|
| |
+ user = parsed_url.netloc
|
| |
+ prj = parsed_url.path.split("/")[1]
|
| |
+ repo_url = "/".join([
|
| |
+ flask.current_app.config["BACKEND_BASE_URL"],
|
| |
+ "results", user, prj, chroot
|
| |
+ ]) + "/"
|
| |
+
|
| |
+ repo_url = repo_url.replace("$chroot", chroot)
|
| |
+ repo_url = repo_url.replace("$distname", chroot.split("-")[0])
|
| |
+
|
| |
+ return pipes.quote(repo_url)
|
| |
+
|
| |
+
|
| |
+ def generate_build_config(copr, chroot_id):
|
| |
+ """ Return dict with proper build config contents """
|
| |
+ chroot = None
|
| |
+ for i in copr.copr_chroots:
|
| |
+ if i.mock_chroot.name == chroot_id:
|
| |
+ chroot = i
|
| |
+ if not chroot:
|
| |
+ return ""
|
| |
+
|
| |
+ packages = "" if not chroot.buildroot_pkgs else chroot.buildroot_pkgs
|
| |
+
|
| |
+ repos = [{
|
| |
+ "id": "copr_base",
|
| |
+ "url": copr.repo_url + "/{}/".format(chroot_id),
|
| |
+ "name": "Copr repository",
|
| |
+ }]
|
| |
+ for repo in copr.repos_list:
|
| |
+ repo_view = {
|
| |
+ "id": generate_repo_name(repo),
|
| |
+ "url": pre_process_repo_url(chroot_id, repo),
|
| |
+ "name": "Additional repo " + generate_repo_name(repo),
|
| |
+ }
|
| |
+ repos.append(repo_view)
|
| |
+
|
| |
+ return {
|
| |
+ 'project_id': copr.repo_id,
|
| |
+ 'additional_packages': packages.split(),
|
| |
+ 'repos': repos,
|
| |
+ 'chroot': chroot_id,
|
| |
+ }
|
| |
This is follow up for:
https://github.com/fedora-copr/copr/pull/22