From f831b09785d1448f7f9ef02709dda07c65499ca8 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 22 2015 11:50:56 +0000 Subject: Include the 'co-package' in the output of the package endpoint Co-packages are packages that are built from the same source-rpm, this can be the sub-packages or the main-package + the other sub-packages --- diff --git a/mdapi/__init__.py b/mdapi/__init__.py index 737575e..09b0425 100644 --- a/mdapi/__init__.py +++ b/mdapi/__init__.py @@ -33,12 +33,17 @@ import lib as mdapilib @asyncio.coroutine def get_pkg(request): name = request.match_info.get('name', None) - session = mdapilib.create_session('sqlite:////var/tmp/rawhide-primary.sqlite') + session = mdapilib.create_session('sqlite:////var/tmp/20151022-rawhide-primary.sqlite') pkg = mdapilib.get_package(session, name) session.close() if not pkg: raise web.HTTPNotFound() - return web.Response(body=json.dumps(pkg.to_json()).encode('utf-8')) + output = pkg.to_json() + output['co-packages'] = [ + cpkg.name + for cpkg in mdapilib.get_co_packages(session, pkg.rpm_sourcerpm) + ] + return web.Response(body=json.dumps(output).encode('utf-8')) @asyncio.coroutine diff --git a/mdapi/lib.py b/mdapi/lib.py index 8f9dfbe..5eef87b 100644 --- a/mdapi/lib.py +++ b/mdapi/lib.py @@ -63,6 +63,18 @@ def get_package(session, pkg_name): return pkg.first() +def get_co_packages(session, srcpkg_name): + ''' Return the name of all the packages coming from the same + source-package. + ''' + pkg = session.query( + primary.Package + ).filter( + primary.Package.rpm_sourcerpm==srcpkg_name + ) + return pkg.all() + + def get_files(session, pkg_id): ''' Return the list of all the files in a package given its key. '''