From 5a1e519eb035e449661c8f2598026d7dbde4c9aa Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 16 2015 08:48:35 +0000 Subject: [PATCH 1/3] Map the tables listing all the dependencies information in the primary DB --- diff --git a/mdapi/primary.py b/mdapi/primary.py index 41d1b46..80b8ddb 100644 --- a/mdapi/primary.py +++ b/mdapi/primary.py @@ -62,3 +62,87 @@ class Package(BASE): 'basename': self.basename, } return pkg + + +class BaseDependency(object): + ''' Base mapping for the tables in the primary.sqlite database that + contain all the dependencies information + ''' + rowid = sa.Column(sa.Integer, primary_key=True) + pkgKey = sa.Column(sa.Integer, index=True) + name = sa.Column(sa.Text) + epoch = sa.Column(sa.Text) + version = sa.Column(sa.Text) + release = sa.Column(sa.Text) + + def to_json(self): + pkg = { + 'name': self.name, + 'epoch': self.epoch, + 'version': self.version, + 'release': self.release, + } + return pkg + + +BASEDEP = declarative_base(cls=BaseDependency) + + +class Requires(BASEDEP): + ''' Maps the requires table in the primary.sqlite database from + repodata to a python object. + ''' + __tablename__ = 'requires' + + +class Provides(BASEDEP): + ''' Maps the provides table in the primary.sqlite database from + repodata to a python object. + ''' + __tablename__ = 'provides' + + +class Conflicts(BASEDEP): + ''' Maps the conflicts table in the primary.sqlite database from + repodata to a python object. + ''' + __tablename__ = 'conflicts' + + + +class Obsoletes(BASEDEP): + ''' Maps the provides table in the primary.sqlite database from + repodata to a python object. + ''' + __tablename__ = 'obsoletes' + + +# New soft-dependencies + + +class Enhances(BASEDEP): + ''' Maps the enhances table in the primary.sqlite database from + repodata to a python object. + ''' + __tablename__ = 'enhances' + + +class Recommends(BASEDEP): + ''' Maps the recommends table in the primary.sqlite database from + repodata to a python object. + ''' + __tablename__ = 'recommends' + + +class Suggests(BASEDEP): + ''' Maps the suggests table in the primary.sqlite database from + repodata to a python object. + ''' + __tablename__ = 'suggests' + + +class Supplements(BASEDEP): + ''' Maps the supplements table in the primary.sqlite database from + repodata to a python object. + ''' + __tablename__ = 'supplements' From 610acd0c8c543bcb702b31bd83b024755ad1b138 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 16 2015 08:48:54 +0000 Subject: [PATCH 2/3] Add a method to query the dependency tables in the primary DB for info about a package --- diff --git a/mdapi/lib.py b/mdapi/lib.py index 3c14649..982f4b8 100644 --- a/mdapi/lib.py +++ b/mdapi/lib.py @@ -30,11 +30,12 @@ import sqlalchemy as sa from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import scoped_session -from sqlalchemy.exc import SQLAlchemyError +from sqlalchemy.exc import SQLAlchemyError, OperationalError import mdapi.changelog as changelog import mdapi.filelist as filelist import mdapi.primary as primary +import mdapi.primary_new as primary_new RETRY_ATTEMPT = 3 @@ -93,6 +94,32 @@ def get_package(session, pkg_name): return output +def get_package_info(session, pkgKey, tablename): + ''' Return the information contained in the specified table for the + given package. + ''' + table = getattr(primary, tablename) + cnt = 0 + try: + query = session.query( + table + ).filter( + table.pkgKey == pkgKey + ) + output = query.all() + except OperationalError: + return None + except SQLAlchemyError as err: + cnt += 1 + if cnt > RETRY_ATTEMPT: + raise + else: + time.sleep(0.1) + output = get_package_info(session, pkgKey, tablename) + + return output + + def get_co_packages(session, srcpkg_name): ''' Return the name of all the packages coming from the same source-package. From 505a0bb4514f679506f49f9af5bc26a84844f873 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 16 2015 08:49:31 +0000 Subject: [PATCH 3/3] Include the dependencies information in the json blob returned for a package --- diff --git a/mdapi/__init__.py b/mdapi/__init__.py index 4778127..5c45c45 100644 --- a/mdapi/__init__.py +++ b/mdapi/__init__.py @@ -105,6 +105,27 @@ def get_pkg(request): 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