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 @classmethod18629 """ 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 ActionsLogic.send_fork_copr(copr, fcopr, builds_map) 66 return fcopr, created67 68 @staticmethod70 group = ComplexLogic.get_group_by_name_safe(group_name) 71 72 try: 73 return CoprsLogic.get_by_group_id( 74 group.id, copr_name, **kwargs).one() 75 except sqlalchemy.orm.exc.NoResultFound: 76 raise ObjectNotFound( 77 message="Project @{}/{} does not exist." 78 .format(group_name, copr_name))79 80 @staticmethod82 """ Get one project 83 84 This always return personal project. For group projects see get_group_copr_safe(). 85 """ 86 try: 87 return CoprsLogic.get(user_name, copr_name, **kwargs).filter(Copr.group_id.is_(None)).one() 88 except sqlalchemy.orm.exc.NoResultFound: 89 raise ObjectNotFound( 90 message="Project {}/{} does not exist." 91 .format(user_name, copr_name))92 93 @staticmethod95 if owner_name[0] == "@": 96 return ComplexLogic.get_group_copr_safe(owner_name[1:], copr_name, **kwargs) 97 return ComplexLogic.get_copr_safe(owner_name, copr_name, **kwargs)98 99 @staticmethod101 try: 102 return CoprsLogic.get_by_id(copr_id).one() 103 except sqlalchemy.orm.exc.NoResultFound: 104 raise ObjectNotFound( 105 message="Project with id {} does not exist." 106 .format(copr_id))107 108 @staticmethod110 try: 111 return BuildsLogic.get_by_id(build_id).one() 112 except sqlalchemy.orm.exc.NoResultFound: 113 raise ObjectNotFound( 114 message="Build {} does not exist.".format(build_id))115 116 @staticmethod118 try: 119 return PackagesLogic.get_by_id(package_id).one() 120 except sqlalchemy.orm.exc.NoResultFound: 121 raise ObjectNotFound( 122 message="Package {} does not exist.".format(package_id))123 124 @staticmethod126 try: 127 return PackagesLogic.get(copr.id, package_name).one() 128 except sqlalchemy.orm.exc.NoResultFound: 129 raise ObjectNotFound( 130 message="Package {} in the copr {} does not exist." 131 .format(package_name, copr))132 133 @staticmethod135 try: 136 group = UsersLogic.get_group_by_alias(group_name).one() 137 except sqlalchemy.orm.exc.NoResultFound: 138 raise ObjectNotFound( 139 message="Group {} does not exist.".format(group_name)) 140 return group141 142 @staticmethod144 try: 145 chroot = CoprChrootsLogic.get_by_name_safe(copr, chroot_name) 146 except (ValueError, KeyError, RuntimeError) as e: 147 raise ObjectNotFound(message=str(e)) 148 149 if not chroot: 150 raise ObjectNotFound( 151 message="Chroot name {} does not exist.".format(chroot_name)) 152 153 return chroot154 # 155 # @staticmethod 156 # def get_coprs_in_a_group(group_name): 157 # group = ComplexLogic.get_group_by_name_safe(group_name) 158 # 159 # 160 161 @staticmethod163 names = flask.g.user.user_groups 164 if names: 165 query = UsersLogic.get_groups_by_names_list(names) 166 return query.filter(User.name == user_name) 167 else: 168 return []169 170 @staticmethod172 # todo: check if count works slowly 173 174 waiting = BuildsLogic.get_build_task_queue(is_background=False).count() 175 waiting_bg = BuildsLogic.get_build_task_queue(is_background=True).count() 176 running = BuildsLogic.get_build_tasks(StatusEnum("running")).count() 177 importing = BuildsLogic.get_build_tasks(helpers.StatusEnum("importing"), background=False).count() 178 importing_bg = BuildsLogic.get_build_tasks(helpers.StatusEnum("importing"), background=True).count() 179 return dict( 180 waiting=waiting, 181 running=running, 182 importing=importing, 183 waiting_bg=waiting_bg, 184 importing_bg=importing_bg 185 )246190 self.user = user 191 self.group = group 192 193 if group and not user.can_build_in_group(group): 194 raise exceptions.InsufficientRightsException( 195 "Only members may create projects in the particular groups.")196198 return CoprsLogic.get_by_group_id(self.group.id, name).first() if self.group \ 199 else CoprsLogic.filter_without_group_projects(CoprsLogic.get(flask.g.user.name, name)).first()200202 fcopr = self.get(copr, name) 203 if not fcopr: 204 fcopr = self.create_object(models.Copr, copr, exclude=["id", "group_id", "created_on"]) 205 fcopr.forked_from_id = copr.id 206 fcopr.user = self.user 207 fcopr.user_id = self.user.id 208 fcopr.created_on = int(time.time()) 209 if name: 210 fcopr.name = name 211 if self.group: 212 fcopr.group = self.group 213 fcopr.group_id = self.group.id 214 215 for chroot in list(copr.copr_chroots): 216 CoprChrootsLogic.create_chroot(self.user, fcopr, chroot.mock_chroot, chroot.buildroot_pkgs, 217 chroot.repos, comps=chroot.comps, comps_name=chroot.comps_name) 218 db.session.add(fcopr) 219 return fcopr220222 fpackage = PackagesLogic.get(fcopr.id, package.name).first() 223 if not fpackage: 224 fpackage = self.create_object(models.Package, package, exclude=["id", "copr_id"]) 225 fpackage.copr = fcopr 226 db.session.add(fpackage) 227 return fpackage228230 fbuild = self.create_object(models.Build, build, exclude=["id", "copr_id", "package_id"]) 231 fbuild.copr = fcopr 232 fbuild.package = fpackage 233 fbuild.build_chroots = [self.create_object(models.BuildChroot, c, exclude=["id", "build_id"]) for c in build.build_chroots] 234 for chroot in fbuild.build_chroots: 235 chroot.status = StatusEnum("forked") 236 db.session.add(fbuild) 237 db.session.commit() 238 return fbuild239241 arguments = {} 242 for name, column in from_object.__mapper__.columns.items(): 243 if not name in exclude: 244 arguments[name] = getattr(from_object, name) 245 return clazz(**arguments)
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Mon Dec 5 22:37:25 2016 | http://epydoc.sourceforge.net |