| Trees | Indices | Help |
|---|
|
|
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 coprs.logic.dist_git_logic import DistGitLogic
13 from wtforms import ValidationError
14
15 import gi
16 gi.require_version('Modulemd', '1.0')
17 from gi.repository import Modulemd
21 @classmethod
23 """
24 Return single module identified by `module_id`
25 """
26 return models.Module.query.filter(models.Module.id == module_id)
27
28 @classmethod
30 return models.Module.query.filter(
31 and_(models.Module.name == name,
32 models.Module.stream == stream,
33 models.Module.version == version,
34 models.Module.copr_id == copr.id))
35
36 @classmethod
40
41 @classmethod
44
45 @classmethod
48
49 @classmethod
54
55 @classmethod
57 yaml_b64 = base64.b64encode(mmd.dumps().encode("utf-8")).decode("utf-8")
58 return models.Module(name=mmd.get_name(), stream=mmd.get_stream(), version=mmd.get_version(),
59 summary=mmd.get_summary(), description=mmd.get_description(), yaml_b64=yaml_b64)
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
68 if not user.can_build_in(copr):
69 raise exceptions.InsufficientRightsException("You don't have permissions to build in this copr.")
70
71 module.copr_id = copr.id
72 module.copr = copr
73 module.created_on = time.time()
74
75 db.session.add(module)
76 return 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
87 self.user = user
88 self.copr = copr
89 self.yaml = yaml
90 self.filename = filename
91 self.distgit = DistGitLogic.get_with_default(distgit_name)
92
93 self.modulemd = ModulesLogic.yaml2modulemd(yaml)
94 ModulesLogic.set_defaults_for_optional_params(self.modulemd, filename=filename)
95 ModulesLogic.validate(self.modulemd)
96
98 module = ModulesLogic.add(self.user, self.copr, ModulesLogic.from_modulemd(self.modulemd))
99 if not self.platform_chroots:
100 raise ValidationError("Module platform is {} which doesn't match to any chroots enabled in {} project"
101 .format(self.platform, self.copr.full_name))
102 self.add_builds(self.modulemd.get_rpm_components(), module)
103 return module
104
105 @classmethod
107 """
108 Determines Which component should be built in which batch. Returns an ordered list of grouped components,
109 first group of components should be built as a first batch, second as second and so on.
110 Particular components groups are represented by dicts and can by built in a random order within the batch.
111 :return: list of lists
112 """
113 batches = defaultdict(dict)
114 for pkgname, rpm in rpms.items():
115 batches[rpm.get_buildorder()][pkgname] = rpm
116 return [batches[number] for number in sorted(batches.keys())]
117
118 @property
120 platform = self.modulemd.get_buildrequires().get("platform", [])
121 return platform if isinstance(platform, list) else [platform]
122
123 @property
125 """
126 Return a list of chroot names based on buildrequired platform and enabled chroots for the project.
127 Example: Copr chroots are ["fedora-22-x86-64", "fedora-23-x86_64"] and modulemd specifies "f23" as a platform,
128 then `platform_chroots` are ["fedora-23-x86_64"]
129 Alternatively, the result will be same for "-f22" platform
130 :return: list of strings
131 """
132
133 # Just to be sure, that all chroot abbreviations from platform are in expected format, e.g. f28 or -f30
134 for abbrev in self.platform:
135 if not (abbrev.startswith(("f", "-f")) and abbrev.lstrip("-f").isnumeric()):
136 raise ValidationError("Unexpected platform '{}', it should be e.g. f28 or -f30".format(abbrev))
137
138 chroot_archs = {}
139 for chroot in self.copr.active_chroots:
140 chroot_archs.setdefault(chroot.name_release, []).append(chroot.arch)
141
142 def abbrev2chroots(abbrev):
143 name_release = abbrev.replace("-", "").replace("f", "fedora-")
144 return ["{}-{}".format(name_release, arch) for arch in chroot_archs.get(name_release, [])]
145
146 exclude_chroots = set()
147 select_chroots = set()
148 for abbrev in self.platform:
149 abbrev_chroots = abbrev2chroots(abbrev)
150 if not abbrev_chroots:
151 raise ValidationError("Module platform stream {} doesn't match to any enabled chroots in the {} project"
152 .format(abbrev, self.copr.full_name))
153 (exclude_chroots if abbrev.startswith("-") else select_chroots).update(abbrev_chroots)
154
155 chroots = {chroot.name for chroot in self.copr.active_chroots}
156 chroots -= exclude_chroots
157 if select_chroots:
158 chroots &= select_chroots
159 return chroots
160
161
163 blocked_by_id = None
164 for group in self.get_build_batches(rpms):
165 batch = models.Batch()
166 batch.blocked_by_id = blocked_by_id
167 db.session.add(batch)
168 for pkgname, rpm in group.items():
169 clone_url = self.get_clone_url(pkgname, rpm)
170 build = builds_logic.BuildsLogic.create_new_from_scm(self.user, self.copr, scm_type="git",
171 clone_url=clone_url, committish=rpm.peek_ref(),
172 chroot_names=self.platform_chroots)
173 build.batch = batch
174 build.batch_id = batch.id
175 build.module_id = module.id
176 db.session.add(build)
177
178 # Every batch needs to by blocked by the previous one
179 blocked_by_id = batch.id
180
182 if rpm.peek_repository():
183 return rpm.peek_repository()
184
185 return self.distgit.package_clone_url(pkgname)
186
190 self.config = config
191 licenses = Modulemd.SimpleSet()
192 licenses.add("unknown")
193 self.mmd = Modulemd.ModuleStream(mdversion=1, name=name, stream=stream, version=version, summary=summary,
194 description="", content_licenses=licenses, module_licenses=licenses)
195
196 @property
199
201 mmd_set = Modulemd.SimpleSet()
202 for package in packages:
203 mmd_set.add(str(package))
204 self.mmd.set_rpm_api(mmd_set)
205
207 mmd_set = Modulemd.SimpleSet()
208 for package in packages:
209 mmd_set.add(str(package))
210 self.mmd.set_rpm_filter(mmd_set)
211
213 for i, values in profiles:
214 name, packages = values
215 profile = Modulemd.Profile(name=name)
216 for package in packages:
217 profile.add_rpm(str(package))
218 self.mmd.add_profile(profile)
219
221 build_ids = sorted(list(set([int(id) for p, id in zip(packages, builds)
222 if p in filter_packages])))
223 for package in filter_packages:
224 build_id = builds[packages.index(package)]
225 build = builds_logic.BuildsLogic.get_by_id(build_id).first()
226 build_chroot = self._build_chroot(build)
227 buildorder = build_ids.index(int(build.id))
228 rationale = "User selected the package as a part of the module"
229 self.add_component(package, build, build_chroot, rationale, buildorder)
230
232 chroot = None
233 for chroot in build.build_chroots:
234 if chroot.name == "custom-1-x86_64":
235 break
236 return chroot
237
239 ref = str(chroot.git_hash) if chroot else ""
240 distgit_url = self.config["DIST_GIT_URL"].replace("/cgit", "/git")
241 url = os.path.join(distgit_url, build.copr.full_name, "{}.git".format(build.package.name))
242 component = Modulemd.ComponentRpm(name=str(package_name), rationale=rationale,
243 repository=url, ref=ref, buildorder=1)
244 self.mmd.add_rpm_component(component)
245
247 return self.mmd.dumps()
248
254
255 @classmethod
260
261 @classmethod
263 return cls(ref.filename, ref.read().decode("utf-8"))
264
265 @classmethod
274
| Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 | http://epydoc.sourceforge.net |