From 610acd0c8c543bcb702b31bd83b024755ad1b138 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 16 2015 08:48:54 +0000 Subject: 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.