Package coprs :: Package logic :: Module actions_logic
[hide private]
[frames] | no frames]

Source Code for Module coprs.logic.actions_logic

  1  import json 
  2  import time 
  3  from coprs import db 
  4  from coprs import models 
  5  from coprs import helpers 
  6  from flask import url_for 
7 8 9 -class ActionsLogic(object):
10 11 @classmethod
12 - def get(cls, action_id):
13 """ 14 Return single action identified by `action_id` 15 """ 16 17 query = models.Action.query.filter(models.Action.id == action_id) 18 return query
19 20 @classmethod
21 - def get_many(cls, action_type=None, result=None):
22 query = models.Action.query 23 if action_type is not None: 24 query = query.filter(models.Action.action_type == 25 int(action_type)) 26 if result is not None: 27 query = query.filter(models.Action.result == 28 int(result)) 29 30 return query
31 32 @classmethod
33 - def get_waiting(cls):
34 """ 35 Return actions that aren't finished 36 """ 37 38 query = (models.Action.query 39 .filter(models.Action.result == 40 helpers.BackendResultEnum("waiting")) 41 .filter(models.Action.action_type != 42 helpers.ActionTypeEnum("legal-flag")) 43 .order_by(models.Action.created_on.asc())) 44 45 return query
46 47 @classmethod
48 - def get_by_ids(cls, ids):
49 """ 50 Return actions matching passed `ids` 51 """ 52 53 return models.Action.query.filter(models.Action.id.in_(ids))
54 55 @classmethod
56 - def update_state_from_dict(cls, action, upd_dict):
57 """ 58 Update `action` object with `upd_dict` data 59 60 Updates result, message and ended_on parameters. 61 """ 62 63 for attr in ["result", "message", "ended_on"]: 64 value = upd_dict.get(attr, None) 65 if value: 66 setattr(action, attr, value) 67 68 db.session.add(action)
69 70 @classmethod
71 - def send_createrepo(cls, username, coprname, chroots):
72 data_dict = { 73 "username": username, 74 "projectname": coprname, 75 "chroots": chroots 76 } 77 action = models.Action( 78 action_type=helpers.ActionTypeEnum("createrepo"), 79 object_type="None", 80 object_id=0, 81 old_value="", 82 data=json.dumps(data_dict), 83 created_on=int(time.time()), 84 ) 85 db.session.add(action)
86 87 @classmethod
88 - def send_delete_build(cls, build):
89 """ Schedules build delete action 90 :type build: models.Build 91 """ 92 # don't delete skipped chroots 93 chroots_to_delete = [ 94 chroot.name for chroot in build.build_chroots 95 if chroot.state not in ["skipped"] 96 ] 97 if len(chroots_to_delete) == 0: 98 return 99 100 data_dict = { 101 "username": build.copr.owner_name, 102 "projectname": build.copr.name, 103 "chroots": chroots_to_delete 104 } 105 106 if build.is_older_results_naming_used: 107 if build.src_pkg_name is None or build.src_pkg_name == "": 108 return 109 data_dict["src_pkg_name"] = build.src_pkg_name 110 else: 111 data_dict["result_dir_name"] = build.result_dir_name 112 113 action = models.Action( 114 action_type=helpers.ActionTypeEnum("delete"), 115 object_type="build", 116 object_id=build.id, 117 old_value=build.copr.full_name, 118 data=json.dumps(data_dict), 119 created_on=int(time.time()) 120 ) 121 db.session.add(action)
122 123 @classmethod
124 - def send_update_comps(cls, chroot):
125 """ Schedules update comps.xml action 126 127 :type copr_chroot: models.CoprChroot 128 """ 129 130 if chroot.copr.is_a_group_project: 131 url_path = url_for('coprs_ns.group_chroot_view_comps', 132 group_name=chroot.copr.group.name, 133 coprname=chroot.copr.name, 134 chrootname=chroot.name) 135 else: 136 url_path = url_for('coprs_ns.chroot_view_comps', 137 username=chroot.copr.user.username, 138 coprname=chroot.copr.name, 139 chrootname=chroot.name) 140 141 data_dict = { 142 "ownername": chroot.copr.owner_name, 143 "projectname": chroot.copr.name, 144 "chroot": chroot.name, 145 "comps_present": chroot.comps_zlib is not None, 146 "url_path": url_path, 147 } 148 149 action = models.Action( 150 action_type=helpers.ActionTypeEnum("update_comps"), 151 object_type="copr_chroot", 152 data=json.dumps(data_dict), 153 created_on=int(time.time()) 154 ) 155 db.session.add(action)
156 157 @classmethod
158 - def send_update_module_md(cls, chroot):
159 """ Schedules update module_md.yaml action 160 161 :type copr_chroot: models.CoprChroot 162 """ 163 if chroot.copr.is_a_group_project: 164 url_path = url_for('coprs_ns.group_chroot_view_module_md', 165 group_name=chroot.copr.group.name, 166 coprname=chroot.copr.name, 167 chrootname=chroot.name) 168 else: 169 url_path = url_for('coprs_ns.chroot_view_module_md', 170 username=chroot.copr.user.username, 171 coprname=chroot.copr.name, 172 chrootname=chroot.name) 173 174 data_dict = { 175 "ownername": chroot.copr.owner_name, 176 "projectname": chroot.copr.name, 177 "chroot": chroot.name, 178 "module_md_present": chroot.module_md_zlib is not None, 179 "url_path": url_path, 180 } 181 182 action = models.Action( 183 action_type=helpers.ActionTypeEnum("update_module_md"), 184 object_type="copr_chroot", 185 data=json.dumps(data_dict), 186 created_on=int(time.time()) 187 ) 188 db.session.add(action)
189 190 @classmethod
191 - def send_create_gpg_key(cls, copr):
192 """ 193 :type copr: models.Copr 194 """ 195 196 data_dict = { 197 "username": copr.owner_name, 198 "projectname": copr.name, 199 } 200 201 action = models.Action( 202 action_type=helpers.ActionTypeEnum("gen_gpg_key"), 203 object_type="copr", 204 data=json.dumps(data_dict), 205 created_on=int(time.time()), 206 ) 207 db.session.add(action)
208 209 @classmethod
210 - def send_rawhide_to_release(cls, data):
211 action = models.Action( 212 action_type=helpers.ActionTypeEnum("rawhide_to_release"), 213 object_type="None", 214 data=json.dumps(data), 215 created_on=int(time.time()), 216 ) 217 db.session.add(action)
218 219 @classmethod
220 - def send_fork_copr(cls, src, dst, builds_map):
221 """ 222 :type src: models.Copr 223 :type dst: models.Copr 224 :type builds_map: dict where keys are forked builds IDs and values are IDs from the original builds. 225 """ 226 227 action = models.Action( 228 action_type=helpers.ActionTypeEnum("fork"), 229 object_type="copr", 230 old_value="{0}".format(src.full_name), 231 new_value="{0}".format(dst.full_name), 232 data=json.dumps({"user": dst.owner_name, "copr": dst.name, "builds_map": builds_map}), 233 created_on=int(time.time()), 234 ) 235 db.session.add(action)
236