Ejemplo n.º 1
0
 def execute(self, session, name, content_from_file, append):
     ns, name = PackageGroup.parse_name(name)
     group = session.db.query(PackageGroup)\
         .filter_by(name=name, namespace=ns or None).first()
     if group:
         sys.exit("Group already exists")
     group = PackageGroup(name=name, namespace=ns)
     session.db.add(group)
     session.db.flush()
     session.log_user_action("Group {} created".format(group.full_name))
     self.set_group_content(session, group, content_from_file, append)
Ejemplo n.º 2
0
 def execute(self, session, name, content_from_file, append):
     ns, name = PackageGroup.parse_name(name)
     group = session.db.query(PackageGroup)\
         .filter_by(name=name, namespace=ns or None).first()
     if group:
         sys.exit("Group already exists")
     group = PackageGroup(name=name, namespace=ns)
     session.db.add(group)
     session.db.flush()
     session.log_user_action("Group {} created".format(group.full_name))
     self.set_group_content(session, group, content_from_file, append)
Ejemplo n.º 3
0
 def execute(self, session, current_name, new_name, new_namespace,
             make_global, content_from_file, append):
     ns, name = PackageGroup.parse_name(current_name)
     group = session.db.query(PackageGroup)\
         .filter_by(name=name, namespace=ns or None).first()
     if not group:
         sys.exit("Group {} not found".format(current_name))
     if new_name:
         group.name = new_name
     if new_namespace:
         group.namespace = new_namespace
     if make_global:
         group.namespace = None
     self.set_group_content(session, group, content_from_file, append)
Ejemplo n.º 4
0
 def execute(self, session, current_name, new_name, new_namespace,
             make_global, content_from_file, append):
     ns, name = PackageGroup.parse_name(current_name)
     group = session.db.query(PackageGroup)\
         .filter_by(name=name, namespace=ns or None).first()
     if not group:
         sys.exit("Group {} not found".format(current_name))
     if new_name:
         group.name = new_name
     if new_namespace:
         group.namespace = new_namespace
     if make_global:
         group.namespace = None
     self.set_group_content(session, group, content_from_file, append)
Ejemplo n.º 5
0
 def execute(self, session, group, pkgs, maintainer):
     namespace, name = PackageGroup.parse_name(group)
     if (session.db.query(PackageGroup).filter_by(namespace=namespace,
                                                  name=name).count()):
         sys.exit("Group already exists")
     group_obj = PackageGroup(name=name, namespace=namespace)
     session.db.add(group_obj)
     session.db.flush()
     session.log_user_action("Group {} created".format(group.full_name))
     try:
         data.set_group_content(session, group, pkgs)
         data.set_group_maintainers(session, group, maintainer)
     except data.PackagesDontExist as e:
         sys.exit(str(e))
Ejemplo n.º 6
0
 def execute(self, session, group, pkgs, maintainer):
     namespace, name = PackageGroup.parse_name(group)
     if (session.db.query(PackageGroup)
             .filter_by(namespace=namespace, name=name)
             .count()):
         sys.exit("Group already exists")
     group_obj = PackageGroup(name=name, namespace=namespace)
     session.db.add(group_obj)
     session.db.flush()
     session.log_user_action("Group {} created".format(group.full_name))
     try:
         data.set_group_content(session, group, pkgs)
         data.set_group_maintainers(session, group, maintainer)
     except data.PackagesDontExist as e:
         sys.exit(str(e))
Ejemplo n.º 7
0
def add_packages():
    """
    Mark multiple packages as tracked. Optionally add them to a group.
    """
    form = forms.AddPackagesForm()
    if request.method == 'POST':
        if not form.validate_or_flash():
            return render_template("add-packages.html", form=form)
        names = set(form.packages.data)
        try:
            collection = [
                c for c in g.collections if c.name == form.collection.data
            ][0]
        except IndexError:
            abort(404)

        try:
            added = data.track_packages(session, collection, names)
        except data.PackagesDontExist as e:
            db.rollback()
            flash_nak(str(e))
            # frontend doesn't have Koji access, so it needs to rely on backend's polling
            flash_nak(
                dedent("""
                If a package has been just created, it is possible that it
                hasn't been propagated to our database yet. In that case,
                please, try again later.
            """))
            return render_template("add-packages.html", form=form)

        if form.group.data:
            namespace, name = PackageGroup.parse_name(form.group.data)
            group = db.query(PackageGroup)\
                      .filter_by(namespace=namespace, name=name)\
                      .first_or_404()
            if not group.editable:
                abort(400)
            data.set_group_content(session, group, names, append=True)

        flash_ack("Packages added: {}".format(','.join(p.name for p in added)))
        db.commit()
        return redirect(request.form.get('next') or url_for('frontpage'))
    return render_template("add-packages.html", form=form)
Ejemplo n.º 8
0
def add_packages():
    """
    Mark multiple packages as tracked. Optionally add them to a group.
    """
    form = forms.AddPackagesForm()
    if request.method == 'POST':
        if not form.validate_or_flash():
            return render_template("add-packages.html", form=form)
        names = set(form.packages.data)
        try:
            collection = [c for c in g.collections
                          if c.name == form.collection.data][0]
        except IndexError:
            abort(404)

        try:
            added = data.track_packages(session, collection, names)
        except data.PackagesDontExist as e:
            db.rollback()
            flash_nak(str(e))
            # frontend doesn't have Koji access, so it needs to rely on backend's polling
            flash_nak(dedent("""
                If a package has been just created, it is possible that it
                hasn't been propagated to our database yet. In that case,
                please, try again later.
            """))
            return render_template("add-packages.html", form=form)

        if form.group.data:
            namespace, name = PackageGroup.parse_name(form.group.data)
            group = db.query(PackageGroup)\
                      .filter_by(namespace=namespace, name=name)\
                      .first_or_404()
            if not group.editable:
                abort(400)
            data.set_group_content(session, group, names, append=True)

        flash_ack("Packages added: {}".format(','.join(p.name for p in added)))
        db.commit()
        return redirect(request.form.get('next') or url_for('frontpage'))
    return render_template("add-packages.html", form=form)
Ejemplo n.º 9
0
 def test_group_name_parse(self):
     self.assertEqual((None, 'foo'), PackageGroup.parse_name('foo'))
     self.assertEqual(('ns', 'bar'), PackageGroup.parse_name('ns/bar'))