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
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 == 0:
55 return 0
56 elif x == 3:
57 return 1
58 elif x == 6:
59 return 2
60 elif x == 7:
61 return 3
62 elif x == 4:
63 return 4
64 elif x == 1:
65 return 5
66 elif x == 5:
67 return 6
68 return 1000
69
70 def sqlite_order_to_status(x):
71 if x == 0:
72 return 0
73 elif x == 1:
74 return 3
75 elif x == 2:
76 return 6
77 elif x == 3:
78 return 7
79 elif x == 4:
80 return 4
81 elif x == 5:
82 return 1
83 elif x == 6:
84 return 5
85 return 1000
86
87 conn = db.engine.connect()
88 conn.connection.create_function("status_to_order", 1, sqlite_status_to_order)
89 conn.connection.create_function("order_to_status", 1, sqlite_order_to_status)
90 statement = text(query_select)
91 statement.bindparams(bindparam("copr_id", Integer))
92 result = conn.execute(statement, {"copr_id": copr.id})
93 else:
94 statement = text(query_select)
95 statement.bindparams(bindparam("copr_id", Integer))
96 result = db.engine.execute(statement, {"copr_id": copr.id})
97
98 return result
99
100 @classmethod
101 - def get(cls, copr_id, package_name):
104
105 @classmethod
119
120 @classmethod
122 if ref_type == "tag":
123 matches = re.search(r'(.*)-[^-]+-[^-]+$', ref)
124 if matches and package.name != matches.group(1):
125 return False
126 else:
127 return True
128
129 committish = package.source_json_dict.get("committish") or ''
130 if committish and not ref.endswith(committish):
131 return False
132
133 path_match = True
134 for commit in commits:
135 for file_path in commit['added'] + commit['removed'] + commit['modified']:
136 path_match = False
137 if cls.path_belong_to_package(package, file_path):
138 path_match = True
139 break
140 if not path_match:
141 return False
142
143 return True
144
145 @classmethod
147 data = package.source_json_dict
148 norm_file_path = file_path.strip('./')
149 package_subdir = data.get('subdirectory') or ''
150 return norm_file_path.startswith(package_subdir.strip('./'))
151
152 @classmethod
173
174 @classmethod
175 - def exists(cls, copr_id, package_name):
179
180
181 @classmethod
191
192
193 @classmethod
203
204
205 @classmethod
206 - def build_package(cls, user, copr, package, chroot_names=None, **build_options):
210
211
212 @classmethod
213 - def batch_build(cls, user, copr, packages, chroot_names=None, **build_options):
254