1 import os
2 import time
3 import base64
4 import requests
5 from collections import defaultdict
6 from sqlalchemy import and_
7 from datetime import datetime
8 from coprs import models
9 from coprs import db
10 from coprs import exceptions
11 from coprs.logic import builds_logic
12 from wtforms import ValidationError
13
14 import gi
15 gi.require_version('Modulemd', '1.0')
16 from gi.repository import Modulemd
20 @classmethod
21 - def get(cls, module_id):
26
27 @classmethod
34
35 @classmethod
39
40 @classmethod
43
44 @classmethod
47
48 @classmethod
50 mmd = Modulemd.ModuleStream()
51 mmd.import_from_string(yaml)
52 return mmd
53
54 @classmethod
59
60 @classmethod
62 if not all([mmd.get_name(), mmd.get_stream(), mmd.get_version()]):
63 raise ValidationError("Module should contain name, stream and version")
64
65 @classmethod
66 - def add(cls, user, copr, module):
76
77 @classmethod
79 mmd.set_name(mmd.get_name() or str(os.path.splitext(filename)[0]))
80 mmd.set_stream(mmd.get_stream() or "master")
81 mmd.set_version(mmd.get_version() or int(datetime.now().strftime("%Y%m%d%H%M%S")))
82
85 - def __init__(self, user, copr, yaml, filename=None):
94
99
100 @classmethod
102 """
103 Determines Which component should be built in which batch. Returns an ordered list of grouped components,
104 first group of components should be built as a first batch, second as second and so on.
105 Particular components groups are represented by dicts and can by built in a random order within the batch.
106 :return: list of lists
107 """
108 batches = defaultdict(dict)
109 for pkgname, rpm in rpms.items():
110 batches[rpm.get_buildorder()][pkgname] = rpm
111 return [batches[number] for number in sorted(batches.keys())]
112
130
132 if rpm.get_repository():
133 return rpm.get_repository()
134 return self.default_distgit.format(pkgname=pkgname)
135
136 @property
138
139 return "https://src.fedoraproject.org/rpms/{pkgname}"
140
143 - def __init__(self, name="", stream="", version=0, summary="", config=None):
149
150 @property
152 return "{}-{}-{}".format(self.mmd.get_name(), self.mmd.get_stream(), self.mmd.get_version())
153
155 mmd_set = Modulemd.SimpleSet()
156 for package in packages:
157 mmd_set.add(str(package))
158 self.mmd.set_rpm_api(mmd_set)
159
161 mmd_set = Modulemd.SimpleSet()
162 for package in packages:
163 mmd_set.add(str(package))
164 self.mmd.set_rpm_filter(mmd_set)
165
173
184
191
192 - def add_component(self, package_name, build, chroot, rationale, buildorder=1):
199
201 return self.mmd.dumps()
202
206 self.filename = filename
207 self.yaml = yaml
208
209 @classmethod
214
215 @classmethod
217 return cls(ref.filename, ref.read().decode("utf-8"))
218
219 @classmethod
221 if not url.endswith(".yaml"):
222 raise ValidationError("This URL doesn't point to a .yaml file")
223
224 request = requests.get(url)
225 if request.status_code != 200:
226 raise requests.RequestException("This URL seems to be wrong")
227 return cls(os.path.basename(url), request.text)
228