def new(cls, user, copr, check_for_duplicates=True): if check_for_duplicates: if copr.group is None and cls.exists_for_user(user, copr.name).all(): raise exceptions.DuplicateException( "Copr: '{0}/{1}' already exists".format(user.name, copr.name)) elif copr.group: db.session.flush() # otherwise copr.id is not set from sequence if cls.exists_for_group(copr.group, copr.name).filter(models.Copr.id != copr.id).all(): db.session.rollback() raise exceptions.DuplicateException( "Copr: '@{0}/{1}' already exists".format(copr.group.name, copr.name)) db.session.add(copr)
def new(cls, user, copr_name, group=None, check_for_duplicates=True): if check_for_duplicates: if group is None and cls.exists_for_user(user, copr_name).all(): raise exceptions.DuplicateException( "Copr: '{0}/{1}' already exists".format( user.name, copr_name)) elif group: if cls.exists_for_group(group, copr_name).all(): db.session.rollback() raise exceptions.DuplicateException( "Copr: '@{0}/{1}' already exists".format( group.name, copr_name))
def fork_copr(cls, copr, user, dstname, dstgroup=None): forking = ProjectForking(user, dstgroup) created = (not bool(forking.get(copr, dstname))) fcopr = forking.fork_copr(copr, dstname) if fcopr.full_name == copr.full_name: raise exceptions.DuplicateException( "Source project should not be same as destination") builds_map = {} for package in copr.main_dir.packages: fpackage = forking.fork_package(package, fcopr) build = package.last_build(successful=True) if not build: continue fbuild = forking.fork_build(build, fcopr, fpackage) if build.result_dir: builds_map['srpm-builds'] = (build.result_dir, fbuild.result_dir) for chroot, fchroot in zip(build.build_chroots, fbuild.build_chroots): if chroot.result_dir: builds_map[chroot.name] = (chroot.result_dir, fchroot.result_dir) db.session.commit() ActionsLogic.send_fork_copr(copr, fcopr, builds_map) return fcopr, created
def add(cls, user, copr_dir, package_name, source_type=helpers.BuildSourceEnum("unset"), source_json=json.dumps({})): users_logic.UsersLogic.raise_if_cant_build_in_copr( user, copr_dir.copr, "You don't have permissions to build in this copr.") if cls.exists(copr_dir.id, package_name).all(): raise exceptions.DuplicateException( "Project dir {} already has a package '{}'".format( copr_dir.full_name, package_name)) package = models.Package( name=package_name, copr=copr_dir.copr, copr_dir=copr_dir, source_type=source_type, source_json=source_json, ) db.session.add(package) return package
def update(cls, user, copr, check_for_duplicates=True): cls.raise_if_unfinished_blocking_action( user, copr, "Can't change this project name," " another operation is in progress: {action}") users_logic.UsersLogic.raise_if_cant_update_copr( user, copr, "Only owners and admins may update their projects.") existing = cls.exists_for_user(copr.owner, copr.name).first() if existing: if check_for_duplicates and existing.id != copr.id: raise exceptions.DuplicateException( "Project: '{0}' already exists".format(copr.name)) else: # we're renaming # if we fire a models.Copr.query, it will use the modified copr in session # -> workaround this by just getting the name old_copr_name = (db.session.query(models.Copr.name) .filter(models.Copr.id == copr.id) .filter(models.Copr.deleted == False) .first()[0]) action = models.Action(action_type=helpers.ActionTypeEnum("rename"), object_type="copr", object_id=copr.id, old_value="{0}/{1}".format(copr.owner.name, old_copr_name), new_value="{0}/{1}".format(copr.owner.name, copr.name), created_on=int(time.time())) db.session.add(action) db.session.add(copr)
def add(cls, name): name_tuple = cls.tuple_from_name(name) if cls.get(*name_tuple).first(): raise exceptions.DuplicateException( "Mock chroot with this name already exists.") new_chroot = models.MockChroot(os_release=name_tuple[0], os_version=name_tuple[1], arch=name_tuple[2]) cls.new(new_chroot) return new_chroot
def fork_copr(cls, copr, user, dstname, dstgroup=None): forking = ProjectForking(user, dstgroup) created = (not bool(forking.get(copr, dstname))) fcopr = forking.fork_copr(copr, dstname) if fcopr.full_name == copr.full_name: raise exceptions.DuplicateException("Source project should not be same as destination") builds_map = {} for package in copr.packages: fpackage = forking.fork_package(package, fcopr) build = package.last_build() if not build: continue fbuild = forking.fork_build(build, fcopr, fpackage) builds_map[fbuild.id] = build.result_dir_name ActionsLogic.send_fork_copr(copr, fcopr, builds_map) return fcopr, created
def new(cls, user, copr, check_for_duplicates=True): if check_for_duplicates and cls.exists_for_user(user, copr.name).all(): raise exceptions.DuplicateException( "Copr: '{0}' already exists".format(copr.name)) db.session.add(copr)