| |
@@ -1,5 +1,6 @@
|
| |
# coding: utf-8
|
| |
|
| |
+ import re
|
| |
from jinja2 import Environment
|
| |
|
| |
template_string = """\
|
| |
@@ -10,7 +11,7 @@
|
| |
|
| |
include('/etc/mock/{{chroot}}.cfg')
|
| |
|
| |
- config_opts['root'] = '{{project_id}}_{{chroot}}'
|
| |
+ config_opts['root'] = '{{ fullname |project_id }}_{{chroot}}'
|
| |
config_opts['chroot_additional_packages'] = '
|
| |
{%- for pkg in additional_packages -%}
|
| |
{%- if loop.last -%}
|
| |
@@ -19,12 +20,12 @@
|
| |
{{ pkg }} {% endif -%}
|
| |
{%- endfor -%}'
|
| |
|
| |
- {% if repos %}
|
| |
+ {% if additional_repos %}
|
| |
config_opts['yum.conf'] += \"\"\"
|
| |
- {% for repo in repos %}
|
| |
- [{{ repo.id }}]
|
| |
- name="{{ repo.name }}"
|
| |
- baseurl={{ repo.url }}
|
| |
+ {% for repo in additional_repos %}
|
| |
+ [{{ repo |repo_name }}]
|
| |
+ name="Additional repo {{ repo |repo_name }}"
|
| |
+ baseurl={{ repo }}
|
| |
gpgcheck=0
|
| |
enabled=1
|
| |
skip_if_unavailable=1
|
| |
@@ -41,8 +42,21 @@
|
| |
self.data = data
|
| |
|
| |
def __str__(self):
|
| |
- template = Environment().from_string(template_string)
|
| |
+ env = Environment()
|
| |
+ env.filters["repo_name"] = generate_repo_name
|
| |
+ env.filters["project_id"] = project_id
|
| |
+ template = env.from_string(template_string)
|
| |
return template.render(self.data)
|
| |
|
| |
|
| |
+ 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 project_id(fullname):
|
| |
+ ownername, name = fullname.split("/")
|
| |
+ return "{}-{}".format(ownername.replace("@", "group_"), name)
|
| |
This PR is trying to fix #427.
The issue is in depth explained in 405#comment-65090.
Do you consider this a good enough solution?
Since the rest of the
copr-cli
code switched to using APIv3 client and this would be the only action using the APIv1, I would rather fix this straight away, than "temporarily" switching to the old client. It wouldn't be that straightforward and some additional code would be necessary to e.g. catch the exceptions.As I unfortunately didn't attend the meeting, I don't know the context of this, but I don't think that another API call is needed.
Yep, I like this the most and this PR implements it. The only exception is that it doesn't implement the
expand_repourls=1
but returns preprocessed URLs straight away. I think, that it should be just fine, but if the parameter is preferred, I can easily add it.