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 -def option_retry_forked(f):
12 """ Shortcut to --retry-forked option definition, to avoid C&P """ 13 method = click.option( 14 "--retry-forked/--no-retry-forked", 15 default=False, 16 help=( 17 "Generate actions for backend also for already forked builds, useful " 18 "e.g. when previous run of this command failed." 19 ) 20 ) 21 return method(f)
22 23 24 @click.command() 25 @click.argument( 26 "rawhide_chroot", 27 required=True 28 ) 29 @click.argument( 30 "dest_chroot", 31 required=True 32 )
33 @option_retry_forked 34 -def rawhide_to_release(rawhide_chroot, dest_chroot, retry_forked):
35 """ 36 Branching 37 """ 38 return rawhide_to_release_function(rawhide_chroot, dest_chroot, 39 retry_forked)
40
41 -def rawhide_to_release_function(rawhide_chroot, dest_chroot, retry_forked):
42 mock_chroot = coprs_logic.MockChrootsLogic.get_from_name(dest_chroot).first() 43 if not mock_chroot: 44 print("Given chroot does not exist. Please run:") 45 print(" sudo python3 manage.py create-chroot {}".format(dest_chroot)) 46 return 47 48 mock_rawhide_chroot = coprs_logic.MockChrootsLogic.get_from_name(rawhide_chroot).first() 49 if not mock_rawhide_chroot: 50 print("Given rawhide chroot does not exist. Didnt you mistyped?:") 51 print(" {}".format(rawhide_chroot)) 52 return 53 54 coprs_query = ( 55 coprs_logic.CoprsLogic.get_all() 56 .join(models.CoprChroot) 57 .filter(models.Copr.follow_fedora_branching == True) 58 .filter(models.CoprChroot.mock_chroot == mock_rawhide_chroot) 59 .options(joinedload('copr_chroots').joinedload('mock_chroot')) 60 ) 61 62 mock_chroot.comment = mock_rawhide_chroot.comment 63 64 for copr in coprs_query: 65 print("Handling builds in copr '{}', chroot '{}'".format( 66 copr.full_name, mock_rawhide_chroot.name)) 67 turn_on_the_chroot_for_copr(copr, rawhide_chroot, mock_chroot) 68 69 data = {"projectname": copr.name, 70 "ownername": copr.owner_name, 71 "rawhide_chroot": rawhide_chroot, 72 "dest_chroot": dest_chroot, 73 "builds": []} 74 75 latest_pkg_builds_in_rawhide = ( 76 db.session.query( 77 func.max(models.Build.id), 78 ) 79 .join(models.BuildChroot) 80 .join(models.Package) 81 .filter(models.BuildChroot.mock_chroot_id == mock_rawhide_chroot.id) 82 .filter(models.BuildChroot.status == StatusEnum("succeeded")) 83 .filter(models.Package.copr_dir == copr.main_dir) 84 .group_by(models.Package.name) 85 ) 86 87 fork_builds = ( 88 db.session.query(models.Build) 89 .options(joinedload('build_chroots').joinedload('mock_chroot')) 90 .filter(models.Build.id.in_(latest_pkg_builds_in_rawhide.subquery())) 91 ).all() 92 93 94 # no builds to fork in this copr 95 if not len(fork_builds): 96 continue 97 98 for build in fork_builds: 99 chroot_exists = mock_chroot in build.chroots 100 101 if chroot_exists and not retry_forked: 102 # this build should already be forked 103 continue 104 105 # rbc means rawhide_build_chroot (we needed short variable) 106 rbc = None 107 for rbc in build.build_chroots: 108 if rbc.mock_chroot == mock_rawhide_chroot: 109 break 110 111 if not chroot_exists: 112 # forked chroot may already exists, e.g. from prevoius 113 # 'rawhide-to-release-run' 114 dest_build_chroot = builds_logic.BuildChrootsLogic.new( 115 build=rbc.build, 116 mock_chroot=mock_chroot, 117 **rbc.to_dict({ 118 "__columns_except__": ["id"], 119 }), 120 ) 121 dest_build_chroot.status = StatusEnum("forked") 122 db.session.add(dest_build_chroot) 123 124 if rbc.result_dir: 125 data['builds'].append(rbc.result_dir) 126 127 if len(data["builds"]): 128 actions_logic.ActionsLogic.send_rawhide_to_release(data) 129 130 db.session.commit()
131
132 -def turn_on_the_chroot_for_copr(copr, rawhide_name, mock_chroot):
133 rawhide_chroot = None 134 for chroot in copr.copr_chroots: 135 if chroot.name == rawhide_name: 136 rawhide_chroot = chroot 137 if chroot.name == mock_chroot.name: 138 # already created 139 return 140 141 create_kwargs = { 142 "buildroot_pkgs": rawhide_chroot.buildroot_pkgs, 143 "comps": rawhide_chroot.comps, 144 "comps_name": rawhide_chroot.comps_name, 145 } 146 coprs_logic.CoprChrootsLogic.create_chroot(copr.user, copr, mock_chroot, **create_kwargs)
147