コード例 #1
0
ファイル: packages.py プロジェクト: msmahmood/packagedb2
def list_packages(motif=None, orphaned=False, status='Approved',
                  origin='list_packages'):
    ''' Display the list of packages corresponding to the motif. '''

    pattern = flask.request.args.get('motif', motif) or '*'
    branches = flask.request.args.get('branches', None)
    owner = flask.request.args.get('owner', None)
    orphaned = bool(flask.request.args.get('orphaned', orphaned))
    status = flask.request.args.get('status', status)
    limit = flask.request.args.get('limit', APP.config['ITEMS_PER_PAGE'])
    page = flask.request.args.get('page', 1)

    try:
        page = int(page)
    except ValueError:
        page = 1

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

    packages = pkgdblib.search_package(
        SESSION,
        pkg_name=pattern,
        pkg_branch=branches,
        pkg_poc=owner,
        orphaned=orphaned,
        status=status,
        page=page,
        limit=limit,
    )
    packages_count = pkgdblib.search_package(
        SESSION,
        pkg_name=pattern,
        pkg_branch=branches,
        pkg_poc=owner,
        orphaned=orphaned,
        status=status,
        page=page,
        limit=limit,
        count=True
    )
    total_page = int(ceil(packages_count / float(limit)))

    return flask.render_template(
        'list_packages.html',
        origin=origin,
        packages=packages,
        motif=motif,
        total_page=total_page,
        packages_count=packages_count,
        page=page
    )
コード例 #2
0
def list_packages(motif=None):
    ''' Display the list of packages corresponding to the motif. '''

    pattern = flask.request.args.get('motif', motif) or '*'
    branches = flask.request.args.get('branches', None)
    owner = flask.request.args.get('owner', None)
    orphaned = bool(flask.request.args.get('orphaned', False))
    status = flask.request.args.get('status', None)
    limit = flask.request.args.get('limit', APP.config['ITEMS_PER_PAGE'])
    page = flask.request.args.get('page', 1)

    try:
        page = int(page)
    except ValueError:
        page = 1

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

    packages = pkgdblib.search_package(
        SESSION,
        pkg_name=pattern,
        clt_name=branches,
        pkg_poc=owner,
        orphaned=orphaned,
        status=status,
        page=page,
        limit=limit,
    )
    packages_count = pkgdblib.search_package(SESSION,
                                             pkg_name=pattern,
                                             clt_name=branches,
                                             pkg_poc=owner,
                                             orphaned=orphaned,
                                             status=status,
                                             page=page,
                                             limit=limit,
                                             count=True)
    total_page = int(ceil(packages_count / float(limit)))

    return flask.render_template('list_packages.html',
                                 packages=packages,
                                 motif=motif,
                                 total_page=total_page,
                                 page=page)
コード例 #3
0
ファイル: acls.py プロジェクト: msmahmood/packagedb2
def watch_package(package):
    ''' Request watch* ACLs on a package.
    Anyone can request these ACLs, no need to be a packager.
    '''
    try:
        pkg = pkgdblib.search_package(SESSION, pkg_name=package, limit=1)[0]
    except IndexError:
        flask.flash('No package found by this name', 'error')
        return flask.redirect(
            flask.url_for('.package_info', package=package))

    pkg_acls = ['watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]
    try:
        for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
            pkgdblib.set_acl_package(
                SESSION,
                pkg_name=package,
                pkg_branch=collec,
                pkg_user=flask.g.fas_user.username,
                acl=acl,
                status='Approved',
                user=flask.g.fas_user,
            )
        SESSION.commit()
        flask.flash('ACLs updated')
    # Let's keep this in although we should never see it
    except pkgdblib.PkgdbException, err:  # pragma: no cover
        SESSION.rollback()
        flask.flash(err.message, 'error')
コード例 #4
0
def package_orphan(package, collection):
    ''' Gives the possibility to orphan or take a package. '''

    packagename = package
    package = None
    try:
        package_acl = pkgdblib.get_acl_package(SESSION, packagename)
        package = pkgdblib.search_package(SESSION, packagename, limit=1)[0]
    except NoResultFound:
        SESSION.rollback()
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')
    except IndexError:
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')

    for acl in package_acl:
        if acl.collection.branchname == collection:
            try:
                pkgdblib.update_pkg_poc(session=SESSION,
                                        pkg_name=package.name,
                                        clt_name=acl.collection.branchname,
                                        pkg_poc='orphan',
                                        user=flask.g.fas_user)
                flask.flash(
                    'You are no longer point of contact on branch: %s' %
                    collection)
            except pkgdblib.PkgdbException, err:
                flask.flash(err.message, 'error')
            break
コード例 #5
0
ファイル: packages.py プロジェクト: ralphbean/packagedb2
def api_package_list(pkgname=None):
    """ List packages.

    :arg packagename: Pattern to list packages from their name.
    :arg branches: List of string of the branches name in which these
        packages will be searched.
    :arg owner: String of the user name to to which restrict the search.
    :arg orphaned: Boolean to retrict the search to orphaned packages.
    :arg deprecated: Boolean to retrict the search to deprecated
        packages.

    """
    httpcode = 200
    output = {}

    pattern = flask.request.args.get("pgkname", pkgname)
    branches = flask.request.args.get("branches", None)
    owner = flask.request.args.get("owner", None)
    orphaned = bool(flask.request.args.get("orphaned", False))
    deprecated = bool(flask.request.args.get("deprecated", False))

    try:
        packages = pkgdblib.search_package(
            SESSION, pkg_name=pattern, clt_name=branches, pkg_owner=owner, orphaned=orphaned, deprecated=deprecated
        )
        SESSION.commit()
        output["output"] = "ok"
        output["packages"] = [pkg.to_json() for pkg in packages]
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        output["output"] = "notok"
        output["error"] = err
        httpcode = 500
コード例 #6
0
def package_retire(package, collection):
    ''' Gives the possibility to orphan or take a package. '''

    packagename = package
    package = None
    try:
        package_acl = pkgdblib.get_acl_package(SESSION, packagename)
        package = pkgdblib.search_package(SESSION, packagename, limit=1)[0]
    except NoResultFound:
        SESSION.rollback()
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')
    except IndexError:
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')

    for acl in package_acl:
        if acl.collection.branchname == collection:
            if acl.point_of_contact == 'orphan':
                try:
                    pkgdblib.update_pkg_status(
                        session=SESSION,
                        pkg_name=package.name,
                        clt_name=acl.collection.branchname,
                        status='Deprecated',
                        user=flask.g.fas_user)
                    flask.flash('This package has been retired on branch: %s' %
                                collection)
                except pkgdblib.PkgdbException, err:
                    flask.flash(err.message, 'error')
                break
            else:
                flask.flash('This package has not been orphaned on '
                            'branch: %s' % collection)
コード例 #7
0
ファイル: packages.py プロジェクト: msmahmood/packagedb2
def package_retire(package, collection):
    ''' Gives the possibility to orphan or take a package. '''

    packagename = package
    package = None
    try:
        package_acl = pkgdblib.get_acl_package(SESSION, packagename)
        package = pkgdblib.search_package(SESSION, packagename, limit=1)[0]
    except (NoResultFound, IndexError):
        SESSION.rollback()
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')

    for acl in package_acl:
        if acl.collection.branchname == collection:
            if acl.point_of_contact == 'orphan':
                try:
                    pkgdblib.update_pkg_status(
                        session=SESSION,
                        pkg_name=package.name,
                        pkg_branch=acl.collection.branchname,
                        status='Retired',
                        user=flask.g.fas_user
                    )
                    flask.flash(
                        'This package has been retired on branch: %s'
                        % collection)
                except pkgdblib.PkgdbException, err:
                    flask.flash(err.message, 'error')
                    SESSION.rollback()
                break
            else:
                flask.flash(
                    'This package has not been orphaned on '
                    'branch: %s' % collection)
コード例 #8
0
ファイル: packages.py プロジェクト: ralphbean/packagedb2
def package_orphan(package, collection):
    ''' Gives the possibility to orphan or take a package. '''

    packagename = package
    package = None
    try:
        package_acl = pkgdblib.get_acl_package(SESSION, packagename)
        package = pkgdblib.search_package(SESSION, packagename, limit=1)[0]
    except NoResultFound:
        SESSION.rollback()
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')
    except IndexError:
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')

    for acl in package_acl:
        if acl.collection.branchname == collection:
            try:
                pkgdblib.update_pkg_poc(
                    session=SESSION,
                    pkg_name=package.name,
                    clt_name=acl.collection.branchname,
                    pkg_poc='orphan',
                    user=flask.g.fas_user
                )
                flask.flash(
                    'You are no longer point of contact on branch: %s'
                    % collection)
            except pkgdblib.PkgdbException, err:
                flask.flash(err.message, 'error')
            break
コード例 #9
0
ファイル: __init__.py プロジェクト: ralphbean/packagedb2
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,
    )
コード例 #10
0
ファイル: acls.py プロジェクト: ralphbean/packagedb2
def comaintain_package(package):
    if not 'packager' in flask.g.fas_user.groups:
        flask.flash(
            'You must be a packager to apply to be a comaintainer',
            'errors')
        return flask.redirect(flask.url_for(
            '.package_info', package=package))

    pkg = pkgdblib.search_package(SESSION, pkg_name=package, limit=1)[0]
    pkg_acls = ['commit', 'watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]

    try:
        for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
            acl_status = 'Awaiting Review'
            if acl in APP.config['AUTO_APPROVE']:
                acl_status = 'Approved'
            pkgdblib.set_acl_package(
                SESSION,
                pkg_name=package,
                clt_name=collec,
                pkg_user=flask.g.fas_user.username,
                acl=acl,
                status=acl_status,
                user=flask.g.fas_user,
            )
        SESSION.commit()
        flask.flash('ACLs updated')
        return flask.redirect(
            flask.url_for('.package_info',
                          package=package))
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        flask.flash(err.message, 'error')
コード例 #11
0
ファイル: acls.py プロジェクト: ralphbean/packagedb2
def comaintain_package(package):
    if not 'packager' in flask.g.fas_user.groups:
        flask.flash('You must be a packager to apply to be a comaintainer',
                    'errors')
        return flask.redirect(flask.url_for('.package_info', package=package))

    pkg = pkgdblib.search_package(SESSION, pkg_name=package, limit=1)[0]
    pkg_acls = ['commit', 'watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]

    try:
        for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
            acl_status = 'Awaiting Review'
            if acl in APP.config['AUTO_APPROVE']:
                acl_status = 'Approved'
            pkgdblib.set_acl_package(
                SESSION,
                pkg_name=package,
                clt_name=collec,
                pkg_user=flask.g.fas_user.username,
                acl=acl,
                status=acl_status,
                user=flask.g.fas_user,
            )
        SESSION.commit()
        flask.flash('ACLs updated')
        return flask.redirect(flask.url_for('.package_info', package=package))
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        flask.flash(err.message, 'error')
コード例 #12
0
def package_info(package):
    ''' Display the information about the specified package. '''

    packagename = package
    package = None
    try:
        package_acl = pkgdblib.get_acl_package(SESSION, packagename)
        package = pkgdblib.search_package(SESSION, packagename, limit=1)[0]
    except NoResultFound:
        SESSION.rollback()
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')
    except IndexError:
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')

    package_acls = []
    branch_admin = []
    is_poc = False
    for pkg in package_acl:
        tmp = {}
        tmp['collection'] = '%s %s' % (pkg.collection.name,
                                       pkg.collection.version)
        tmp['branchname'] = pkg.collection.branchname
        tmp['point_of_contact'] = pkg.point_of_contact
        if hasattr(flask.g, 'fas_user') and flask.g.fas_user and \
                pkg.point_of_contact == flask.g.fas_user.username:
            is_poc = True
        acls = {}
        for acl in pkg.acls:
            tmp2 = {'acl': acl.acl, 'status': acl.status}
            if acl.fas_name in acls:
                acls[acl.fas_name].append(tmp2)
            else:
                acls[acl.fas_name] = [tmp2]
        ## This list is a little hacky, but we would have to save ACLs
        ## in their own table otherwise.
        planned_acls = set(
            ['approveacls', 'commit', 'watchbugzilla', 'watchcommits'])
        seen_acls = set([aclobj['acl'] for aclobj in acls[acl.fas_name]])
        for aclname in planned_acls - seen_acls:
            acls[acl.fas_name].append({'acl': aclname, 'status': ''})
        tmp['acls'] = acls
        package_acls.append(tmp)
        if is_pkg_admin(flask.g.fas_user, package.name,
                        pkg.collection.branchname):
            branch_admin.append(pkg.collection.branchname)

    return flask.render_template(
        'package.html',
        package=package,
        package_acl=package_acls,
        branch_admin=branch_admin,
        is_poc=is_poc,
    )
コード例 #13
0
ファイル: packages.py プロジェクト: ralphbean/packagedb2
def package_info(package):
    ''' Display the information about the specified package. '''

    packagename = package
    package = None
    try:
        package_acl = pkgdblib.get_acl_package(SESSION, packagename)
        package = pkgdblib.search_package(SESSION, packagename, limit=1)[0]
    except NoResultFound:
        SESSION.rollback()
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')
    except IndexError:
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')

    package_acls = []
    branch_admin = []
    is_poc = False
    for pkg in package_acl:
        tmp = {}
        tmp['collection'] = '%s %s' % (pkg.collection.name,
                                       pkg.collection.version)
        tmp['branchname'] = pkg.collection.branchname
        tmp['point_of_contact'] = pkg.point_of_contact
        if hasattr(flask.g, 'fas_user') and flask.g.fas_user and \
                pkg.point_of_contact == flask.g.fas_user.username:
            is_poc = True
        acls = {}
        for acl in pkg.acls:
            tmp2 = {'acl': acl.acl, 'status': acl.status}
            if acl.fas_name in acls:
                acls[acl.fas_name].append(tmp2)
            else:
                acls[acl.fas_name] = [tmp2]
        ## This list is a little hacky, but we would have to save ACLs
        ## in their own table otherwise.
        planned_acls = set(['approveacls', 'commit', 'watchbugzilla',
                            'watchcommits'])
        seen_acls = set([aclobj['acl'] for aclobj in acls[acl.fas_name]])
        for aclname in planned_acls - seen_acls:
            acls[acl.fas_name].append({'acl': aclname, 'status': ''})
        tmp['acls'] = acls
        package_acls.append(tmp)
        if is_pkg_admin(flask.g.fas_user, package.name,
                        pkg.collection.branchname):
            branch_admin.append(pkg.collection.branchname)

    return flask.render_template(
        'package.html',
        package=package,
        package_acl=package_acls,
        branch_admin=branch_admin,
        is_poc=is_poc,
    )
コード例 #14
0
ファイル: acls.py プロジェクト: msmahmood/packagedb2
def comaintain_package(package):
    ''' Asks for ACLs to co-maintain a package.
    You need to be a packager to request co-maintainership.
    '''
    # This is really wearing belt and suspenders, the decorator above
    # should take care of this
    if not 'packager' in flask.g.fas_user.groups:  # pragma: no cover
        flask.flash(
            'You must be a packager to apply to be a comaintainer',
            'errors')
        return flask.redirect(flask.url_for(
            '.package_info', package=package))

    try:
        pkg = pkgdblib.search_package(SESSION, pkg_name=package, limit=1)[0]
    except IndexError:
        flask.flash('No package found by this name', 'error')
        return flask.redirect(
            flask.url_for('.package_info', package=package))

    pkg_acls = ['commit', 'watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]

    try:
        for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
            acl_status = 'Awaiting Review'
            if acl in APP.config['AUTO_APPROVE']:
                acl_status = 'Approved'
            pkgdblib.set_acl_package(
                SESSION,
                pkg_name=package,
                pkg_branch=collec,
                pkg_user=flask.g.fas_user.username,
                acl=acl,
                status=acl_status,
                user=flask.g.fas_user,
            )
        SESSION.commit()
        flask.flash('ACLs updated')
    # Let's keep this in although we should never see it
    except pkgdblib.PkgdbException, err:  # pragma: no cover
        SESSION.rollback()
        flask.flash(err.message, 'error')
コード例 #15
0
ファイル: acls.py プロジェクト: ralphbean/packagedb2
def watch_package(package):
    pkg = pkgdblib.search_package(SESSION, pkg_name=package)[0]
    pkg_acls = ['watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]
    try:
        for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
            pkgdblib.set_acl_package(
                SESSION,
                pkg_name=package,
                clt_name=collec,
                pkg_user=flask.g.fas_user.username,
                acl=acl,
                status='Approved',
                user=flask.g.fas_user,
            )
        SESSION.commit()
        flask.flash('ACLs updated')
        return flask.redirect(flask.url_for('.package_info', package=package))
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        flask.flash(err.message, 'error')
コード例 #16
0
ファイル: packages.py プロジェクト: ralphbean/packagedb2
def api_package_list(pkgname=None):
    ''' List packages.

    :arg packagename: Pattern to list packages from their name.
    :arg branches: List of string of the branches name in which these
        packages will be searched.
    :arg owner: String of the user name to to which restrict the search.
    :arg orphaned: Boolean to retrict the search to orphaned packages.
    :arg deprecated: Boolean to retrict the search to deprecated
        packages.

    '''
    httpcode = 200
    output = {}

    pattern = flask.request.args.get('pgkname', pkgname)
    branches = flask.request.args.get('branches', None)
    owner = flask.request.args.get('owner', None)
    orphaned = bool(flask.request.args.get('orphaned', False))
    deprecated = bool(flask.request.args.get('deprecated', False))

    try:
        packages = pkgdblib.search_package(
            SESSION,
            pkg_name=pattern,
            clt_name=branches,
            pkg_owner=owner,
            orphaned=orphaned,
            deprecated=deprecated,
        )
        SESSION.commit()
        output['output'] = 'ok'
        output['packages'] = [pkg.to_json() for pkg in packages]
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        output['output'] = 'notok'
        output['error'] = err
        httpcode = 500
コード例 #17
0
ファイル: acls.py プロジェクト: ralphbean/packagedb2
def watch_package(package):
    pkg = pkgdblib.search_package(SESSION, pkg_name=package)[0]
    pkg_acls = ['watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]
    try:
        for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
            pkgdblib.set_acl_package(
                SESSION,
                pkg_name=package,
                clt_name=collec,
                pkg_user=flask.g.fas_user.username,
                acl=acl,
                status='Approved',
                user=flask.g.fas_user,
            )
        SESSION.commit()
        flask.flash('ACLs updated')
        return flask.redirect(
            flask.url_for('.package_info',
                          package=package))
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        flask.flash(err.message, 'error')
コード例 #18
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,
    )
コード例 #19
0
ファイル: test_pkgdblib.py プロジェクト: ralphbean/packagedb2
    def test_search_package(self):
        """ Test the search_package function. """
        self.test_add_package()
        pkgs = pkgdblib.search_package(self.session,
                                       pkg_name='gu*',
                                       clt_name='F-18',
                                       pkg_poc=None,
                                       orphaned=None,
                                       status=None,
                                       )
        self.assertEqual(len(pkgs), 1)
        self.assertEqual(pkgs[0].name, 'guake')
        self.assertEqual(pkgs[0].upstream_url, 'http://guake.org')

        pkgs = pkgdblib.search_package(self.session,
                                       pkg_name='g*',
                                       clt_name='F-18',
                                       pkg_poc=None,
                                       orphaned=None,
                                       status=None,
                                       )
        self.assertEqual(len(pkgs), 2)
        self.assertEqual(pkgs[0].name, 'guake')
        self.assertEqual(pkgs[1].name, 'geany')

        pkgs = pkgdblib.search_package(self.session,
                                       pkg_name='g*',
                                       clt_name='F-18',
                                       pkg_poc=None,
                                       orphaned=None,
                                       status=None,
                                       limit=1
                                       )
        self.assertEqual(len(pkgs), 1)
        self.assertEqual(pkgs[0].name, 'guake')

        pkgs = pkgdblib.search_package(self.session,
                                       pkg_name='g*',
                                       clt_name='F-18',
                                       pkg_poc=None,
                                       orphaned=None,
                                       status=None,
                                       limit=1,
                                       page=2
                                       )
        self.assertEqual(len(pkgs), 1)
        self.assertEqual(pkgs[0].name, 'geany')

        pkgs = pkgdblib.search_package(self.session,
                                       pkg_name='g*',
                                       clt_name='F-18',
                                       pkg_poc=None,
                                       orphaned=None,
                                       status=None,
                                       page=2
                                       )
        self.assertEqual(len(pkgs), 0)

        pkgs = pkgdblib.search_package(self.session,
                                       pkg_name='gu*',
                                       clt_name='F-18',
                                       pkg_poc=None,
                                       orphaned=True,
                                       status=None,
                                       )
        self.assertEqual(len(pkgs), 0)

        pkgs = pkgdblib.search_package(self.session,
                                       pkg_name='gu*',
                                       clt_name='F-18',
                                       pkg_poc=None,
                                       orphaned=None,
                                       status='Deprecated',
                                       )
        self.assertEqual(len(pkgs), 0)

        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.search_package,
                          self.session,
                          pkg_name='g*',
                          clt_name='F-18',
                          pkg_poc=None,
                          orphaned=None,
                          status=None,
                          limit='a'
                          )

        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.search_package,
                          self.session,
                          pkg_name='g*',
                          clt_name='F-18',
                          pkg_poc=None,
                          orphaned=None,
                          status=None,
                          page='a'
                          )
コード例 #20
0
ファイル: packages.py プロジェクト: ralphbean/packagedb2
def package_give(package):
    ''' Gives the PoC of a package to someone else. '''


    packagename = package
    package = None
    try:
        package_acl = pkgdblib.get_acl_package(SESSION, packagename)
        package = pkgdblib.search_package(SESSION, packagename, limit=1)[0]
    except NoResultFound:
        SESSION.rollback()
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')
    except IndexError:
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')

    # Restrict the branch to the one current user is PoC of (unless admin
    # or group)
    collect_name = []
    for acl in package_acl:
        if acl.point_of_contact != flask.g.fas_user.username and \
                not is_pkgdb_admin(flask.g.fas_user) and \
                not acl.point_of_contact.startswith('group::'):
            pass
        else:
            if acl.point_of_contact.startswith('group::'):
                group = acl.point_of_contact.split('group::')[0]
                if group not in flask.g.fas_user.groups:
                    pass
            else:
                collect_name.append(acl.collection.branchname)

    form = pkgdb.forms.GivePoCForm(collections=collect_name)

    acls = ['commit', 'watchbugzilla', 'watchcommits', 'approveacls']

    if form.validate_on_submit():
        collections = form.pkg_branch.data
        pkg_poc = form.pkg_poc.data
        if pkg_poc.startswith('group::'):
            acls = ['commit', 'watchbugzilla', 'watchcommits']

        try:
            for pkg_collection in collections:
                message = pkgdblib.update_pkg_poc(
                    SESSION,
                    pkg_name=packagename,
                    clt_name=pkg_collection,
                    pkg_poc=pkg_poc,
                    user=flask.g.fas_user,
                )
                flask.flash(message)

                for acl in acls:
                    pkgdblib.set_acl_package(
                        SESSION,
                        pkg_name=packagename,
                        clt_name=pkg_collection,
                        pkg_user=pkg_poc,
                        acl=acl,
                        status='Approved',
                        user=flask.g.fas_user
                    )

                SESSION.commit()
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'error')

        return flask.redirect(
            flask.url_for('.package_info', package=packagename)
        )
コード例 #21
0
    def test_search_package(self):
        """ Test the search_package function. """
        self.test_add_package()
        pkgs = pkgdblib.search_package(
            self.session,
            pkg_name='gu*',
            clt_name='F-18',
            pkg_poc=None,
            orphaned=None,
            status=None,
        )
        self.assertEqual(len(pkgs), 1)
        self.assertEqual(pkgs[0].name, 'guake')
        self.assertEqual(pkgs[0].upstream_url, 'http://guake.org')

        pkgs = pkgdblib.search_package(
            self.session,
            pkg_name='g*',
            clt_name='F-18',
            pkg_poc=None,
            orphaned=None,
            status=None,
        )
        self.assertEqual(len(pkgs), 2)
        self.assertEqual(pkgs[0].name, 'guake')
        self.assertEqual(pkgs[1].name, 'geany')

        pkgs = pkgdblib.search_package(self.session,
                                       pkg_name='g*',
                                       clt_name='F-18',
                                       pkg_poc=None,
                                       orphaned=None,
                                       status=None,
                                       limit=1)
        self.assertEqual(len(pkgs), 1)
        self.assertEqual(pkgs[0].name, 'guake')

        pkgs = pkgdblib.search_package(self.session,
                                       pkg_name='g*',
                                       clt_name='F-18',
                                       pkg_poc=None,
                                       orphaned=None,
                                       status=None,
                                       limit=1,
                                       page=2)
        self.assertEqual(len(pkgs), 1)
        self.assertEqual(pkgs[0].name, 'geany')

        pkgs = pkgdblib.search_package(self.session,
                                       pkg_name='g*',
                                       clt_name='F-18',
                                       pkg_poc=None,
                                       orphaned=None,
                                       status=None,
                                       page=2)
        self.assertEqual(len(pkgs), 0)

        pkgs = pkgdblib.search_package(
            self.session,
            pkg_name='gu*',
            clt_name='F-18',
            pkg_poc=None,
            orphaned=True,
            status=None,
        )
        self.assertEqual(len(pkgs), 0)

        pkgs = pkgdblib.search_package(
            self.session,
            pkg_name='gu*',
            clt_name='F-18',
            pkg_poc=None,
            orphaned=None,
            status='Deprecated',
        )
        self.assertEqual(len(pkgs), 0)

        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.search_package,
                          self.session,
                          pkg_name='g*',
                          clt_name='F-18',
                          pkg_poc=None,
                          orphaned=None,
                          status=None,
                          limit='a')

        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.search_package,
                          self.session,
                          pkg_name='g*',
                          clt_name='F-18',
                          pkg_poc=None,
                          orphaned=None,
                          status=None,
                          page='a')
コード例 #22
0
def package_give(package):
    ''' Gives the PoC of a package to someone else. '''

    packagename = package
    package = None
    try:
        package_acl = pkgdblib.get_acl_package(SESSION, packagename)
        package = pkgdblib.search_package(SESSION, packagename, limit=1)[0]
    except NoResultFound:
        SESSION.rollback()
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')
    except IndexError:
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')

    # Restrict the branch to the one current user is PoC of (unless admin
    # or group)
    collect_name = []
    for acl in package_acl:
        if acl.point_of_contact != flask.g.fas_user.username and \
                not is_pkgdb_admin(flask.g.fas_user) and \
                not acl.point_of_contact.startswith('group::'):
            pass
        else:
            if acl.point_of_contact.startswith('group::'):
                group = acl.point_of_contact.split('group::')[0]
                if group not in flask.g.fas_user.groups:
                    pass
            else:
                collect_name.append(acl.collection.branchname)

    form = pkgdb.forms.GivePoCForm(collections=collect_name)

    acls = ['commit', 'watchbugzilla', 'watchcommits', 'approveacls']

    if form.validate_on_submit():
        collections = form.pkg_branch.data
        pkg_poc = form.pkg_poc.data
        if pkg_poc.startswith('group::'):
            acls = ['commit', 'watchbugzilla', 'watchcommits']

        try:
            for pkg_collection in collections:
                message = pkgdblib.update_pkg_poc(
                    SESSION,
                    pkg_name=packagename,
                    clt_name=pkg_collection,
                    pkg_poc=pkg_poc,
                    user=flask.g.fas_user,
                )
                flask.flash(message)

                for acl in acls:
                    pkgdblib.set_acl_package(SESSION,
                                             pkg_name=packagename,
                                             clt_name=pkg_collection,
                                             pkg_user=pkg_poc,
                                             acl=acl,
                                             status='Approved',
                                             user=flask.g.fas_user)

                SESSION.commit()
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'error')

        return flask.redirect(
            flask.url_for('.package_info', package=packagename))