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