Ejemplo n.º 1
0
def get_pkg_changelog(request):
    branch = request.match_info.get('branch')
    name = request.match_info.get('name')
    pretty = _get_pretty(request)
    pkg, repotype = yield from _get_pkg(branch, name)

    dbfile = '%s/mdapi-%s%s-other.sqlite' % (
        CONFIG['DB_FOLDER'], branch, '-%s' % repotype if repotype else '')
    if not os.path.exists(dbfile):
        raise web.HTTPBadRequest()

    with file_lock.FileFlock(dbfile + '.lock'):
        session2 = yield from mdapilib.create_session(
            'sqlite:///%s' % dbfile)
        changelogs = yield from mdapilib.get_changelog(session2, pkg.pkgId)
        session2.close()

    output = {
        'changelogs': [changelog.to_json() for changelog in changelogs],
        'repo': repotype if repotype else 'release',
    }
    args = {}
    if pretty:
        args = dict(sort_keys=True, indent=4, separators=(',', ': '))

    return web.Response(body=json.dumps(output, **args).encode('utf-8'),
                        content_type='application/json')
Ejemplo n.º 2
0
def get_pkg_changelog(request):
    branch = request.match_info.get('branch')
    name = request.match_info.get('name')
    pretty = _get_pretty(request)
    pkg, repotype = yield from _get_pkg(branch, name)

    dbfile = '%s/mdapi-%s%s-other.sqlite' % (
        CONFIG['DB_FOLDER'], branch, '-%s' % repotype if repotype else '')
    if not os.path.exists(dbfile):
        raise web.HTTPBadRequest()

    with file_lock.FileFlock(dbfile + '.lock'):
        session2 = yield from mdapilib.create_session('sqlite:///%s' % dbfile)
        changelogs = yield from mdapilib.get_changelog(session2, pkg.pkgId)
        session2.close()

    output = {
        'changelogs': [changelog.to_json() for changelog in changelogs],
        'repo': repotype if repotype else 'release',
    }
    args = {}
    if pretty:
        args = dict(sort_keys=True, indent=4, separators=(',', ': '))

    return web.Response(body=json.dumps(output, **args).encode('utf-8'),
                        content_type='application/json')
Ejemplo n.º 3
0
def _get_pkg(branch, name):
    ''' Return the pkg information for the given package in the specified
    branch or raise an aiohttp exception.
    '''
    pkg = None
    wrongdb = False
    for repotype in ['updates-testing', 'updates', 'testing', None]:

        if repotype:
            dbfile = '%s/mdapi-%s-%s-primary.sqlite' % (
                CONFIG['DB_FOLDER'], branch, repotype)
        else:
            dbfile = '%s/mdapi-%s-primary.sqlite' % (CONFIG['DB_FOLDER'], branch)

        if not os.path.exists(dbfile):
            wrongdb = True
            continue

        wrongdb = False

        with file_lock.FileFlock(dbfile + '.lock'):
            session = mdapilib.create_session('sqlite:///%s' % dbfile)
            pkg = mdapilib.get_package(session, name)
            session.close()
        if pkg:
            break

    if wrongdb:
        raise web.HTTPBadRequest()

    if not pkg:
        raise web.HTTPNotFound()

    return (pkg, repotype)
Ejemplo n.º 4
0
def get_pkg_files(request):
    branch = request.match_info.get('branch')
    name = request.match_info.get('name')
    pretty = _get_pretty(request)
    pkg, repotype = _get_pkg(branch, name)

    dbfile = '%s/mdapi-%s%s-filelists.sqlite' % (
        CONFIG['DB_FOLDER'], branch, '-%s' % repotype if repotype else '')
    if not os.path.exists(dbfile):
        raise web.HTTPBadRequest()

    with file_lock.FileFlock(dbfile + '.lock'):
        session2 = mdapilib.create_session('sqlite:///%s' % dbfile)
        filelist = mdapilib.get_files(session2, pkg.pkgId)
        session2.close()

    output = {
        'files': [fileinfo.to_json() for fileinfo in filelist],
        'repo': repotype if repotype else 'release',
    }
    args = {}
    if pretty:
        args = dict(sort_keys=True, indent=4, separators=(',', ': '))

    return web.Response(body=json.dumps(output, **args).encode('utf-8'))
Ejemplo n.º 5
0
def _expand_pkg_info(pkgs, branch, repotype=None):
    ''' Return a JSON blob containing all the information we want to return
    for the provided package or packages.
    '''
    singleton = False
    if not isinstance(pkgs, (list, tuple)):
        singleton = True
        pkgs = [pkgs]
    output = []
    for pkg in pkgs:
        out = pkg.to_json()
        dbfile = '%s/mdapi-%s%s-primary.sqlite' % (
            CONFIG['DB_FOLDER'], branch, '-%s' % repotype if repotype else '')

        with file_lock.FileFlock(dbfile + '.lock'):
            session = yield from mdapilib.create_session('sqlite:///%s' %
                                                         dbfile)
            # Fill in some extra info

            # Basic infos, always present regardless of the version of the repo
            for datatype in ['conflicts', 'obsoletes', 'provides', 'requires']:
                data = yield from mdapilib.get_package_info(
                    session, pkg.pkgKey, datatype.capitalize())
                if data:
                    out[datatype] = [item.to_json() for item in data]
                else:
                    out[datatype] = data

            # New meta-data present for soft dependency management in RPM
            for datatype in [
                    'enhances', 'recommends', 'suggests', 'supplements'
            ]:
                data = yield from mdapilib.get_package_info(
                    session, pkg.pkgKey, datatype.capitalize())
                if data:
                    out[datatype] = [item.to_json() for item in data]
                else:
                    out[datatype] = data

            # Add the list of packages built from the same src.rpm
            if pkg.rpm_sourcerpm:
                copkgs = yield from mdapilib.get_co_packages(
                    session, pkg.rpm_sourcerpm)
                out['co-packages'] = list(set([cpkg.name for cpkg in copkgs]))
            else:
                out['co-packages'] = []
            out['repo'] = repotype if repotype else 'release'
            session.close()
        output.append(out)
    if singleton:
        return output[0]
    else:
        return output
Ejemplo n.º 6
0
def _expand_pkg_info(pkgs, branch, repotype=None):
    ''' Return a JSON blob containing all the information we want to return
    for the provided package or packages.
    '''
    singleton = False
    if not isinstance(pkgs, (list, tuple)):
        singleton = True
        pkgs = [pkgs]
    output = []
    for pkg in pkgs:
        out = pkg.to_json()
        dbfile = '%s/mdapi-%s%s-primary.sqlite' % (
            CONFIG['DB_FOLDER'], branch, '-%s' % repotype if repotype else '')

        with file_lock.FileFlock(dbfile + '.lock'):
            session = yield from mdapilib.create_session(
                'sqlite:///%s' % dbfile)
            # Fill in some extra info

            # Basic infos, always present regardless of the version of the repo
            for datatype in ['conflicts', 'obsoletes', 'provides', 'requires']:
                data = yield from mdapilib.get_package_info(
                    session, pkg.pkgKey, datatype.capitalize())
                if data:
                    out[datatype] = [item.to_json() for item in data]
                else:
                    out[datatype] = data

            # New meta-data present for soft dependency management in RPM
            for datatype in ['enhances', 'recommends', 'suggests', 'supplements']:
                data = yield from mdapilib.get_package_info(
                    session, pkg.pkgKey, datatype.capitalize())
                if data:
                    out[datatype] = [item.to_json() for item in data]
                else:
                    out[datatype] = data

            # Add the list of packages built from the same src.rpm
            if pkg.rpm_sourcerpm:
                copkgs = yield from mdapilib.get_co_packages(
                    session, pkg.rpm_sourcerpm)
                out['co-packages'] = list(set([
                    cpkg.name for cpkg in copkgs
                ]))
            else:
                out['co-packages'] = []
            out['repo'] = repotype if repotype else 'release'
            session.close()
        output.append(out)
    if singleton:
        return output[0]
    else:
        return output
Ejemplo n.º 7
0
def get_pkg(request):
    branch = request.match_info.get('branch')
    pretty = _get_pretty(request)
    name = request.match_info.get('name')
    pkg, repotype = _get_pkg(branch, name)

    output = pkg.to_json()

    dbfile = '%s/mdapi-%s%s-primary.sqlite' % (
        CONFIG['DB_FOLDER'], branch, '-%s' % repotype if repotype else '')

    with file_lock.FileFlock(dbfile + '.lock'):
        session = mdapilib.create_session('sqlite:///%s' % dbfile)
        # Fill in some extra info

        # Basic infos, always present regardless of the version of the repo
        for datatype in ['conflicts', 'obsoletes', 'provides', 'requires']:
            data = mdapilib.get_package_info(
                session, pkg.pkgKey, datatype.capitalize())
            if data:
                output[datatype] = [item.to_json() for item in data]
            else:
                output[datatype] = data

        # New meta-data present for soft dependency management in RPM
        for datatype in ['enhances', 'recommends', 'suggests', 'supplements']:
            data = mdapilib.get_package_info(
                session, pkg.pkgKey, datatype.capitalize())
            if data:
                output[datatype] = [item.to_json() for item in data]
            else:
                output[datatype] = data

        # Add the list of packages built from the same src.rpm
        if pkg.rpm_sourcerpm:
            output['co-packages'] = list(set([
                cpkg.name
                for cpkg in mdapilib.get_co_packages(session, pkg.rpm_sourcerpm)
            ]))
        else:
            output['co-packages'] = []
        output['repo'] = repotype if repotype else 'release'
        session.close()

    args = {}
    if pretty:
        args = dict(sort_keys=True, indent=4, separators=(',', ': '))

    return web.Response(body=json.dumps(output, **args).encode('utf-8'))
Ejemplo n.º 8
0
def _get_pkg(branch, name=None, action=None, srcname=None):
    ''' Return the pkg information for the given package in the specified
    branch or raise an aiohttp exception.
    '''
    if (not name and not srcname) or (name and srcname):
        raise web.HTTPBadRequest()

    pkg = None
    wrongdb = False
    for repotype in ['updates-testing', 'updates', 'testing', None]:

        if repotype:
            dbfile = '%s/mdapi-%s-%s-primary.sqlite' % (CONFIG['DB_FOLDER'],
                                                        branch, repotype)
        else:
            dbfile = '%s/mdapi-%s-primary.sqlite' % (CONFIG['DB_FOLDER'],
                                                     branch)

        if not os.path.exists(dbfile):
            wrongdb = True
            continue

        wrongdb = False

        with file_lock.FileFlock(dbfile + '.lock'):
            session = yield from mdapilib.create_session('sqlite:///%s' %
                                                         dbfile)
            if name:
                if action:
                    pkg = yield from mdapilib.get_package_by(
                        session, action, name)
                else:
                    pkg = yield from mdapilib.get_package(session, name)
            elif srcname:
                pkg = yield from mdapilib.get_package_by_src(session, srcname)
            session.close()
        if pkg:
            break

    if wrongdb:
        raise web.HTTPBadRequest()

    if not pkg:
        raise web.HTTPNotFound()

    return (pkg, repotype)