Exemple #1
0
def list_collections(motif=None, page=1):
    ''' Display the list of collections corresponding to the motif. '''

    pattern = flask.request.args.get('motif', motif) or '*'
    limit = flask.request.args.get('limit', APP.config['ITEMS_PER_PAGE'])

    try:
        int(limit)
    except ValueError:
        limit = APP.config['ITEMS_PER_PAGE']
        flask.flash('Incorrect limit provided, using default', 'errors')

    collections = pkgdblib.search_collection(
        SESSION,
        pattern=pattern,
        page=page,
        limit=limit,
    )
    collections_count = pkgdblib.search_collection(
        SESSION,
        pattern=pattern,
        page=page,
        limit=limit,
        count=True
    )
    total_page = int(ceil(collections_count / float(limit)))

    return flask.render_template(
        'list_collections.html',
        collections=collections,
        motif=motif,
        total_page=total_page,
        page=page
    )
Exemple #2
0
def list_collections(motif=None, page=1):
    ''' Display the list of collections corresponding to the motif. '''

    pattern = flask.request.args.get('motif', motif) or '*'
    limit = flask.request.args.get('limit', APP.config['ITEMS_PER_PAGE'])

    try:
        int(limit)
    except ValueError:
        limit = APP.config['ITEMS_PER_PAGE']
        flask.flash('Incorrect limit provided, using default', 'errors')

    collections = pkgdblib.search_collection(
        SESSION,
        pattern=pattern,
        page=page,
        limit=limit,
    )
    collections_count = pkgdblib.search_collection(SESSION,
                                                   pattern=pattern,
                                                   page=page,
                                                   limit=limit,
                                                   count=True)
    total_page = int(ceil(collections_count / float(limit)))

    return flask.render_template('list_collections.html',
                                 collections=collections,
                                 motif=motif,
                                 total_page=total_page,
                                 page=page)
Exemple #3
0
def stats():
    ''' Display some statistics aboue the packages in the DB. '''
    collections = pkgdblib.search_collection(SESSION, '*', 'Active')
    collections.extend(pkgdblib.search_collection(
        SESSION, '*', 'Under Development'))

    packages = {}
    for collection in collections:
        packages_count = pkgdblib.search_package(
            SESSION,
            pkg_name='*',
            clt_name=collection.branchname,
            count=True
        )
        packages[collection.branchname] = packages_count

    # Top maintainers
    top_maintainers = pkgdblib.get_top_maintainers(SESSION)
    # Top point of contact
    top_poc = pkgdblib.get_top_poc(SESSION)

    return flask.render_template(
        'stats.html',
        packages=packages,
        top_maintainers=top_maintainers,
        top_poc=top_poc,
    )
Exemple #4
0
def api_collection_list(pattern=None):
    ''' List collections.

    :arg pattern: a pattern to which the collection searched should match.
    :arg status: restrict the search to certain status.

    '''
    httpcode = 200
    output = {}

    pattern = flask.request.args.get('pattern', None) or pattern
    status = flask.request.args.get('status', None)
    if pattern:
        collections = pkgdblib.search_collection(SESSION,
                                                 pattern=pattern,
                                                 status=status
                                                 )
    else:
        collections = model.Collection.all(SESSION)
    output = {'collections':
              [collec.api_repr(1) for collec in collections]
              }

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout
    def test_search_collection(self):
        """ Test the search_collection function. """
        create_collection(self.session)

        collections = pkgdblib.search_collection(self.session, 'EPEL*')
        self.assertEqual(len(collections), 0)

        collections = pkgdblib.search_collection(self.session, 'F-*',
                                                 status='EOL')
        self.assertEqual(len(collections), 0)

        collections = pkgdblib.search_collection(self.session, 'F-*')
        self.assertEqual(len(collections), 2)
        self.assertEqual("Collection(u'Fedora', u'17', u'Active', u'toshio', "
                         "publishurltemplate=None, pendingurltemplate=None,"
                         " summary=u'Fedora 17 release', description=None)",
                         collections[0].__repr__())

        collections = pkgdblib.search_collection(
            self.session,
            'F-*',
            limit=1)
        self.assertEqual(len(collections), 1)

        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.search_collection,
                          self.session,
                          'F-*',
                          limit='a'
                          )

        collections = pkgdblib.search_collection(
            self.session,
            'F-*',
            limit=1,
            page=2)
        self.assertEqual(len(collections), 1)

        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.search_collection,
                          self.session,
                          'F-*',
                          page='a'
                          )
Exemple #6
0
def stats():
    ''' Display some statistics aboue the packages in the DB. '''
    collections = pkgdblib.search_collection(SESSION, '*', 'Active')
    collections.extend(pkgdblib.search_collection(
        SESSION, '*', 'Under Development'))

    collections = pkgdblib.count_collection(SESSION)

    # Top maintainers
    top_maintainers = pkgdblib.get_top_maintainers(SESSION)
    # Top point of contact
    top_poc = pkgdblib.get_top_poc(SESSION)

    return flask.render_template(
        'stats.html',
        collections=collections,
        top_maintainers=top_maintainers,
        top_poc=top_poc,
    )
Exemple #7
0
    def test_search_collection(self):
        """ Test the search_collection function. """
        create_collection(self.session)

        collections = pkgdblib.search_collection(self.session, 'EPEL*')
        self.assertEqual(len(collections), 0)

        collections = pkgdblib.search_collection(self.session,
                                                 'F-*',
                                                 status='EOL')
        self.assertEqual(len(collections), 0)

        collections = pkgdblib.search_collection(self.session, 'F-*')
        self.assertEqual(len(collections), 2)
        self.assertEqual(
            "Collection(u'Fedora', u'17', u'Active', u'toshio', "
            "publishurltemplate=None, pendingurltemplate=None,"
            " summary=u'Fedora 17 release', description=None)",
            collections[0].__repr__())

        collections = pkgdblib.search_collection(self.session, 'F-*', limit=1)
        self.assertEqual(len(collections), 1)

        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.search_collection,
                          self.session,
                          'F-*',
                          limit='a')

        collections = pkgdblib.search_collection(self.session,
                                                 'F-*',
                                                 limit=1,
                                                 page=2)
        self.assertEqual(len(collections), 1)

        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.search_collection,
                          self.session,
                          'F-*',
                          page='a')
Exemple #8
0
def collection_edit(collection):
    ''' Allows to edit the information about the specified collection. '''

    collections = []
    try:
        collection = pkgdblib.search_collection(SESSION, collection)[0]
    except NoResultFound:
        SESSION.rollback()
    except IndexError:
        flask.flash('No collection of this name found.', 'errors')
        return flask.render_template('msg.html')

    clt_status = pkgdb.lib.get_status(SESSION, 'clt_status')['clt_status']
    form = pkgdb.forms.AddCollectionForm(
        clt_status=clt_status
    )

    if form.validate_on_submit():
        clt_name = form.collection_name.data
        clt_version = form.collection_version.data
        clt_status = form.collection_status.data
        clt_publishurl = form.collection_publishURLTemplate.data
        clt_pendingurl = form.collection_pendingURLTemplate.data
        clt_summary = form.collection_summary.data
        clt_description = form.collection_description.data
        clt_branchname = form.collection_branchname.data
        clt_disttag = form.collection_distTag.data
        clt_gitbranch = form.collection_git_branch_name.data

        try:
            pkgdblib.edit_collection(
                SESSION,
                collection=collection,
                clt_name=clt_name,
                clt_version=clt_version,
                clt_status=clt_status,
                clt_publishurl=clt_publishurl,
                clt_pendingurl=clt_pendingurl,
                clt_summary=clt_summary,
                clt_description=clt_description,
                clt_branchname=clt_branchname,
                clt_disttag=clt_disttag,
                clt_gitbranch=clt_gitbranch,
                user=flask.g.fas_user,
            )
            SESSION.commit()
            flask.flash('Collection "%s" edited' % clt_name)
            return flask.redirect(flask.url_for(
                '.collection_info', collection=collection.branchname))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'errors')
Exemple #9
0
def collection_info(collection):
    ''' Display the information about the specified collection. '''

    try:
        collection = pkgdblib.search_collection(SESSION, collection)[0]
    except IndexError:
        flask.flash('No collection of this name found.', 'errors')
        return flask.render_template('msg.html')

    return flask.render_template(
        'collection.html',
        collection=collection,
    )
Exemple #10
0
    def test_edit_collection(self):
        """ Test the edit_collection function. """
        create_collection(self.session)

        collection = pkgdblib.search_collection(self.session, 'F-18')[0]

        out = pkgdblib.edit_collection(self.session, collection,
                                       user=FakeFasUserAdmin())
        self.assertEqual(out, None)

        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.edit_collection,
                          self.session,
                          collection)

        out = pkgdblib.edit_collection(
            self.session,
            collection,
            clt_name='Fedora youhou!',
            clt_version='Awesome 18',
            clt_status='EOL',
            clt_publishurl='http://.....',
            clt_pendingurl='http://.....',
            clt_summary='Fedora awesome release 18',
            clt_description='This is a description of how cool Fedora is',
            clt_branchname='f18_b',
            clt_disttag='fc18',
            clt_gitbranch='F-18',
            user=FakeFasUserAdmin(),
            )

        self.assertEqual(out, 'Collection "f18_b" edited')

        collections = pkgdblib.search_collection(self.session, 'F-18')
        self.assertEqual(collections, [])

        collection = pkgdblib.search_collection(self.session, 'f18_b')[0]
        self.assertEqual(collection.name, 'Fedora youhou!')
        self.assertEqual(collection.status, 'EOL')
Exemple #11
0
def collection_edit(collection):
    ''' Allows to edit the information about the specified collection. '''

    collections = []
    try:
        collection = pkgdblib.search_collection(SESSION, collection)[0]
    except NoResultFound:
        SESSION.rollback()
    except IndexError:
        flask.flash('No collection of this name found.', 'errors')
        return flask.render_template('msg.html')

    clt_status = pkgdb.lib.get_status(SESSION, 'clt_status')['clt_status']
    form = pkgdb.forms.AddCollectionForm(clt_status=clt_status)

    if form.validate_on_submit():
        clt_name = form.collection_name.data
        clt_version = form.collection_version.data
        clt_status = form.collection_status.data
        clt_publishurl = form.collection_publishURLTemplate.data
        clt_pendingurl = form.collection_pendingURLTemplate.data
        clt_summary = form.collection_summary.data
        clt_description = form.collection_description.data
        clt_branchname = form.collection_branchname.data
        clt_disttag = form.collection_distTag.data
        clt_gitbranch = form.collection_git_branch_name.data

        try:
            pkgdblib.edit_collection(
                SESSION,
                collection=collection,
                clt_name=clt_name,
                clt_version=clt_version,
                clt_status=clt_status,
                clt_publishurl=clt_publishurl,
                clt_pendingurl=clt_pendingurl,
                clt_summary=clt_summary,
                clt_description=clt_description,
                clt_branchname=clt_branchname,
                clt_disttag=clt_disttag,
                clt_gitbranch=clt_gitbranch,
                user=flask.g.fas_user,
            )
            SESSION.commit()
            flask.flash('Collection "%s" edited' % clt_name)
            return flask.redirect(
                flask.url_for('.collection_info',
                              collection=collection.branchname))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'errors')
Exemple #12
0
    def test_edit_collection(self):
        """ Test the edit_collection function. """
        create_collection(self.session)

        collection = pkgdblib.search_collection(self.session, 'F-18')[0]

        out = pkgdblib.edit_collection(self.session,
                                       collection,
                                       user=FakeFasUserAdmin())
        self.assertEqual(out, None)

        self.assertRaises(pkgdblib.PkgdbException, pkgdblib.edit_collection,
                          self.session, collection)

        out = pkgdblib.edit_collection(
            self.session,
            collection,
            clt_name='Fedora youhou!',
            clt_version='Awesome 18',
            clt_status='EOL',
            clt_publishurl='http://.....',
            clt_pendingurl='http://.....',
            clt_summary='Fedora awesome release 18',
            clt_description='This is a description of how cool Fedora is',
            clt_branchname='f18_b',
            clt_disttag='fc18',
            clt_gitbranch='F-18',
            user=FakeFasUserAdmin(),
        )

        self.assertEqual(out, 'Collection "f18_b" edited')

        collections = pkgdblib.search_collection(self.session, 'F-18')
        self.assertEqual(collections, [])

        collection = pkgdblib.search_collection(self.session, 'f18_b')[0]
        self.assertEqual(collection.name, 'Fedora youhou!')
        self.assertEqual(collection.status, 'EOL')
Exemple #13
0
def stats():
    ''' Display some statistics aboue the packages in the DB. '''
    collections = pkgdblib.search_collection(SESSION, '*', 'Active')
    collections.extend(
        pkgdblib.search_collection(SESSION, '*', 'Under Development'))

    packages = {}
    for collection in collections:
        packages_count = pkgdblib.search_package(
            SESSION, pkg_name='*', clt_name=collection.branchname, count=True)
        packages[collection.branchname] = packages_count

    # Top maintainers
    top_maintainers = pkgdblib.get_top_maintainers(SESSION)
    # Top point of contact
    top_poc = pkgdblib.get_top_poc(SESSION)

    return flask.render_template(
        'stats.html',
        packages=packages,
        top_maintainers=top_maintainers,
        top_poc=top_poc,
    )
Exemple #14
0
def collection_info(collection):
    ''' Display the information about the specified collection. '''

    collections = []
    try:
        collection = pkgdblib.search_collection(SESSION, collection)[0]
    except NoResultFound:
        SESSION.rollback()
    except IndexError:
        flask.flash('No collection of this name found.', 'errors')
        return flask.render_template('msg.html')

    return flask.render_template(
        'collection.html',
        collection=collection,
    )
Exemple #15
0
def collection_edit(collection):
    ''' Allows to edit the information about the specified collection. '''

    try:
        collection = pkgdblib.search_collection(SESSION, collection)[0]
    except IndexError:
        flask.flash('No collection of this name found.', 'errors')
        return flask.render_template('msg.html')

    clt_status = pkgdb.lib.get_status(SESSION, 'clt_status')['clt_status']
    form = pkgdb.forms.AddCollectionForm(
        clt_status=clt_status
    )

    if form.validate_on_submit():
        clt_name = form.collection_name.data
        clt_version = form.collection_version.data
        clt_status = form.collection_status.data
        clt_branchname = form.collection_branchname.data
        clt_disttag = form.collection_distTag.data
        clt_gitbranch = form.collection_git_branch_name.data

        try:
            pkgdblib.edit_collection(
                SESSION,
                collection=collection,
                clt_name=clt_name,
                clt_version=clt_version,
                clt_status=clt_status,
                clt_branchname=clt_branchname,
                clt_disttag=clt_disttag,
                clt_gitbranch=clt_gitbranch,
                user=flask.g.fas_user,
            )
            SESSION.commit()
            flask.flash('Collection "%s" edited' % clt_branchname)
            return flask.redirect(flask.url_for(
                '.collection_info', collection=collection.branchname))
        # In theory we should never hit this
        except pkgdblib.PkgdbException, err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(err.message, 'errors')
Exemple #16
0
def api_collection_list(pattern=None):
    '''
List collections
----------------
    List the collections based on a pattern. If no pattern is provided, it
    will return all the collection.

    ::

        /api/collections/<pattern>/

        /api/collections/?pattern=<pattern>

    Accept GET queries only.

    :arg pattern: a pattern to which the collection searched should match.
    :arg status: restrict the search to certain status.

    Sample response:

    ::

        /api/collections

        {
          "collections": [
            {
              "status": "Active",
              "branchname": "f20",
              "version": "20",
              "name": "Fedora"
            },
            {
              "status": "EOL",
              "branchname": "F-17",
              "version": "17",
              "name": "Fedora"
            },
                {
              "status": "Active",
              "branchname": "EL-6",
              "version": "6",
              "name": "Fedora EPEL"
            }
          ]
        }

    ::

        /api/collections?pattern=EL*

        {
          "collections": [
            {
              "status": "EOL",
              "branchname": "EL-4",
              "version": "4",
              "name": "Fedora EPEL"
            },
            {
              "status": "Active",
              "branchname": "EL-5",
              "version": "5",
              "name": "Fedora EPEL"
            },
            {
              "status": "Active",
              "branchname": "EL-6",
              "version": "6",
              "name": "Fedora EPEL"
            }
          ]
        }
    '''
    httpcode = 200
    output = {}

    pattern = flask.request.args.get('pattern', None) or pattern
    status = flask.request.args.get('status', None)
    if pattern:
        collections = pkgdblib.search_collection(SESSION,
                                                 pattern=pattern,
                                                 status=status
                                                 )
    else:
        collections = model.Collection.all(SESSION)
    output = {'collections':
              [collec.to_json() for collec in collections]
              }

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout