1 import os
2 import time
3 import base64
4 import json
5 import requests
6 from collections import defaultdict
7 from sqlalchemy import and_
8 from datetime import datetime
9 from coprs import models
10 from coprs import db
11 from coprs import exceptions
12 from coprs.logic import builds_logic
13 from wtforms import ValidationError
14
15 import gi
16 gi.require_version('Modulemd', '1.0')
17 from gi.repository import Modulemd
21 @classmethod
22 - def get(cls, module_id):
27
28 @classmethod
35
36 @classmethod
40
41 @classmethod
44
45 @classmethod
48
49 @classmethod
51 mmd = Modulemd.ModuleStream()
52 mmd.import_from_string(yaml)
53 return mmd
54
55 @classmethod
60
61 @classmethod
63 if not all([mmd.get_name(), mmd.get_stream(), mmd.get_version()]):
64 raise ValidationError("Module should contain name, stream and version")
65
66 @classmethod
67 - def add(cls, user, copr, module):
77
78 @classmethod
80 mmd.set_name(mmd.get_name() or str(os.path.splitext(filename)[0]))
81 mmd.set_stream(mmd.get_stream() or "master")
82 mmd.set_version(mmd.get_version() or int(datetime.now().strftime("%Y%m%d%H%M%S")))
83
86 - def __init__(self, user, copr, yaml, filename=None):
95
100
101 @classmethod
103 """
104 Determines Which component should be built in which batch. Returns an ordered list of grouped components,
105 first group of components should be built as a first batch, second as second and so on.
106 Particular components groups are represented by dicts and can by built in a random order within the batch.
107 :return: list of lists
108 """
109 batches = defaultdict(dict)
110 for pkgname, rpm in rpms.items():
111 batches[rpm.get_buildorder()][pkgname] = rpm
112 return [batches[number] for number in sorted(batches.keys())]
113
126
128 if rpm.get_repository():
129 return rpm.get_repository()
130 return self.default_distgit.format(pkgname=pkgname)
131
132 @property
134
135 return "https://src.fedoraproject.org/rpms/{pkgname}"
136
139 - def __init__(self, name="", stream="", version=0, summary="", config=None):
145
146 @property
148 return "{}-{}-{}".format(self.mmd.get_name(), self.mmd.get_stream(), self.mmd.get_version())
149
151 mmd_set = Modulemd.SimpleSet()
152 for package in packages:
153 mmd_set.add(str(package))
154 self.mmd.set_rpm_api(mmd_set)
155
157 mmd_set = Modulemd.SimpleSet()
158 for package in packages:
159 mmd_set.add(str(package))
160 self.mmd.set_rpm_filter(mmd_set)
161
169
180
187
188 - def add_component(self, package_name, build, chroot, rationale, buildorder=1):
195
197 return self.mmd.dumps()
198
202 self.filename = filename
203 self.yaml = yaml
204
205 @classmethod
210
211 @classmethod
213 return cls(ref.filename, ref.read())
214
215 @classmethod
217 if not url.endswith(".yaml"):
218 raise ValidationError("This URL doesn't point to a .yaml file")
219
220 request = requests.get(url)
221 if request.status_code != 200:
222 raise requests.RequestException("This URL seems to be wrong")
223 return cls(os.path.basename(url), request.text)
224