1 import json
2 import time
3 import re
4
5 from sqlalchemy import or_
6 from sqlalchemy import and_, bindparam, Integer
7 from sqlalchemy.sql import false, true, text
8
9 from coprs import app
10 from coprs import db
11 from coprs import exceptions
12 from coprs import models
13 from coprs import helpers
14 from coprs import forms
15
16 from coprs.logic import coprs_logic
17 from coprs.logic import users_logic
18 from coprs.logic import builds_logic
19
20 from coprs.constants import DEFAULT_BUILD_TIMEOUT
21
22 log = app.logger
26
27 @classmethod
30
31 @classmethod
35
36 @classmethod
38 query_select = """
39 SELECT package.name, build.pkg_version, build.submitted_on, package.webhook_rebuild, order_to_status(subquery2.min_order_for_a_build) AS status, build.source_status
40 FROM package
41 LEFT OUTER JOIN (select MAX(build.id) as max_build_id_for_a_package, package_id
42 FROM build
43 WHERE build.copr_id = :copr_id
44 GROUP BY package_id) as subquery1 ON subquery1.package_id = package.id
45 LEFT OUTER JOIN build ON build.id = subquery1.max_build_id_for_a_package
46 LEFT OUTER JOIN (select build_id, min(status_to_order(status)) as min_order_for_a_build
47 FROM build_chroot
48 GROUP BY build_id) as subquery2 ON subquery2.build_id = subquery1.max_build_id_for_a_package
49 WHERE package.copr_id = :copr_id;
50 """
51
52 if db.engine.url.drivername == "sqlite":
53 def sqlite_status_to_order(x):
54 if x == 3:
55 return 1
56 elif x == 6:
57 return 2
58 elif x == 7:
59 return 3
60 elif x == 4:
61 return 4
62 elif x == 0:
63 return 5
64 elif x == 1:
65 return 6
66 elif x == 5:
67 return 7
68 elif x == 2:
69 return 8
70 elif x == 8:
71 return 9
72 elif x == 9:
73 return 10
74 return 1000
75
76 def sqlite_order_to_status(x):
77 if x == 1:
78 return 3
79 elif x == 2:
80 return 6
81 elif x == 3:
82 return 7
83 elif x == 4:
84 return 4
85 elif x == 5:
86 return 0
87 elif x == 6:
88 return 1
89 elif x == 7:
90 return 5
91 elif x == 8:
92 return 2
93 elif x == 9:
94 return 8
95 elif x == 10:
96 return 9
97 return 1000
98
99 conn = db.engine.connect()
100 conn.connection.create_function("status_to_order", 1, sqlite_status_to_order)
101 conn.connection.create_function("order_to_status", 1, sqlite_order_to_status)
102 statement = text(query_select)
103 statement.bindparams(bindparam("copr_id", Integer))
104 result = conn.execute(statement, {"copr_id": copr.id})
105 else:
106 statement = text(query_select)
107 statement.bindparams(bindparam("copr_id", Integer))
108 result = db.engine.execute(statement, {"copr_id": copr.id})
109
110 return result
111
112 @classmethod
113 - def get(cls, copr_id, package_name):
116
117 @classmethod
140
141 @classmethod
143 if ref_type == "tag":
144 matches = re.search(r'(.*)-[^-]+-[^-]+$', ref)
145 if matches and package.name != matches.group(1):
146 return False
147 else:
148 return True
149
150 committish = package.source_json_dict.get("committish") or ''
151 if committish and not ref.endswith(committish):
152 return False
153
154 path_match = True
155 for commit in commits:
156 for file_path in commit['added'] + commit['removed'] + commit['modified']:
157 path_match = False
158 if cls.path_belong_to_package(package, file_path):
159 path_match = True
160 break
161 if not path_match:
162 return False
163
164 return True
165
166 @classmethod
168 data = package.source_json_dict
169 norm_file_path = file_path.strip('./')
170 package_subdir = data.get('subdirectory') or ''
171 return norm_file_path.startswith(package_subdir.strip('./'))
172
173 @classmethod
194
195 @classmethod
196 - def exists(cls, copr_id, package_name):
200
201
202 @classmethod
212
213
214 @classmethod
224
225
226 @classmethod
227 - def build_package(cls, user, copr, package, chroot_names=None, **build_options):
231
232
233 @classmethod
234 - def batch_build(cls, user, copr, packages, chroot_names=None, **build_options):
275