Package commands :: Module rawhide_to_release
[hide private]
[frames] | no frames]

Source Code for Module commands.rawhide_to_release

  1  import click 
  2  from sqlalchemy import func 
  3  from sqlalchemy.orm import joinedload 
  4   
  5  from flask_script import Command, Option 
  6  from copr_common.enums import StatusEnum 
  7  from coprs import db 
  8  from coprs import models 
  9  from coprs.logic import coprs_logic, actions_logic, builds_logic, packages_logic 
 10   
 11   
 12  @click.command() 
 13  @click.argument( 
 14      "rawhide_chroot", 
 15      required=True 
 16  ) 
 17  @click.argument( 
 18      "dest_chroot", 
 19      required=True 
 20  ) 
21 -def rawhide_to_release(rawhide_chroot, dest_chroot):
22 """ 23 Branching 24 """ 25 return rawhide_to_release_function(rawhide_chroot, dest_chroot)
26
27 -def rawhide_to_release_function(rawhide_chroot, dest_chroot):
28 mock_chroot = coprs_logic.MockChrootsLogic.get_from_name(dest_chroot).first() 29 if not mock_chroot: 30 print("Given chroot does not exist. Please run:") 31 print(" sudo python3 manage.py create-chroot {}".format(dest_chroot)) 32 return 33 34 mock_rawhide_chroot = coprs_logic.MockChrootsLogic.get_from_name(rawhide_chroot).first() 35 if not mock_rawhide_chroot: 36 print("Given rawhide chroot does not exist. Didnt you mistyped?:") 37 print(" {}".format(rawhide_chroot)) 38 return 39 40 coprs_query = ( 41 coprs_logic.CoprsLogic.get_all() 42 .join(models.CoprChroot) 43 .filter(models.Copr.follow_fedora_branching == True) 44 .filter(models.CoprChroot.mock_chroot == mock_rawhide_chroot) 45 .options(joinedload('copr_chroots').joinedload('mock_chroot')) 46 ) 47 48 for copr in coprs_query: 49 print("Handling builds in copr '{}', chroot '{}'".format( 50 copr.full_name, mock_rawhide_chroot.name)) 51 turn_on_the_chroot_for_copr(copr, rawhide_chroot, mock_chroot) 52 53 data = {"projectname": copr.name, 54 "ownername": copr.owner_name, 55 "rawhide_chroot": rawhide_chroot, 56 "dest_chroot": dest_chroot, 57 "builds": []} 58 59 latest_pkg_builds_in_rawhide = ( 60 db.session.query( 61 func.max(models.Build.id), 62 ) 63 .join(models.BuildChroot) 64 .join(models.Package) 65 .filter(models.BuildChroot.mock_chroot_id == mock_rawhide_chroot.id) 66 .filter(models.BuildChroot.status == StatusEnum("succeeded")) 67 .filter(models.Package.copr_dir == copr.main_dir) 68 .group_by(models.Package.name) 69 ) 70 71 fork_builds = ( 72 db.session.query(models.Build) 73 .options(joinedload('build_chroots').joinedload('mock_chroot')) 74 .filter(models.Build.id.in_(latest_pkg_builds_in_rawhide.subquery())) 75 ).all() 76 77 78 # no builds to fork in this copr 79 if not len(fork_builds): 80 continue 81 82 for build in fork_builds: 83 if mock_chroot in build.chroots: 84 # forked chroot already exists, from previous run? 85 continue 86 87 # rbc means rawhide_build_chroot (we needed short variable) 88 rbc = None 89 for rbc in build.build_chroots: 90 if rbc.mock_chroot == mock_rawhide_chroot: 91 break 92 93 dest_build_chroot = models.BuildChroot(**rbc.to_dict()) 94 dest_build_chroot.mock_chroot_id = mock_chroot.id 95 dest_build_chroot.mock_chroot = mock_chroot 96 dest_build_chroot.status = StatusEnum("forked") 97 db.session.add(dest_build_chroot) 98 99 data['builds'].append(build.result_dir) 100 101 if len(data["builds"]): 102 actions_logic.ActionsLogic.send_rawhide_to_release(data) 103 104 db.session.commit()
105
106 -def turn_on_the_chroot_for_copr(copr, rawhide_name, mock_chroot):
107 rawhide_chroot = None 108 for chroot in copr.copr_chroots: 109 if chroot.name == rawhide_name: 110 rawhide_chroot = chroot 111 if chroot.name == mock_chroot.name: 112 # already created 113 return 114 115 create_kwargs = { 116 "buildroot_pkgs": rawhide_chroot.buildroot_pkgs, 117 "comps": rawhide_chroot.comps, 118 "comps_name": rawhide_chroot.comps_name, 119 } 120 coprs_logic.CoprChrootsLogic.create_chroot(copr.user, copr, mock_chroot, **create_kwargs)
121