예제 #1
0
파일: api.py 프로젝트: cicku/anitya
def api_get_version():

    project_id = flask.request.form.get('id', None)
    httpcode = 200

    if not project_id:
        errors = []
        if not project_id:
            errors.append('No project id specified')
        output = {'output': 'notok', 'error': errors}
        httpcode = 400
    else:

        project = anitya.lib.model.Project.get(
            SESSION, project_id=project_id)

        if not project:
            output = {'output': 'notok', 'error': 'No such project'}
            httpcode = 404
        else:
            try:
                anitya.check_release(project, SESSION)
                output = project.__json__()
            except anitya.lib.exceptions.AnityaException as err:
                output = {'output': 'notok', 'error': [str(err)]}
                httpcode = 400

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout
예제 #2
0
def update_project(project_id):
    """ Check for updates on the specified project. """
    session = anitya.lib.init(anitya.app.APP.config['DB_URL'])
    project = anitya.lib.model.Project.by_id(session, project_id)
    try:
        anitya.check_release(project, session),
    except anitya.lib.exceptions.AnityaException as err:
        LOG.info(err)
    finally:
        session.get_bind().dispose()
        session.remove()
예제 #3
0
def update_project(project_id):
    """ Check for updates on the specified project. """
    session = anitya.lib.init(anitya.app.APP.config['DB_URL'])
    project = anitya.lib.model.Project.by_id(session, project_id)
    try:
        anitya.check_release(project, session),
    except anitya.lib.exceptions.AnityaException as err:
        LOG.info(err)
    finally:
        session.get_bind().dispose()
        session.remove()
예제 #4
0
def create_project(session,
                   name,
                   homepage,
                   user_id,
                   backend='custom',
                   version_url=None,
                   version_prefix=None,
                   regex=None,
                   check_release=False,
                   insecure=False):
    """ Create the project in the database.

    """
    # Set the ecosystem if there's one associated with the given backend
    ecosystems = [
        e for e in anitya.lib.plugins.ECOSYSTEM_PLUGINS.get_plugins()
        if e.default_backend == backend
    ]
    ecosystem_name = ecosystems[0].name if len(ecosystems) == 1 else None

    project = anitya.lib.model.Project(name=name,
                                       homepage=homepage,
                                       backend=backend,
                                       ecosystem_name=ecosystem_name,
                                       version_url=version_url,
                                       regex=regex,
                                       version_prefix=version_prefix,
                                       insecure=insecure)

    session.add(project)

    try:
        session.flush()
    except IntegrityError:
        session.rollback()
        raise anitya.lib.exceptions.ProjectExists(project)
    except SQLAlchemyError as err:
        _log.exception(err)
        session.rollback()
        raise anitya.lib.exceptions.AnityaException(
            'Could not add this project, already exists?')

    anitya.log(session,
               project=project,
               topic='project.add',
               message=dict(
                   agent=user_id,
                   project=project.name,
               ))
    session.commit()
    if check_release is True:
        anitya.check_release(project, session)
    return project
예제 #5
0
파일: __init__.py 프로젝트: msimacek/anitya
def create_project(
        session, name, homepage, user_id, backend='custom',
        version_url=None, version_prefix=None, regex=None,
        check_release=False, insecure=False):
    """ Create the project in the database.

    """
    # Set the ecosystem if there's one associated with the given backend
    ecosystems = [e for e in anitya.lib.plugins.ECOSYSTEM_PLUGINS.get_plugins()
                  if e.default_backend == backend]
    ecosystem_name = ecosystems[0].name if len(ecosystems) == 1 else None

    project = anitya.lib.model.Project(
        name=name,
        homepage=homepage,
        backend=backend,
        ecosystem_name=ecosystem_name,
        version_url=version_url,
        regex=regex,
        version_prefix=version_prefix,
        insecure=insecure
    )

    session.add(project)

    try:
        session.flush()
    except IntegrityError:
        session.rollback()
        raise anitya.lib.exceptions.ProjectExists(project)
    except SQLAlchemyError as err:
        _log.exception(err)
        session.rollback()
        raise anitya.lib.exceptions.AnityaException(
            'Could not add this project, already exists?')

    anitya.log(
        session,
        project=project,
        topic='project.add',
        message=dict(
            agent=user_id,
            project=project.name,
        )
    )
    session.commit()
    if check_release is True:
        anitya.check_release(project, session)
    return project
예제 #6
0
def main(debug):
    ''' Retrieve all the packages and for each of them update the release
    version.
    '''
    session = anitya.app.SESSION
    LOG = logging.getLogger('anitya')
    LOG.setLevel(logging.DEBUG)

    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')

    if debug:
        # Console handler
        chand = logging.StreamHandler()
        chand.setLevel(logging.INFO)
        chand.setFormatter(formatter)
        LOG.addHandler(chand)

    # Save the logs in a file
    fhand = logging.FileHandler('/var/tmp/anitya_cron.log')
    fhand.setLevel(logging.INFO)
    fhand.setFormatter(formatter)
    LOG.addHandler(fhand)

    projects = anitya.lib.model.Project.all(session)

    if PBAR:
        widgets = ['Release update: ',
                   Percentage(),
                   ' ',
                   Bar(marker=RotatingMarker()),
                   ' ',
                   ETA()]
        pbar = ProgressBar(widgets=widgets, maxval=len(projects)).start()

    cnt = 0
    for project in projects:
        LOG.info(project.name)
        try:
            anitya.check_release(project, session)
        except anitya.lib.exceptions.AnityaException as err:
            pass
        cnt += 1
        if PBAR:
            pbar.update(cnt)
    if PBAR:
        pbar.finish()
예제 #7
0
def create_project(session,
                   name,
                   homepage,
                   user_id,
                   backend='custom',
                   version_url=None,
                   version_prefix=None,
                   regex=None,
                   check_release=False):
    """ Create the project in the database.

    """
    # Set the ecosystem if there's one associated with the given backend
    backend_ref = anitya.lib.model.Backend.by_name(session, name=backend)
    ecosystem_ref = backend_ref.default_ecosystem

    project = anitya.lib.model.Project(
        name=name,
        homepage=homepage,
        backend=backend,
        ecosystem=ecosystem_ref,
        version_url=version_url,
        regex=regex,
        version_prefix=version_prefix,
    )

    session.add(project)

    try:
        session.flush()
    except SQLAlchemyError as err:
        log.exception(err)
        session.rollback()
        raise anitya.lib.exceptions.AnityaException(
            'Could not add this project, already exists?')

    anitya.log(session,
               project=project,
               topic='project.add',
               message=dict(
                   agent=user_id,
                   project=project.name,
               ))
    session.commit()
    if check_release is True:
        anitya.check_release(project, session)
    return project
예제 #8
0
def create_project(
        session, name, homepage, user_id, backend='custom',
        version_url=None, version_prefix=None, regex=None,
        check_release=False):
    """ Create the project in the database.

    """
    # Set the ecosystem if there's one associated with the given backend
    backend_ref = anitya.lib.model.Backend.by_name(session, name=backend)
    ecosystem_ref = backend_ref.default_ecosystem

    project = anitya.lib.model.Project(
        name=name,
        homepage=homepage,
        backend=backend,
        ecosystem=ecosystem_ref,
        version_url=version_url,
        regex=regex,
        version_prefix=version_prefix,
    )

    session.add(project)

    try:
        session.flush()
    except SQLAlchemyError as err:
        log.exception(err)
        session.rollback()
        raise anitya.lib.exceptions.AnityaException(
            'Could not add this project, already exists?')

    anitya.log(
        session,
        project=project,
        topic='project.add',
        message=dict(
            agent=user_id,
            project=project.name,
        )
    )
    session.commit()
    if check_release is True:
        anitya.check_release(project, session)
    return project
예제 #9
0
def api_get_version():
    '''
    Retrieve version
    ----------------
    Forces anitya to retrieve the latest version available from a project
    upstream.

    ::

        /api/version/get

    Accepts POST queries only.

    :arg id: the identifier of the project in anitya.

    Sample response:

    ::

      {
        "backend": "Sourceforge",
        "created_on": 1409917222.0,
        "homepage": "http://sourceforge.net/projects/zero-install",
        "id": 1,
        "name": "zero-install",
        "packages": [
          {
            "distro": "Fedora",
            "package_name": "0install"
          }
        ],
        "regex": "",
        "updated_on": 1413794215.0,
        "version": "2.7",
        "version_url": "0install",
        "versions": [
          "2.7"
        ]
      }

    '''

    project_id = flask.request.form.get('id', None)
    test = flask.request.form.get('test', False)
    httpcode = 200

    if not project_id:
        errors = []
        if not project_id:
            errors.append('No project id specified')
        output = {'output': 'notok', 'error': errors}
        httpcode = 400
    else:

        project = anitya.lib.model.Project.get(SESSION, project_id=project_id)

        if not project:
            output = {'output': 'notok', 'error': 'No such project'}
            httpcode = 404
        else:
            try:
                version = anitya.check_release(project, SESSION, test=test)
                if version:
                    output = {'version': version}
                else:
                    output = project.__json__(detailed=True)
            except anitya.lib.exceptions.AnityaException as err:
                output = {'output': 'notok', 'error': [str(err)]}
                httpcode = 400

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout
예제 #10
0
파일: api.py 프로젝트: praveenkumar/anitya
def api_get_version():
    '''
    Retrieve version
    ----------------
    Forces anitya to retrieve the latest version available from a project
    upstream.

    ::

        /api/version/get

    Accepts POST queries only.

    :arg id: the identifier of the project in anitya.

    Sample response:

    ::

      {
        "backend": "Sourceforge",
        "created_on": 1409917222.0,
        "homepage": "http://sourceforge.net/projects/zero-install",
        "id": 1,
        "name": "zero-install",
        "packages": [
          {
            "distro": "Fedora",
            "package_name": "0install"
          }
        ],
        "regex": "",
        "updated_on": 1413794215.0,
        "version": "2.7",
        "version_url": "0install",
        "versions": [
          "2.7"
        ]
      }

    '''

    project_id = flask.request.form.get('id', None)
    httpcode = 200

    if not project_id:
        errors = []
        if not project_id:
            errors.append('No project id specified')
        output = {'output': 'notok', 'error': errors}
        httpcode = 400
    else:

        project = anitya.lib.model.Project.get(
            SESSION, project_id=project_id)

        if not project:
            output = {'output': 'notok', 'error': 'No such project'}
            httpcode = 404
        else:
            try:
                anitya.check_release(project, SESSION)
                output = project.__json__(detailed=True)
            except anitya.lib.exceptions.AnityaException as err:
                output = {'output': 'notok', 'error': [str(err)]}
                httpcode = 400

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout
예제 #11
0
def edit_project(session,
                 project,
                 name,
                 homepage,
                 backend,
                 version_url,
                 version_prefix,
                 regex,
                 insecure,
                 user_id,
                 check_release=False):
    """ Edit a project in the database.

    """
    changes = {}
    if name != project.name:
        old = project.name
        project.name = name.strip() if name else None
        changes['name'] = {'old': old, 'new': project.name}
    if homepage != project.homepage:
        old = project.homepage
        project.homepage = homepage.strip() if homepage else None
        changes['homepage'] = {'old': old, 'new': project.homepage}
    if backend != project.backend:
        old = project.backend
        project.backend = backend
        changes['backend'] = {'old': old, 'new': project.backend}
    if version_url != project.version_url:
        old = project.version_url
        project.version_url = version_url.strip() if version_url else None
        if old != project.version_url:
            changes['version_url'] = {'old': old, 'new': project.version_url}
    if version_prefix != project.version_prefix:
        old = project.version_prefix
        project.version_prefix = version_prefix.strip() \
            if version_prefix else None
        if old != project.version_prefix:
            changes['version_prefix'] = {
                'old': old,
                'new': project.version_prefix
            }
    if regex != project.regex:
        old = project.regex
        project.regex = regex.strip() if regex else None
        if old != project.regex:
            changes['regex'] = {'old': old, 'new': project.regex}
    if insecure != project.insecure:
        old = project.insecure
        project.insecure = insecure
        changes['insecure'] = {'old': old, 'new': project.insecure}

    try:
        if changes:
            anitya.log(
                session,
                project=project,
                topic='project.edit',
                message=dict(
                    agent=user_id,
                    project=project.name,
                    fields=list(changes.keys()),  # be backward compat
                    changes=changes,
                ))
            session.add(project)
            session.commit()
        if check_release is True:
            anitya.check_release(project, session)
    except SQLAlchemyError as err:
        _log.exception(err)
        session.rollback()
        raise anitya.lib.exceptions.AnityaException(
            'Could not edit this project. Is there already a project '
            'with these name and homepage?')
예제 #12
0
def edit_project(
        session, project, name, homepage, backend, version_url,
        version_prefix, regex, insecure, user_id, check_release=False):
    """ Edit a project in the database.

    """
    changes = {}
    if name != project.name:
        old = project.name
        project.name = name.strip() if name else None
        changes['name'] = {'old': old, 'new': project.name}
    if homepage != project.homepage:
        old = project.homepage
        project.homepage = homepage.strip() if homepage else None
        changes['homepage'] = {'old': old, 'new': project.homepage}
    if backend != project.backend:
        old = project.backend
        project.backend = backend
        changes['backend'] = {'old': old, 'new': project.backend}
    if  version_url != project.version_url:
        old = project.version_url
        project.version_url = version_url.strip() if version_url else None
        if old != project.version_url:
            changes['version_url'] = {'old': old, 'new': project.version_url}
    if  version_prefix != project.version_prefix:
        old = project.version_prefix
        project.version_prefix = version_prefix.strip() if version_prefix else None
        if old != project.version_prefix:
            changes['version_prefix'] = {
                'old': old, 'new': project.version_prefix}
    if regex != project.regex:
        old = project.regex
        project.regex = regex.strip() if regex else None
        if old != project.regex:
            changes['regex'] = {'old': old, 'new': project.regex}
    if insecure != project.insecure:
        old = project.insecure
        project.insecure = insecure
        changes['insecure'] = {'old': old, 'new': project.insecure}

    try:
        if changes:
            anitya.log(
                session,
                project=project,
                topic='project.edit',
                message=dict(
                    agent=user_id,
                    project=project.name,
                    fields=list(changes.keys()),  # be backward compat
                    changes=changes,
                )
            )
            session.add(project)
            session.commit()
        if check_release is True:
            anitya.check_release(project, session)
    except SQLAlchemyError as err:
        log.exception(err)
        session.rollback()
        raise anitya.lib.exceptions.AnityaException(
            'Could not edit this project. Is there already a project '
            'with these name and homepage?')