Trees | Indices | Help |
---|
|
1 # coding: utf-8 2 3 import time 4 import flask 5 import sqlalchemy 6 7 from .. import db 8 from .builds_logic import BuildsLogic 9 from coprs import models 10 from coprs import exceptions 11 from coprs.exceptions import ObjectNotFound 12 from coprs.helpers import StatusEnum 13 from coprs.logic.packages_logic import PackagesLogic 14 from coprs.logic.actions_logic import ActionsLogic 15 16 from coprs.logic.users_logic import UsersLogic 17 from coprs.models import User, Copr 18 from .coprs_logic import CoprsLogic, CoprChrootsLogic 19 from .. import helpers23 """ 24 Used for manipulation which affects multiply models 25 """ 26 27 @classmethod18729 """ 30 Delete copr and all its builds. 31 32 :param copr: 33 :raises ActionInProgressException: 34 :raises InsufficientRightsException: 35 """ 36 builds_query = BuildsLogic.get_multiple_by_copr(copr=copr) 37 38 if copr.persistent: 39 raise exceptions.InsufficientRightsException("This project is protected against deletion.") 40 41 for build in builds_query: 42 BuildsLogic.delete_build(flask.g.user, build, send_delete_action=False) 43 44 CoprsLogic.delete_unsafe(flask.g.user, copr)45 46 @classmethod48 forking = ProjectForking(user, dstgroup) 49 created = (not bool(forking.get(copr, dstname))) 50 fcopr = forking.fork_copr(copr, dstname) 51 52 if fcopr.full_name == copr.full_name: 53 raise exceptions.DuplicateException("Source project should not be same as destination") 54 55 builds_map = {} 56 for package in copr.packages: 57 fpackage = forking.fork_package(package, fcopr) 58 build = package.last_build(successful=True) 59 if not build: 60 continue 61 62 fbuild = forking.fork_build(build, fcopr, fpackage) 63 builds_map[fbuild.id] = build.result_dir_name 64 65 db.session.commit() 66 ActionsLogic.send_fork_copr(copr, fcopr, builds_map) 67 return fcopr, created68 69 @staticmethod71 group = ComplexLogic.get_group_by_name_safe(group_name) 72 73 try: 74 return CoprsLogic.get_by_group_id( 75 group.id, copr_name, **kwargs).one() 76 except sqlalchemy.orm.exc.NoResultFound: 77 raise ObjectNotFound( 78 message="Project @{}/{} does not exist." 79 .format(group_name, copr_name))80 81 @staticmethod83 """ Get one project 84 85 This always return personal project. For group projects see get_group_copr_safe(). 86 """ 87 try: 88 return CoprsLogic.get(user_name, copr_name, **kwargs).filter(Copr.group_id.is_(None)).one() 89 except sqlalchemy.orm.exc.NoResultFound: 90 raise ObjectNotFound( 91 message="Project {}/{} does not exist." 92 .format(user_name, copr_name))93 94 @staticmethod96 if owner_name[0] == "@": 97 return ComplexLogic.get_group_copr_safe(owner_name[1:], copr_name, **kwargs) 98 return ComplexLogic.get_copr_safe(owner_name, copr_name, **kwargs)99 100 @staticmethod102 try: 103 return CoprsLogic.get_by_id(copr_id).one() 104 except sqlalchemy.orm.exc.NoResultFound: 105 raise ObjectNotFound( 106 message="Project with id {} does not exist." 107 .format(copr_id))108 109 @staticmethod111 try: 112 return BuildsLogic.get_by_id(build_id).one() 113 except sqlalchemy.orm.exc.NoResultFound: 114 raise ObjectNotFound( 115 message="Build {} does not exist.".format(build_id))116 117 @staticmethod119 try: 120 return PackagesLogic.get_by_id(package_id).one() 121 except sqlalchemy.orm.exc.NoResultFound: 122 raise ObjectNotFound( 123 message="Package {} does not exist.".format(package_id))124 125 @staticmethod127 try: 128 return PackagesLogic.get(copr.id, package_name).one() 129 except sqlalchemy.orm.exc.NoResultFound: 130 raise ObjectNotFound( 131 message="Package {} in the copr {} does not exist." 132 .format(package_name, copr))133 134 @staticmethod136 try: 137 group = UsersLogic.get_group_by_alias(group_name).one() 138 except sqlalchemy.orm.exc.NoResultFound: 139 raise ObjectNotFound( 140 message="Group {} does not exist.".format(group_name)) 141 return group142 143 @staticmethod145 try: 146 chroot = CoprChrootsLogic.get_by_name_safe(copr, chroot_name) 147 except (ValueError, KeyError, RuntimeError) as e: 148 raise ObjectNotFound(message=str(e)) 149 150 if not chroot: 151 raise ObjectNotFound( 152 message="Chroot name {} does not exist.".format(chroot_name)) 153 154 return chroot155 # 156 # @staticmethod 157 # def get_coprs_in_a_group(group_name): 158 # group = ComplexLogic.get_group_by_name_safe(group_name) 159 # 160 # 161 162 @staticmethod164 names = flask.g.user.user_groups 165 if names: 166 query = UsersLogic.get_groups_by_names_list(names) 167 return query.filter(User.name == user_name) 168 else: 169 return []170 171 @staticmethod173 # todo: check if count works slowly 174 175 waiting = BuildsLogic.get_build_task_queue(is_background=False).count() 176 waiting_bg = BuildsLogic.get_build_task_queue(is_background=True).count() 177 running = BuildsLogic.get_build_tasks(StatusEnum("running")).count() 178 importing = BuildsLogic.get_build_tasks(helpers.StatusEnum("importing"), background=False).count() 179 importing_bg = BuildsLogic.get_build_tasks(helpers.StatusEnum("importing"), background=True).count() 180 return dict( 181 waiting=waiting, 182 running=running, 183 importing=importing, 184 waiting_bg=waiting_bg, 185 importing_bg=importing_bg 186 )247191 self.user = user 192 self.group = group 193 194 if group and not user.can_build_in_group(group): 195 raise exceptions.InsufficientRightsException( 196 "Only members may create projects in the particular groups.")197199 return CoprsLogic.get_by_group_id(self.group.id, name).first() if self.group \ 200 else CoprsLogic.filter_without_group_projects(CoprsLogic.get(flask.g.user.name, name)).first()201203 fcopr = self.get(copr, name) 204 if not fcopr: 205 fcopr = self.create_object(models.Copr, copr, exclude=["id", "group_id", "created_on"]) 206 fcopr.forked_from_id = copr.id 207 fcopr.user = self.user 208 fcopr.user_id = self.user.id 209 fcopr.created_on = int(time.time()) 210 if name: 211 fcopr.name = name 212 if self.group: 213 fcopr.group = self.group 214 fcopr.group_id = self.group.id 215 216 for chroot in list(copr.copr_chroots): 217 CoprChrootsLogic.create_chroot(self.user, fcopr, chroot.mock_chroot, chroot.buildroot_pkgs, 218 chroot.repos, comps=chroot.comps, comps_name=chroot.comps_name) 219 db.session.add(fcopr) 220 return fcopr221223 fpackage = PackagesLogic.get(fcopr.id, package.name).first() 224 if not fpackage: 225 fpackage = self.create_object(models.Package, package, exclude=["id", "copr_id"]) 226 fpackage.copr = fcopr 227 db.session.add(fpackage) 228 return fpackage229231 fbuild = self.create_object(models.Build, build, exclude=["id", "copr_id", "package_id"]) 232 fbuild.copr = fcopr 233 fbuild.package = fpackage 234 fbuild.build_chroots = [self.create_object(models.BuildChroot, c, exclude=["id", "build_id"]) for c in build.build_chroots] 235 for chroot in fbuild.build_chroots: 236 chroot.status = StatusEnum("forked") 237 db.session.add(fbuild) 238 db.session.flush() 239 return fbuild240242 arguments = {} 243 for name, column in from_object.__mapper__.columns.items(): 244 if not name in exclude: 245 arguments[name] = getattr(from_object, name) 246 return clazz(**arguments)
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 | http://epydoc.sourceforge.net |