@@ -65,7 +65,7 @@ def get_transitive_runtime_dependencies(cls, copr):
65
65
66
66
for dep in analyzed_copr .runtime_deps :
67
67
try :
68
- copr_dep = cls .get_copr_by_repo_safe (dep )
68
+ copr_dep = cls .get_copr_by_repo (dep )
69
69
except exceptions .ObjectNotFound :
70
70
non_existing .add (dep )
71
71
continue
@@ -170,120 +170,232 @@ def fork_copr(cls, copr, user, dstname, dstgroup=None):
170
170
return fcopr , created
171
171
172
172
@staticmethod
173
- def get_group_copr_safe (group_name , copr_name , ** kwargs ):
174
- group = ComplexLogic .get_group_by_name_safe (group_name )
173
+ def get_group_copr (group_name , copr_name , ** kwargs ):
174
+ """
175
+ Get group Copr by group and copr name.
176
+
177
+ Returns:
178
+ Copr model
179
+
180
+ Raises:
181
+ ObjectNotFound to API if nothing is found in database
182
+ """
183
+ group = ComplexLogic .get_group_by_name (group_name )
175
184
try :
176
185
return CoprsLogic .get_by_group_id (
177
186
group .id , copr_name , ** kwargs ).one ()
178
- except sqlalchemy .orm .exc .NoResultFound :
187
+ except sqlalchemy .orm .exc .NoResultFound as exc :
179
188
raise ObjectNotFound (
180
- message = "Project @{}/{} does not exist."
181
- .format (group_name , copr_name ))
189
+ message = "Project @{}/{} does not exist." .format (
190
+ group_name , copr_name
191
+ )
192
+ ) from exc
182
193
183
194
@staticmethod
184
- def get_copr_safe (user_name , copr_name , ** kwargs ):
195
+ def get_copr (user_name , copr_name , ** kwargs ):
185
196
""" Get one project.
186
197
187
- This always return personal project. For group projects see get_group_copr_safe ().
198
+ This always return personal project. For group projects see get_group_copr ().
188
199
"""
189
200
try :
190
201
return CoprsLogic .get (user_name , copr_name , ** kwargs ).filter (Copr .group_id .is_ (None )).one ()
191
- except sqlalchemy .orm .exc .NoResultFound :
202
+ except sqlalchemy .orm .exc .NoResultFound as exc :
192
203
raise ObjectNotFound (
193
- message = "Project {}/{} does not exist."
194
- .format (user_name , copr_name ))
204
+ message = "Project {}/{} does not exist." .format (
205
+ user_name , copr_name
206
+ )
207
+ ) from exc
195
208
196
209
@staticmethod
197
- def get_copr_by_owner_safe (owner_name , copr_name , ** kwargs ):
210
+ def get_copr_by_owner (owner_name , copr_name , ** kwargs ):
211
+ """
212
+ Get Copr by owner name and copr name.
213
+
214
+ Returns:
215
+ Copr model
216
+
217
+ Raises:
218
+ ObjectNotFound to API if nothing is found in database
219
+ """
198
220
if owner_name [0 ] == "@" :
199
- return ComplexLogic .get_group_copr_safe (owner_name [1 :], copr_name , ** kwargs )
200
- return ComplexLogic .get_copr_safe (owner_name , copr_name , ** kwargs )
221
+ return ComplexLogic .get_group_copr (owner_name [1 :], copr_name , ** kwargs )
222
+ return ComplexLogic .get_copr (owner_name , copr_name , ** kwargs )
201
223
202
224
@staticmethod
203
- def get_copr_by_repo_safe (repo_url ):
225
+ def get_copr_by_repo (repo_url ):
226
+ """
227
+ Safely get copr repo by repo url.
228
+
229
+ Args:
230
+ repo_url: str
231
+
232
+ Returns:
233
+ Copr repo or None in case of invalid url format or different url
234
+ scheme than copr.
235
+
236
+ Raises:
237
+ ObjectNotFound to the API if no such Copr (group) result was found
238
+ in database.
239
+ """
204
240
copr_repo = helpers .copr_repo_fullname (repo_url )
205
241
if not copr_repo :
206
242
return None
207
243
try :
208
244
owner , copr = copr_repo .split ("/" )
209
- except :
245
+ except ValueError :
210
246
# invalid format, e.g. multiple slashes in copr_repo
211
247
return None
212
- return ComplexLogic .get_copr_by_owner_safe (owner , copr )
248
+ return ComplexLogic .get_copr_by_owner (owner , copr )
213
249
214
250
@staticmethod
215
- def get_copr_dir_safe (ownername , copr_dirname , ** kwargs ):
251
+ def get_copr_dir (ownername , copr_dirname ):
252
+ """
253
+ Get CoprDir by owner name and dir name.
254
+
255
+ Returns:
256
+ CoprDir model
257
+
258
+ Raises:
259
+ ObjectNotFound to the API if no result was found in database.
260
+ """
216
261
try :
217
262
return CoprDirsLogic .get_by_ownername (ownername , copr_dirname ).one ()
218
- except sqlalchemy .orm .exc .NoResultFound :
219
- raise ObjectNotFound (message = "copr dir {}/{} does not exist."
220
- .format (ownername , copr_dirname ))
263
+ except sqlalchemy .orm .exc .NoResultFound as exc :
264
+ raise ObjectNotFound (
265
+ message = "copr dir {}/{} does not exist." .format (
266
+ ownername , copr_dirname
267
+ )
268
+ ) from exc
221
269
222
270
@staticmethod
223
- def get_copr_by_id_safe (copr_id ):
271
+ def get_copr_by_id (copr_id ):
272
+ """
273
+ Get Copr by its ID.
274
+
275
+ Returns:
276
+ Copr model
277
+
278
+ Raises:
279
+ ObjectNotFound to the API if no such project with ID exists.
280
+ """
224
281
try :
225
282
return CoprsLogic .get_by_id (copr_id ).one ()
226
- except sqlalchemy .orm .exc .NoResultFound :
283
+ except sqlalchemy .orm .exc .NoResultFound as exc :
227
284
raise ObjectNotFound (
228
- message = "Project with id {} does not exist."
229
- . format ( copr_id ))
285
+ message = "Project with id {} does not exist." . format ( copr_id )
286
+ ) from exc
230
287
231
288
@staticmethod
232
- def get_build_safe (build_id ):
289
+ def get_build (build_id ):
290
+ """
291
+ Get Build by its ID.
292
+
293
+ Returns:
294
+ Build model
295
+
296
+ Raises:
297
+ ObjectNotFound to the API if no such build with ID exists.
298
+ """
233
299
try :
234
300
return BuildsLogic .get_by_id (build_id ).one ()
235
- except (sqlalchemy .orm .exc .NoResultFound ,
236
- sqlalchemy .exc .DataError ):
301
+ except (sqlalchemy .orm .exc .NoResultFound , sqlalchemy .exc .DataError ) as exc :
237
302
raise ObjectNotFound (
238
- message = "Build {} does not exist." .format (build_id ))
303
+ message = "Build {} does not exist." .format (build_id )
304
+ ) from exc
239
305
240
306
@staticmethod
241
307
def get_build_chroot (build_id , chrootname ):
242
308
"""
243
- Return a `models.BuildChroot` instance based on build ID and name of the chroot.
244
- If there is no such chroot, `ObjectNotFound` execption is raised.
309
+ Get a BuildChroot instance based on build ID and name of the chroot.
310
+
311
+ Returns:
312
+ BuildChroot model
313
+
314
+ Raises:
315
+ If there is no such chroot, `ObjectNotFound` execption is raised.
245
316
"""
246
- build = ComplexLogic .get_build_safe (build_id )
317
+ build = ComplexLogic .get_build (build_id )
247
318
try :
248
319
return build .chroots_dict_by_name [chrootname ]
249
- except KeyError :
320
+ except KeyError as exc :
250
321
msg = "Build {} was not submitted to {} chroot." .format (build_id , chrootname )
251
322
if not MockChrootsLogic .get_from_name (chrootname ).one_or_none ():
252
323
msg = "Chroot {} does not exist" .format (chrootname )
253
- raise ObjectNotFound (message = msg )
324
+ raise ObjectNotFound (message = msg ) from exc
254
325
255
326
@staticmethod
256
- def get_package_by_id_safe (package_id ):
327
+ def get_package_by_id (package_id ):
328
+ """
329
+ Get Package instance based on its ID.
330
+
331
+ Returns:
332
+ Package model
333
+
334
+ Raises:
335
+ ObjectNotFound to the API if no such package with ID exists.
336
+ """
257
337
try :
258
338
return PackagesLogic .get_by_id (package_id ).one ()
259
- except sqlalchemy .orm .exc .NoResultFound :
339
+ except sqlalchemy .orm .exc .NoResultFound as exc :
260
340
raise ObjectNotFound (
261
- message = "Package {} does not exist." .format (package_id ))
341
+ message = "Package {} does not exist." .format (package_id )
342
+ ) from exc
262
343
263
344
@staticmethod
264
- def get_package_safe (copr , package_name ):
345
+ def get_package (copr , package_name ):
346
+ """
347
+ Get Package instance based on Copr instance and package name.
348
+
349
+ Returns:
350
+ Package model
351
+
352
+ Raises:
353
+ ObjectNotFound to the API if no such package with given name
354
+ exists.
355
+ """
265
356
try :
266
357
return PackagesLogic .get (copr .id , package_name ).one ()
267
- except sqlalchemy .orm .exc .NoResultFound :
358
+ except sqlalchemy .orm .exc .NoResultFound as exc :
268
359
raise ObjectNotFound (
269
- message = "Package {} in the copr {} does not exist."
270
- .format (package_name , copr ))
360
+ message = "Package {} in the copr {} does not exist." .format (
361
+ package_name , copr
362
+ )
363
+ ) from exc
271
364
272
365
@staticmethod
273
- def get_group_by_name_safe (group_name ):
366
+ def get_group_by_name (group_name ):
367
+ """
368
+ Get Group instance based on a given name.
369
+
370
+ Returns:
371
+ Group model
372
+
373
+ Raises:
374
+ ObjectNotFound for the API if no such group name exists.
375
+ """
274
376
try :
275
377
group = UsersLogic .get_group_by_alias (group_name ).one ()
276
- except sqlalchemy .orm .exc .NoResultFound :
378
+ except sqlalchemy .orm .exc .NoResultFound as exc :
277
379
raise ObjectNotFound (
278
- message = "Group {} does not exist." .format (group_name ))
380
+ message = "Group {} does not exist." .format (group_name )
381
+ ) from exc
279
382
return group
280
383
281
384
@staticmethod
282
- def get_copr_chroot_safe (copr , chroot_name ):
385
+ def get_copr_chroot (copr , chroot_name ):
386
+ """
387
+ Get CoprChroot by Copr model and chroot name.
388
+
389
+ Returns:
390
+ CoprChroot model
391
+
392
+ Raises:
393
+ ObjectNotFound for the API if no such chroot name exists in Copr.
394
+ """
283
395
try :
284
- chroot = CoprChrootsLogic .get_by_name_safe (copr , chroot_name )
396
+ chroot = CoprChrootsLogic .get_by_name_or_none (copr , chroot_name )
285
397
except (ValueError , KeyError , RuntimeError ) as e :
286
- raise ObjectNotFound (message = str (e ))
398
+ raise ObjectNotFound (message = str (e )) from e
287
399
288
400
if not chroot :
289
401
raise ObjectNotFound (
@@ -552,14 +664,14 @@ def get_additional_repo_views(cls, repos_list, chroot_id):
552
664
"name" : "Additional repo " + helpers .generate_repo_name (repo ),
553
665
}
554
666
555
- # We ask get_copr_by_repo_safe () here only to resolve the
667
+ # We ask get_copr_by_repo () here only to resolve the
556
668
# module_hotfixes attribute. If the asked project doesn't exist, we
557
669
# still adjust the 'repos' variable -- the build will eventually
558
670
# fail on repo downloading, but at least the copr maintainer will be
559
671
# notified about the misconfiguration. Better than just skip the
560
672
# repo.
561
673
try :
562
- copr = ComplexLogic .get_copr_by_repo_safe (repo )
674
+ copr = ComplexLogic .get_copr_by_repo (repo )
563
675
except ObjectNotFound :
564
676
copr = None
565
677
if copr and copr .module_hotfixes :
0 commit comments