Esempio n. 1
0
File: util.py Progetto: tyll/bodhi
def get_pkg_pushers(pkg, branch):
    watchers = []
    committers = []
    watchergroups = []
    committergroups = []

    if config.get('acl_system') == 'dummy':
        return ((['guest',
                  'admin'], ['guest',
                             'admin']), (['guest',
                                          'admin'], ['guest', 'admin']))

    from pkgdb2client import PkgDB
    pkgdb = PkgDB(config.get('pkgdb_url'))
    acls = pkgdb.get_package(pkg, branches=branch)

    for package in acls['packages']:
        for acl in package.get('acls', []):
            if acl['status'] == 'Approved':
                if acl['acl'] == 'watchcommits':
                    name = acl['fas_name']
                    if name.startswith('group::'):
                        watchergroups.append(name.split('::')[1])
                    else:
                        watchers.append(name)
                elif acl['acl'] == 'commit':
                    name = acl['fas_name']
                    if name.startswith('group::'):
                        committergroups.append(name.split('::')[1])
                    else:
                        committers.append(name)

    return (committers, watchers), (committergroups, watchergroups)
Esempio n. 2
0
def get_critpath_components(collection='master', component_type='rpm'):
    """
    Return a list of critical path packages for a given collection.

    Args:
    collection (basestring): The collection/branch to search. Defaults to 'master'.
    component_type (basestring): The component type to search for. This only affects PDC queries.
        Defaults to 'rpm'.
    Returns:
        list: The critpath components for the given collection and type.
    """
    critpath_components = []
    critpath_type = config.get('critpath.type')
    if critpath_type != 'pdc' and component_type != 'rpm':
        log.warning('The critpath.type of "{0}" does not support searching for'
                    ' non-RPM components'.format(component_type))

    if critpath_type == 'pkgdb':
        from pkgdb2client import PkgDB
        pkgdb = PkgDB(config.get('pkgdb_url'))
        results = pkgdb.get_critpath_packages(branches=collection)
        if collection in results['pkgs']:
            critpath_components = results['pkgs'][collection]
    elif critpath_type == 'pdc':
        critpath_components = get_critpath_components_from_pdc(
            collection, component_type)
    else:
        critpath_components = config.get('critpath_pkgs')
    return critpath_components
Esempio n. 3
0
    def __init__(self, irc):
        super(Fedora, self).__init__(irc)

        # caches, automatically downloaded on __init__, manually refreshed on
        # .refresh
        self.userlist = None
        self.bugzacl = None

        # To get the information, we need a username and password to FAS.
        # DO NOT COMMIT YOUR USERNAME AND PASSWORD TO THE PUBLIC REPOSITORY!
        self.fasurl = self.registryValue('fas.url')
        self.username = self.registryValue('fas.username')
        self.password = self.registryValue('fas.password')

        self.fasclient = AccountSystem(self.fasurl, username=self.username,
                                       password=self.password)
        self.pkgdb = PkgDB()
        # URLs
        # self.url = {}

        self.github_oauth_token = self.registryValue('github.oauth_token')

        self.karma_tokens = ('++', '--') if self.allow_negative else ('++',)

        # fetch necessary caches
        self._refresh()

        # Pull in /etc/fedmsg.d/ so we can build the fedmsg.meta processors.
        fm_config = fedmsg.config.load_config()
        fedmsg.meta.make_processors(**fm_config)
Esempio n. 4
0
def get_critpath_pkgs(collection='master'):
    """Return a list of critical path packages for a given collection"""
    critpath_pkgs = []
    critpath_type = config.get('critpath.type')
    if critpath_type == 'pkgdb':
        from pkgdb2client import PkgDB
        pkgdb = PkgDB(config.get('pkgdb_url'))
        results = pkgdb.get_critpath_packages(branches=collection)
        if collection in results['pkgs']:
            critpath_pkgs = results['pkgs'][collection]
    else:
        critpath_pkgs = config.get('critpath_pkgs', '').split()
    return critpath_pkgs
Esempio n. 5
0
File: util.py Progetto: tyll/bodhi
def get_critpath_pkgs(collection='master'):
    critpath_pkgs = []
    critpath_type = config.get('critpath.type', None)
    if critpath_type == 'pkgdb':
        from pkgdb2client import PkgDB
        pkgdb = PkgDB(config.get('pkgdb_url'))
        results = pkgdb.get_critpath_packages(branches=collection)
        if collection in results['pkgs']:
            critpath_pkgs = results['pkgs'][collection]
    else:
        # HACK: Avoid the current critpath policy for EPEL
        if not collection.startswith('EL'):
            # Note: ''.split() == []
            critpath_pkgs = config.get('critpath', '').split()
    return critpath_pkgs
Esempio n. 6
0
def get_critpath_components(collection='master',
                            component_type='rpm',
                            components=None):
    """
    Return a list of critical path packages for a given collection, filtered by components.

    Args:
        collection (basestring): The collection/branch to search. Defaults to 'master'.
        component_type (basestring): The component type to search for. This only affects PDC
            queries. Defaults to 'rpm'.
        components (frozenset or None): The list of components we are interested in. If None (the
            default), all components for the given collection and type are returned.
    Returns:
        list: The critpath components for the given collection and type.
    """
    critpath_components = []
    critpath_type = config.get('critpath.type')
    if critpath_type != 'pdc' and component_type != 'rpm':
        log.warning('The critpath.type of "{0}" does not support searching for'
                    ' non-RPM components'.format(component_type))

    if critpath_type == 'pkgdb':
        from pkgdb2client import PkgDB
        pkgdb = PkgDB(config.get('pkgdb_url'))
        results = pkgdb.get_critpath_packages(branches=collection)
        if collection in results['pkgs']:
            critpath_components = results['pkgs'][collection]
    elif critpath_type == 'pdc':
        critpath_components = get_critpath_components_from_pdc(
            collection, component_type, components)
    else:
        critpath_components = config.get('critpath_pkgs')

    # Filter the list of components down to what was requested, in case the specific path did
    # not take our request into account.
    if components is not None:
        critpath_components = [
            c for c in critpath_components if c in components
        ]

    return critpath_components
Esempio n. 7
0
    def __init__(self, bot):
        self.bot = bot

        fas_url = bot.config['fas']['url']
        fas_username = bot.config['fas']['username']
        fas_password = bot.config['fas']['password']
        self.fasclient = AccountSystem(fas_url,
                                       username=fas_username,
                                       password=fas_password)

        #self.log.info("Downloading package owners cache")
        data = requests.get(
            'https://admin.fedoraproject.org/pkgdb/api/bugzilla?format=json',
            verify=True).json()
        self.bugzacl = data['bugzillaAcls']

        self.pkgdb = PkgDB()

        # Pull in /etc/fedmsg.d/ so we can build the fedmsg.meta processors.
        fm_config = fedmsg.config.load_config()
        fedmsg.meta.make_processors(**fm_config)
Esempio n. 8
0
from fedora.client import (AppError, ServerError)

import argparse
import requests
import logging
import koji
import itertools

from pkgdb2client import PkgDB, PkgDBException, __version__
import pkgdb2client
import pkgdb2client.utils

KOJI_HUB = 'http://koji.fedoraproject.org/kojihub'

pkgdbclient = PkgDB('https://admin.fedoraproject.org/pkgdb',
                    login_callback=pkgdb2client.ask_password)
BOLD = "\033[1m"
RED = "\033[0;31m"
RESET = "\033[0;0m"

# Initial simple logging stuff
logging.basicConfig()
PKGDBLOG = logging.getLogger("pkgdb2client")
LOG = logging.getLogger("pkgdb-cli")

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


class ActionError(Exception):
    ''' This class is raised when an ACL action is requested but not in
    the list of allowed action. '''
Esempio n. 9
0
# Set Koschei monitoring flag for <PACKAGES> to <VALUE> in pkgdb2 instance at
# <PKGDB_URL>.  Login credentials are provided in <FAS_CONF> file.
# Requires: packagedb-cli >= 2.9.
PACKAGES = ['pkg1', 'pkg2']
VALUE = True
PKGDB_URL = 'https://admin.stg.fedoraproject.org/pkgdb'
FAS_CONF = '/etc/fas.conf'


from pkgdb2client import PkgDB
from ConfigParser import ConfigParser

# Obtain FAS credentials
conf = ConfigParser()
conf.read(FAS_CONF)
login = conf.get('global', 'login')
password = conf.get('global', 'password')

# Initiate authenticated pkgdb2 session
pkgdb = PkgDB(PKGDB_URL)
pkgdb.login(login, password)

# Set package monitoring status one-by-one
for package in PACKAGES:
    result = pkgdb.set_koschei_status(package, VALUE)
    message = result.get('messages', 'Invalid output')
    print "%s: %s" % (package, message)

print "Done."
Esempio n. 10
0
from fedora.client import (AppError, ServerError)

import argparse
import requests
import logging
import koji
import itertools

from pkgdb2client import PkgDB, PkgDBException, __version__
import pkgdb2client
import pkgdb2client.utils


KOJI_HUB = 'http://koji.fedoraproject.org/kojihub'

pkgdbclient = PkgDB('https://admin.fedoraproject.org/pkgdb',
                    login_callback=pkgdb2client.ask_password)
BOLD = "\033[1m"
RED = "\033[0;31m"
RESET = "\033[0;0m"

# Initial simple logging stuff
logging.basicConfig()
PKGDBLOG = logging.getLogger("pkgdb2client")
LOG = logging.getLogger("pkgdb-cli")

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


class ActionError(Exception):
    ''' This class is raised when an ACL action is requested but not in
    the list of allowed action. '''
Esempio n. 11
0
def main():
    ''' Main function '''
    # Set up parser for global args
    parser = setup_parser()
    # Parse the commandline
    try:
        arg = parser.parse_args()
    except argparse.ArgumentTypeError as err:
        print("\nError: {0}".format(err))
        return 2

    if arg.nocolor:
        global RED, BOLD, RESET
        RED = ""
        BOLD = ""
        RESET = ""

    logging.basicConfig()
    if arg.debug:
        LOG.setLevel(logging.DEBUG)
        PKGDBLOG.setLevel(logging.DEBUG)
    elif arg.verbose:
        LOG.setLevel(logging.INFO)

    global pkgdbclient
    if arg.pkgdburl != pkgdb2client.PKGDB_URL:
        print("Querying pkgdb at: %s" % arg.pkgdburl)
        pkgdbclient = PkgDB(
            arg.pkgdburl,
            login_callback=pkgdb2client.ask_password)

    pkgdbclient.insecure = arg.insecure

    if arg.bzurl != pkgdb2client.BZ_URL:
        if not arg.bzurl.endswith('xmlrpc.cgi'):
            arg.bzurl = '%s/xmlrpc.cgi' % arg.bzurl
        print("Querying bugzilla at: %s" % arg.bzurl)
        utils._get_bz(arg.bzurl, insecure=arg.insecure)

    if arg.fasurl != pkgdb2client.FAS_URL:
        print("Querying FAS at: %s" % arg.fasurl)
        utils._get_fas(arg.fasurl, insecure=arg.insecure)

    if arg.kojihuburl != pkgdb2client.KOJI_HUB:
        print("Querying koji at: %s" % arg.kojihuburl)
        global KOJI_HUB
        KOJI_HUB = arg.kojihuburl

    return_code = 0

    if arg.password:
        pkgdbclient.password = arg.password
    if arg.username:
        pkgdbclient.username = arg.username

    try:
        arg.func(arg)
    except KeyboardInterrupt:
        print("\nInterrupted by user.")
        return_code = 1
    except ServerError as err:
        LOG.debug('ServerError')
        print('{0}'.format(err))
        return_code = 3
    except ActionError as err:
        LOG.debug('ActionError')
        print('{0}'.format(err.message))
        return_code = 7
    except argparse.ArgumentError as err:
        LOG.debug('ArgparseError')
        print('{0}'.format(err.message))
        return_code = 9
    except AppError as err:
        LOG.debug('AppError')
        print('{0}: {1}'.format(err.name, err.message))
        return_code = 4
    except PkgDBException as err:
        LOG.debug('PkgDBException')
        print('{0}'.format(err))
        return_code = 8
    except ValueError as err:
        print('Error: {0}'.format(err))
        print('Did you log in?')
        return_code = 6
    except Exception as err:
        print('Error: {0}'.format(err))
        logging.exception("Generic error catched:")
        return_code = 5

    return return_code
Esempio n. 12
0
"""

from fedora.client import (AppError, ServerError)

import argparse
import requests
import logging
import koji
import itertools

from pkgdb2client import PkgDB, PkgDBException, __version__
import pkgdb2client
import pkgdb2client.utils as utils


pkgdbclient = PkgDB(
    pkgdb2client.PKGDB_URL, login_callback=pkgdb2client.ask_password)

BOLD = "\033[1m"
RED = "\033[0;31m"
RESET = "\033[0;0m"

# Initial simple logging stuff
logging.basicConfig()
PKGDBLOG = logging.getLogger("pkgdb2client")
LOG = logging.getLogger("pkgdb-cli")

ACTIONLIST = ['watchbugzilla', 'watchcommits', 'commit', 'approveacls']
KOJI_HUB = pkgdb2client.KOJI_HUB


class ActionError(Exception):
Esempio n. 13
0
 def setUp(self):
     """ set up data used in the tests.
     setUp is called before each test function execution.
     """
     self.pkgdb = PkgDB(PKGDB_URL, insecure=True)
Esempio n. 14
0
def main():
    ''' Main function '''
    # Set up parser for global args
    parser = setup_parser()
    # Parse the commandline
    try:
        arg = parser.parse_args()
    except argparse.ArgumentTypeError as err:
        print("\nError: {0}".format(err))
        return 2

    logging.basicConfig()
    if arg.debug:
        LOG.setLevel(logging.DEBUG)
        PKGDBLOG.setLevel(logging.DEBUG)
    elif arg.verbose:
        LOG.setLevel(logging.INFO)

    global PKGDBCLIENT
    if arg.pkgdburl:
        LOG.info("Querying pkgdb at: %s", arg.pkgdburl)
        PKGDBCLIENT = PkgDB(arg.pkgdburl,
                            login_callback=pkgdb2client.ask_password)

    PKGDBCLIENT.insecure = arg.insecure

    if arg.bzurl:
        if not arg.bzurl.endswith('xmlrpc.cgi'):
            arg.bzurl = '%s/xmlrpc.cgi' % arg.bzurl
        LOG.info("Querying bugzilla at: %s", arg.pkgdburl)
        utils._get_bz(arg.bzurl, insecure=arg.insecure)

    if arg.fasurl:
        LOG.info("Querying FAS at: %s", arg.pkgdburl)
        utils.FASCLIENT.base_url = arg.fasurl
        utils.FASCLIENT.insecure = arg.insecure

    return_code = 0

    if arg.password:
        PKGDBCLIENT.password = arg.password
    if arg.username:
        PKGDBCLIENT.username = arg.username

    try:
        arg.func(arg)
    except KeyboardInterrupt:
        print("\nInterrupted by user.")
        return_code = 1
    except ServerError as err:
        LOG.debug('ServerError')
        print('{0}'.format(err))
        return_code = 3
    except ActionError as err:
        LOG.debug('ActionError')
        print('{0}'.format(err.message))
        return_code = 7
    except AppError as err:
        LOG.debug('AppError')
        print('{0}: {1}'.format(err.name, err.message))
        return_code = 4
    except PkgDBException as err:
        LOG.debug('PkgDBException')
        print('{0}'.format(err))
        return_code = 8
    except ValueError as err:
        print('Error: {0}'.format(err))
        print('Did you log in?')
        return_code = 6
    except Exception as err:
        print('Error: {0}'.format(err))
        logging.exception("Generic error catched:")
        return_code = 5

    return return_code
Esempio n. 15
0
# license.
"""

from fedora.client import (AppError, ServerError)

import argparse
import logging

from six.moves import input

from pkgdb2client import PkgDB, PkgDBException, __version__
from pkgdb2client.cli import ActionError
import pkgdb2client
import pkgdb2client.utils as utils

PKGDBCLIENT = PkgDB('https://admin.fedoraproject.org/pkgdb',
                    login_callback=pkgdb2client.ask_password)
BOLD = "\033[1m"
RED = "\033[0;31m"
RESET = "\033[0;0m"

# Initial simple logging stuff
logging.basicConfig()
PKGDBLOG = logging.getLogger("pkgdb2client")
LOG = logging.getLogger("pkgdb-admin")


def setup_parser():
    '''
    Set the main arguments.
    '''
    parser = argparse.ArgumentParser(prog="pkgdb-admin")
Esempio n. 16
0
"""

from fedora.client import (AppError, ServerError)

import argparse
import requests
import logging
import koji

from pkgdb2client import PkgDB, PkgDBException, __version__
from pkgdb2client.cli import ActionError
import pkgdb2client
import pkgdb2client.utils as utils


PKGDBCLIENT = PkgDB('https://admin.fedoraproject.org/pkgdb',
                    login_callback=pkgdb2client.ask_password)
BOLD = "\033[1m"
RED = "\033[0;31m"
RESET = "\033[0;0m"

# Initial simple logging stuff
logging.basicConfig()
PKGDBLOG = logging.getLogger("pkgdb2client")
LOG = logging.getLogger("pkgdb-admin")


def setup_parser():
    '''
    Set the main arguments.
    '''
    parser = argparse.ArgumentParser(prog="pkgdb-admin")