1 import os
2 import time
3 import base64
4 import json
5 import requests
6 import modulemd
7 from collections import defaultdict
8 from sqlalchemy import and_
9 from datetime import datetime
10 from coprs import models
11 from coprs import db
12 from coprs import exceptions
13 from coprs.logic import builds_logic
14 from wtforms import ValidationError
18 @classmethod
19 - def get(cls, module_id):
24
25 @classmethod
32
33 @classmethod
37
38 @classmethod
41
42 @classmethod
45
46 @classmethod
48 mmd = modulemd.ModuleMetadata()
49 mmd.loads(yaml)
50 return mmd
51
52 @classmethod
57
58 @classmethod
60 if not all([mmd.name, mmd.stream, mmd.version]):
61 raise ValidationError("Module should contain name, stream and version")
62
63 @classmethod
64 - def add(cls, user, copr, module):
74
75 @classmethod
80
83 - def __init__(self, user, copr, yaml, filename=None):
92
97
98 @classmethod
100 """
101 Determines Which component should be built in which batch. Returns an ordered list of grouped components,
102 first group of components should be built as a first batch, second as second and so on.
103 Particular components groups are represented by dicts and can by built in a random order within the batch.
104 :return: list of lists
105 """
106 batches = defaultdict(dict)
107 for pkgname, rpm in rpms.items():
108 batches[rpm.buildorder][pkgname] = rpm
109 return [batches[number] for number in sorted(batches.keys())]
110
123
125 return rpm.repository if rpm.repository else self.default_distgit.format(pkgname=pkgname)
126
127 @property
129
130 return "https://src.fedoraproject.org/rpms/{pkgname}"
131
134 - def __init__(self, name="", stream="", version=0, summary="", config=None):
141
142 @property
145
149
153
160
171
178
179 - def add_component(self, package_name, build, chroot, rationale, buildorder=1):
186
189
192
194 return self.mmd.dumps()
195
196 - def dump(self, handle):
197 return self.mmd.dump(handle)
198
201 - def __init__(self, mbs_url, user_name=None):
204
205 - def post(self, json=None, data=None, files=None):
206 request = requests.post(self.url, verify=False,
207 json=json, data=data, files=files)
208 return MBSResponse(request)
209
215
219 self.response = response
220
221 @property
223 return self.response.status_code != 201
224
225 @property
227 if self.response.status_code in [500, 403, 404]:
228 return "Error from MBS: {} - {}".format(self.response.status_code, self.response.reason)
229 resp = json.loads(self.response.content)
230 if self.response.status_code != 201:
231 return "Error from MBS: {}".format(resp["message"])
232 return "Created module {}-{}-{}".format(resp["name"], resp["stream"], resp["version"])
233
237 self.filename = filename
238 self.yaml = yaml
239
240 @classmethod
245
246 @classmethod
248 return cls(ref.filename, ref.read())
249
250 @classmethod
252 if not url.endswith(".yaml"):
253 raise ValidationError("This URL doesn't point to a .yaml file")
254
255 request = requests.get(url)
256 if request.status_code != 200:
257 raise requests.RequestException("This URL seems to be wrong")
258 return cls(os.path.basename(url), request.text)
259