Ejemplo n.º 1
0
def delete_distro(distro_name):
    """ Delete a distro """

    distro = anitya.lib.model.Distro.by_name(SESSION, distro_name)
    if not distro:
        flask.abort(404)

    if not is_admin():
        flask.abort(401)

    form = anitya.forms.ConfirmationForm()

    if form.validate_on_submit():
        anitya.log(
            SESSION,
            distro=distro,
            topic='distro.remove',
            message=dict(
                agent=flask.g.auth.openid,
                distro=distro.name,
            )
        )

        SESSION.delete(distro)
        SESSION.commit()
        flask.flash('Distro %s has been removed' % distro_name)
        return flask.redirect(flask.url_for('distros'))

    return flask.render_template(
        'distro_delete.html',
        current='distros',
        distro=distro,
        form=form)
Ejemplo n.º 2
0
Archivo: ui.py Proyecto: cicku/anitya
def map_project(project_id):

    project = anitya.lib.model.Project.get(SESSION, project_id)
    if not project:
        flask.abort(404)

    form = anitya.forms.MappingForm()

    if form.validate_on_submit():

        try:
            anitya.lib.map_project(
                SESSION,
                project=project,
                package_name=form.package_name.data,
                distribution=form.distro.data,
                user_mail=flask.g.auth.email,
            )
            SESSION.commit()
            flask.flash('Mapping added')
        except anitya.lib.exceptions.AnityaException as err:
            flask.flash(str(err), 'error')

        return flask.redirect(
            flask.url_for('project', project_id=project.id)
        )

    return flask.render_template(
        'mapping.html',
        current='projects',
        project=project,
        form=form,
    )
Ejemplo n.º 3
0
def delete_distro(distro_name):
    """ Delete a distro """

    distro = anitya.lib.model.Distro.by_name(SESSION, distro_name)
    if not distro:
        flask.abort(404)

    if not is_admin():
        flask.abort(401)

    form = anitya.forms.ConfirmationForm()

    if form.validate_on_submit():
        anitya.log(SESSION,
                   distro=distro,
                   topic='distro.remove',
                   message=dict(
                       agent=flask.g.auth.openid,
                       distro=distro.name,
                   ))

        SESSION.delete(distro)
        SESSION.commit()
        flask.flash('Distro %s has been removed' % distro_name)
        return flask.redirect(flask.url_for('distros'))

    return flask.render_template('distro_delete.html',
                                 current='distros',
                                 distro=distro,
                                 form=form)
Ejemplo n.º 4
0
def add_distro():

    if not is_admin():
        flask.abort(401)

    form = anitya.forms.DistroForm()

    if form.validate_on_submit():
        name = form.name.data

        distro = anitya.lib.model.Distro(name)

        anitya.log(SESSION,
                   distro=distro,
                   topic='distro.add',
                   message=dict(
                       agent=flask.g.auth.openid,
                       distro=distro.name,
                   ))

        try:
            SESSION.add(distro)
            SESSION.commit()
            flask.flash('Distribution added')
        except SQLAlchemyError as err:
            flask.flash('Could not add this distro, already exists?', 'error')
        return flask.redirect(flask.url_for('distros'))

    return flask.render_template('distro_add.html',
                                 current='distros',
                                 form=form)
Ejemplo n.º 5
0
def new_project():

    plugins = anitya.lib.plugins.load_plugins(SESSION)
    plg_names = [plugin.name for plugin in plugins]
    form = anitya.forms.ProjectForm(backends=plg_names)

    if flask.request.method == 'GET':
        form.name.data = flask.request.args.get('name', '')
        form.homepage.data = flask.request.args.get('homepage', '')
        form.backend.data = flask.request.args.get('backend', '')

        form.distro.data = flask.request.args.get('distro', '')
        form.package_name.data = flask.request.args.get('package_name', '')

    if form.validate_on_submit():
        project = None
        try:
            project = anitya.lib.create_project(
                SESSION,
                name=form.name.data.strip(),
                homepage=form.homepage.data.strip(),
                backend=form.backend.data.strip(),
                version_url=form.version_url.data.strip() or None,
                version_prefix=form.version_prefix.data.strip() or None,
                regex=form.regex.data.strip() or None,
                user_id=flask.g.auth.openid,
                check_release=form.check_release.data,
            )
            SESSION.commit()

            # Optionally, the user can also map a distro when creating a proj.
            if form.distro.data and form.package_name.data:
                anitya.lib.map_project(
                    SESSION,
                    project=project,
                    package_name=form.package_name.data,
                    distribution=form.distro.data,
                    user_id=flask.g.auth.openid,
                )
                SESSION.commit()

            flask.flash('Project created')
        except anitya.lib.exceptions.AnityaException as err:
            flask.flash(err)

        if project:
            return flask.redirect(
                flask.url_for('project', project_id=project.id)
            )

    return flask.render_template(
        'project_new.html',
        context='Add',
        current='Add projects',
        form=form,
        plugins=plugins,
    )
Ejemplo n.º 6
0
def new_project():

    plugins = anitya.lib.plugins.load_plugins(SESSION)
    plg_names = [plugin.name for plugin in plugins]
    form = anitya.forms.ProjectForm(backends=plg_names)

    if flask.request.method == 'GET':
        form.name.data = flask.request.args.get('name', '')
        form.homepage.data = flask.request.args.get('homepage', '')
        form.backend.data = flask.request.args.get('backend', '')

        form.distro.data = flask.request.args.get('distro', '')
        form.package_name.data = flask.request.args.get('package_name', '')

    if form.validate_on_submit():
        project = None
        try:
            project = anitya.lib.create_project(
                SESSION,
                name=form.name.data.strip(),
                homepage=form.homepage.data.strip(),
                backend=form.backend.data.strip(),
                version_url=form.version_url.data.strip() or None,
                version_prefix=form.version_prefix.data.strip() or None,
                regex=form.regex.data.strip() or None,
                user_id=flask.g.auth.openid,
                check_release=form.check_release.data,
            )
            SESSION.commit()

            # Optionally, the user can also map a distro when creating a proj.
            if form.distro.data and form.package_name.data:
                anitya.lib.map_project(
                    SESSION,
                    project=project,
                    package_name=form.package_name.data,
                    distribution=form.distro.data,
                    user_id=flask.g.auth.openid,
                )
                SESSION.commit()

            flask.flash('Project created')
        except anitya.lib.exceptions.AnityaException as err:
            flask.flash(err)

        if project:
            return flask.redirect(
                flask.url_for('project', project_id=project.id))

    return flask.render_template(
        'project_new.html',
        context='Add',
        current='Add projects',
        form=form,
        plugins=plugins,
    )
Ejemplo n.º 7
0
def delete_project_version(project_id, version):

    project = anitya.lib.model.Project.get(SESSION, project_id)
    if not project:
        flask.abort(404)

    version_obj = None
    for vers in project.versions_obj:
        if version == vers.version:
            version_obj = vers
            break

    if version_obj is None:
        flask.abort(
            404,
            'Version %s not found for project %s' % (version, project.name)
        )

    if not is_admin():
        flask.abort(401)

    form = anitya.forms.ConfirmationForm()
    confirm = flask.request.form.get('confirm', False)

    if form.validate_on_submit():
        if confirm:
            anitya.log(
                SESSION,
                project=project,
                topic='project.version.remove',
                message=dict(
                    agent=flask.g.auth.openid,
                    project=project.name,
                    version=version,
                )
            )

            # Delete the record of the version for this project
            SESSION.delete(version_obj)
            # Adjust the latest_version if needed
            if project.latest_version == version:
                project.latest_version = None
                SESSION.add(project)
            SESSION.commit()

            flask.flash('Version for %s has been removed' % version)
        return flask.redirect(
            flask.url_for('project', project_id=project.id))

    return flask.render_template(
        'version_delete.html',
        current='projects',
        project=project,
        version=version,
        form=form)
Ejemplo n.º 8
0
def delete_project_version(project_id, version):

    project = anitya.lib.model.Project.get(SESSION, project_id)
    if not project:
        flask.abort(404)

    version_obj = None
    for vers in project.versions_obj:
        if version == vers.version:
            version_obj = vers
            break

    if version_obj is None:
        flask.abort(
            404,
            'Version %s not found for project %s' % (version, project.name)
        )

    if not is_admin():
        flask.abort(401)

    form = anitya.forms.ConfirmationForm()
    confirm = flask.request.form.get('confirm', False)

    if form.validate_on_submit():
        if confirm:
            anitya.log(
                SESSION,
                project=project,
                topic='project.version.remove',
                message=dict(
                    agent=flask.g.auth.openid,
                    project=project.name,
                    version=version,
                )
            )

            # Delete the record of the version for this project
            SESSION.delete(version_obj)
            # Adjust the latest_version if needed
            if project.latest_version == version:
                project.latest_version = None
                SESSION.add(project)
            SESSION.commit()

            flask.flash('Version for %s has been removed' % version)
        return flask.redirect(
            flask.url_for('project', project_id=project.id))

    return flask.render_template(
        'version_delete.html',
        current='projects',
        project=project,
        version=version,
        form=form)
Ejemplo n.º 9
0
def delete_project_mapping(project_id, distro_name, pkg_name):

    project = anitya.lib.model.Project.get(SESSION, project_id)
    if not project:
        flask.abort(404)

    distro = anitya.lib.model.Distro.get(SESSION, distro_name)
    if not distro:
        flask.abort(404)

    package = anitya.lib.model.Packages.get(
        SESSION, project.id, distro.name, pkg_name)
    if not package:
        flask.abort(404)

    if not is_admin():
        flask.abort(401)

    form = anitya.forms.ConfirmationForm()
    confirm = flask.request.form.get('confirm', False)

    if form.validate_on_submit():
        if confirm:
            anitya.log(
                SESSION,
                project=project,
                topic='project.map.remove',
                message=dict(
                    agent=flask.g.auth.openid,
                    project=project.name,
                    distro=distro.name,
                )
            )

            SESSION.delete(package)
            SESSION.commit()

            flask.flash('Mapping for %s has been removed' % project.name)
        return flask.redirect(
            flask.url_for('project', project_id=project.id))

    return flask.render_template(
        'regex_delete.html',
        current='projects',
        project=project,
        package=package,
        form=form)
Ejemplo n.º 10
0
def delete_project_mapping(project_id, distro_name, pkg_name):

    project = anitya.lib.model.Project.get(SESSION, project_id)
    if not project:
        flask.abort(404)

    distro = anitya.lib.model.Distro.get(SESSION, distro_name)
    if not distro:
        flask.abort(404)

    package = anitya.lib.model.Packages.get(
        SESSION, project.id, distro.name, pkg_name)
    if not package:
        flask.abort(404)

    if not is_admin():
        flask.abort(401)

    form = anitya.forms.ConfirmationForm()
    confirm = flask.request.form.get('confirm', False)

    if form.validate_on_submit():
        if confirm:
            anitya.log(
                SESSION,
                project=project,
                topic='project.map.remove',
                message=dict(
                    agent=flask.g.auth.openid,
                    project=project.name,
                    distro=distro.name,
                )
            )

            SESSION.delete(package)
            SESSION.commit()

            flask.flash('Mapping for %s has been removed' % project.name)
        return flask.redirect(
            flask.url_for('project', project_id=project.id))

    return flask.render_template(
        'regex_delete.html',
        current='projects',
        project=project,
        package=package,
        form=form)
Ejemplo n.º 11
0
def edit_project_mapping(project_id, pkg_id):

    project = anitya.lib.model.Project.get(SESSION, project_id)
    if not project:
        flask.abort(404)

    package = anitya.lib.model.Packages.by_id(SESSION, pkg_id)
    if not package:
        flask.abort(404)

    form = anitya.forms.MappingForm(obj=package)

    if form.validate_on_submit():

        try:
            anitya.lib.map_project(
                SESSION,
                project=project,
                package_name=form.package_name.data,
                distribution=form.distro.data,
                user_id=flask.g.auth.openid,
                old_package_name=package.package_name,
                old_distro_name=package.distro,
            )

            SESSION.commit()
            flask.flash('Mapping edited')
        except anitya.lib.exceptions.AnityaInvalidMappingException as err:
            err.link = flask.url_for('project', project_id=err.project_id)
            flask.flash(err.message, 'error')
        except anitya.lib.exceptions.AnityaException as err:
            flask.flash(str(err), 'error')

        return flask.redirect(
            flask.url_for('project', project_id=project_id))

    return flask.render_template(
        'mapping.html',
        current='projects',
        project=project,
        package=package,
        form=form,
    )
Ejemplo n.º 12
0
def delete_project(project_id):

    project = anitya.lib.model.Project.get(SESSION, project_id)
    if not project:
        flask.abort(404)

    if not is_admin():
        flask.abort(401)

    project_name = project.name

    form = anitya.forms.ConfirmationForm()
    confirm = flask.request.form.get('confirm', False)

    if form.validate_on_submit():
        if confirm:
            anitya.log(
                SESSION,
                project=project,
                topic='project.remove',
                message=dict(
                    agent=flask.g.auth.openid,
                    project=project.name,
                )
            )

            for version in project.versions_obj:
                SESSION.delete(version)

            SESSION.delete(project)
            SESSION.commit()
            flask.flash('Project %s has been removed' % project_name)
            return flask.redirect(flask.url_for('projects'))
        else:
            return flask.redirect(
                flask.url_for('project', project_id=project.id))

    return flask.render_template(
        'project_delete.html',
        current='projects',
        project=project,
        form=form)
Ejemplo n.º 13
0
def delete_project(project_id):

    project = anitya.lib.model.Project.get(SESSION, project_id)
    if not project:
        flask.abort(404)

    if not is_admin():
        flask.abort(401)

    project_name = project.name

    form = anitya.forms.ConfirmationForm()
    confirm = flask.request.form.get('confirm', False)

    if form.validate_on_submit():
        if confirm:
            anitya.log(
                SESSION,
                project=project,
                topic='project.remove',
                message=dict(
                    agent=flask.g.auth.openid,
                    project=project.name,
                )
            )

            for version in project.versions_obj:
                SESSION.delete(version)

            SESSION.delete(project)
            SESSION.commit()
            flask.flash('Project %s has been removed' % project_name)
            return flask.redirect(flask.url_for('projects'))
        else:
            return flask.redirect(
                flask.url_for('project', project_id=project.id))

    return flask.render_template(
        'project_delete.html',
        current='projects',
        project=project,
        form=form)
Ejemplo n.º 14
0
def edit_project_mapping(project_id, pkg_id):

    project = anitya.lib.model.Project.get(SESSION, project_id)
    if not project:
        flask.abort(404)

    package = anitya.lib.model.Packages.by_id(SESSION, pkg_id)
    if not package:
        flask.abort(404)

    form = anitya.forms.MappingForm(obj=package)

    if form.validate_on_submit():

        try:
            anitya.lib.map_project(
                SESSION,
                project=project,
                package_name=form.package_name.data,
                distribution=form.distro.data,
                user_id=flask.g.auth.openid,
                old_package_name=package.package_name,
                old_distro_name=package.distro,
            )

            SESSION.commit()
            flask.flash('Mapping edited')
        except anitya.lib.exceptions.AnityaInvalidMappingException as err:
            err.link = flask.url_for('project', project_id=err.project_id)
            flask.flash(err.message, 'error')
        except anitya.lib.exceptions.AnityaException as err:
            flask.flash(str(err), 'error')

        return flask.redirect(flask.url_for('project', project_id=project_id))

    return flask.render_template(
        'mapping.html',
        current='projects',
        project=project,
        package=package,
        form=form,
    )
Ejemplo n.º 15
0
def edit_distro(distro_name):

    distro = anitya.lib.model.Distro.by_name(SESSION, distro_name)
    if not distro:
        flask.abort(404)

    if not is_admin():
        flask.abort(401)

    form = anitya.forms.DistroForm(obj=distro)

    if form.validate_on_submit():
        name = form.name.data

        if name != distro.name:
            anitya.log(
                SESSION,
                distro=distro,
                topic='distro.edit',
                message=dict(
                    agent=flask.g.auth.openid,
                    old=distro.name,
                    new=name,
                )
            )

            distro.name = name

            SESSION.add(distro)
            SESSION.commit()
            message = 'Distribution edited'
            flask.flash(message)
        return flask.redirect(
            flask.url_for('distros')
        )

    return flask.render_template(
        'distro_edit.html',
        current='distros',
        distro=distro,
        form=form)
Ejemplo n.º 16
0
def edit_distro(distro_name):

    distro = anitya.lib.model.Distro.by_name(SESSION, distro_name)
    if not distro:
        flask.abort(404)

    if not is_admin():
        flask.abort(401)

    form = anitya.forms.DistroForm(obj=distro)

    if form.validate_on_submit():
        name = form.name.data

        if name != distro.name:
            anitya.log(
                SESSION,
                distro=distro,
                topic='distro.edit',
                message=dict(
                    agent=flask.g.auth.openid,
                    old=distro.name,
                    new=name,
                )
            )

            distro.name = name

            SESSION.add(distro)
            SESSION.commit()
            message = 'Distribution edited'
            flask.flash(message)
        return flask.redirect(
            flask.url_for('distros')
        )

    return flask.render_template(
        'distro_edit.html',
        current='distros',
        distro=distro,
        form=form)
Ejemplo n.º 17
0
def map_project(project_id):

    project = anitya.lib.model.Project.get(SESSION, project_id)
    if not project:
        flask.abort(404)

    form = anitya.forms.MappingForm()

    if flask.request.method == 'GET':
        form.package_name.data = flask.request.args.get(
            'package_name', project.name)
        form.distro.data = flask.request.args.get('distro', '')

    if form.validate_on_submit():
        try:
            anitya.lib.map_project(
                SESSION,
                project=project,
                package_name=form.package_name.data.strip(),
                distribution=form.distro.data.strip(),
                user_id=flask.g.auth.openid,
            )
            SESSION.commit()
            flask.flash('Mapping added')
        except anitya.lib.exceptions.AnityaInvalidMappingException as err:
            err.link = flask.url_for('project', project_id=err.project_id)
            flask.flash(err.message, 'error')
        except anitya.lib.exceptions.AnityaException as err:
            flask.flash(str(err), 'error')

        return flask.redirect(
            flask.url_for('project', project_id=project.id)
        )

    return flask.render_template(
        'mapping.html',
        current='projects',
        project=project,
        form=form,
    )
Ejemplo n.º 18
0
def map_project(project_id):

    project = anitya.lib.model.Project.get(SESSION, project_id)
    if not project:
        flask.abort(404)

    form = anitya.forms.MappingForm()

    if flask.request.method == 'GET':
        form.package_name.data = flask.request.args.get(
            'package_name', project.name)
        form.distro.data = flask.request.args.get('distro', '')

    if form.validate_on_submit():
        try:
            anitya.lib.map_project(
                SESSION,
                project=project,
                package_name=form.package_name.data.strip(),
                distribution=form.distro.data.strip(),
                user_id=flask.g.auth.openid,
            )
            SESSION.commit()
            flask.flash('Mapping added')
        except anitya.lib.exceptions.AnityaInvalidMappingException as err:
            err.link = flask.url_for('project', project_id=err.project_id)
            flask.flash(err.message, 'error')
        except anitya.lib.exceptions.AnityaException as err:
            flask.flash(str(err), 'error')

        return flask.redirect(flask.url_for('project', project_id=project.id))

    return flask.render_template(
        'mapping.html',
        current='projects',
        project=project,
        form=form,
    )
Ejemplo n.º 19
0
def add_distro():

    if not is_admin():
        flask.abort(401)

    form = anitya.forms.DistroForm()

    if form.validate_on_submit():
        name = form.name.data

        distro = anitya.lib.model.Distro(name)

        anitya.log(
            SESSION,
            distro=distro,
            topic='distro.add',
            message=dict(
                agent=flask.g.auth.openid,
                distro=distro.name,
            )
        )

        try:
            SESSION.add(distro)
            SESSION.commit()
            flask.flash('Distribution added')
        except SQLAlchemyError as err:
            flask.flash(
                'Could not add this distro, already exists?', 'error')
        return flask.redirect(
            flask.url_for('distros')
        )

    return flask.render_template(
        'distro_add.html',
        current='distros',
        form=form)
Ejemplo n.º 20
0
    def post(self):
        """
        Create a new project.

        **Example Request**:

        .. sourcecode:: http

            POST /api/v2/projects/?access_token=MYAPIACCESSTOKEN HTTP/1.1
            Accept: application/json
            Accept-Encoding: gzip, deflate
            Connection: keep-alive
            Content-Length: 114
            Content-Type: application/json
            Host: localhost:5000
            User-Agent: HTTPie/0.9.4

            {
                "backend": "custom",
                "homepage": "http://example.com/test",
                "name": "test_project",
                "version_prefix": "release-"
            }


        **Example Response**:

        .. sourcecode:: http

            HTTP/1.0 201 CREATED
            Content-Length: 276
            Content-Type: application/json
            Date: Sun, 26 Mar 2017 15:56:30 GMT
            Server: Werkzeug/0.12.1 Python/2.7.13

            {
                "backend": "PyPI",
                "created_on": 1490543790.0,
                "homepage": "http://python-requests.org",
                "id": 13857,
                "name": "requests",
                "regex": null,
                "updated_on": 1490543790.0,
                "version": null,
                "version_url": null,
                "versions": []
            }

        :query string access_token: Your API access token.
        :reqjson string name: The project name
        :reqjson string homepage: The project homepage URL
        :reqjson string backend: The project backend (github, folder, etc.).
        :reqjson string version_url: The URL to fetch when determining the
                                     project version (defaults to null).
        :reqjson string version_prefix: The project version prefix, if any. For
                                        example, some projects prefix with "v".
        :reqjson string regex: The regex to use when searching the
                               ``version_url`` page.
        :reqjson bool insecure: When retrieving the versions via HTTPS, do not
                                validate the certificate (defaults to false).
        :reqjson bool check_release: Check the release immediately after
                                     creating the project.

        :statuscode 201: When the project was successfully created.
        :statuscode 400: When required arguments are missing or malformed.
        :statuscode 401: When your access token is missing or invalid, or when
                         the server is not configured for OpenID Connect. The
                         response will include a JSON body describing the exact
                         problem.
        :statuscode 409: When the project already exists.
        """
        name_help = _('The project name')
        homepage_help = _('The project homepage URL')
        backend_help = _('The project backend (github, folder, etc.)')
        version_url_help = _('The URL to fetch when determining the project '
                             'version (defaults to null)')
        version_prefix_help = _('The project version prefix, if any. For '
                                'example, some projects prefix with "v"')
        regex_help = _('The regex to use when searching the version_url page')
        insecure_help = _('When retrieving the versions via HTTPS, do not '
                          'validate the certificate (defaults to false)')
        check_release_help = _('Check the release immediately after creating '
                               'the project.')

        parser = _BASE_ARG_PARSER.copy()
        parser.add_argument('name', type=str, help=name_help, required=True)
        parser.add_argument('homepage',
                            type=str,
                            help=homepage_help,
                            required=True)
        parser.add_argument('backend',
                            type=str,
                            help=backend_help,
                            required=True)
        parser.add_argument('version_url',
                            type=str,
                            help=version_url_help,
                            default=None)
        parser.add_argument('version_prefix',
                            type=str,
                            help=version_prefix_help,
                            default=None)
        parser.add_argument('regex', type=str, help=regex_help, default=None)
        parser.add_argument('insecure',
                            type=bool,
                            help=insecure_help,
                            default=False)
        parser.add_argument('check_release',
                            type=bool,
                            help=check_release_help)
        args = parser.parse_args(strict=True)
        access_token = args.pop('access_token')

        try:
            project = anitya.lib.create_project(SESSION,
                                                user_id=APP.oidc.user_getfield(
                                                    'email', access_token),
                                                **args)
            SESSION.commit()
            return project.__json__(), 201
        except ProjectExists as e:
            response = jsonify(e.to_dict())
            response.status_code = 409
            return response