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
131
132 @classmethod
134 if ref_type == "tag":
135 matches = re.search(r'(.*)-[^-]+-[^-]+$', ref)
136 if matches and package.name != matches.group(1):
137 return False
138 else:
139 return True
140
141 committish = package.source_json_dict.get("committish") or ''
142 if committish and not ref.endswith(committish):
143 return False
144
145 path_match = True
146 for commit in commits:
147 for file_path in commit['added'] + commit['removed'] + commit['modified']:
148 path_match = False
149 if cls.path_belong_to_package(package, file_path):
150 path_match = True
151 break
152 if not path_match:
153 return False
154
155 return True
156
157 @classmethod
159 data = package.source_json_dict
160 norm_file_path = file_path.strip('./')
161 package_subdir = data.get('subdirectory') or ''
162 return norm_file_path.startswith(package_subdir.strip('./'))
163
164 @classmethod
185
186 @classmethod
187 - def exists(cls, copr_id, package_name):
191
192
193 @classmethod
203
204
205 @classmethod
215
216
217 @classmethod
218 - def build_package(cls, user, copr, package, chroot_names=None, **build_options):
222
223
224 @classmethod
225 - def batch_build(cls, user, copr, packages, chroot_names=None, **build_options):
266