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

Source Code for Module commands.rawhide_to_release

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