#39 Implement a new endpoint to query package by their source package name
Merged 8 years ago by pingou. Opened 8 years ago by pingou.

file modified
+29 -6
@@ -56,10 +56,13 @@ 

  

  

  @asyncio.coroutine

- def _get_pkg(branch, name, action=None):

+ 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]:
@@ -80,11 +83,14 @@ 

          with file_lock.FileFlock(dbfile + '.lock'):

              session = yield from mdapilib.create_session(

                  'sqlite:///%s' % dbfile)

-             if action:

-                 pkg = yield from mdapilib.get_package_by(

-                     session, action, name)

-             else:

-                 pkg = yield from mdapilib.get_package(session, name)

+             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
@@ -184,6 +190,22 @@ 

  

  

  @asyncio.coroutine

+ def get_src_pkg(request):

+     branch = request.match_info.get('branch')

+     pretty = _get_pretty(request)

+     name = request.match_info.get('name')

+     pkg, repotype = yield from _get_pkg(branch, srcname=name)

+ 

+     output = yield from _expand_pkg_info(pkg, branch, repotype)

+ 

+     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')

+ 

+ @asyncio.coroutine

  def get_pkg_files(request):

      branch = request.match_info.get('branch')

      name = request.match_info.get('name')
@@ -343,6 +365,7 @@ 

          ('/', index),

          ('/branches', list_branches),

          ('/{branch}/pkg/{name}', get_pkg),

+         ('/{branch}/srcpkg/{name}', get_src_pkg),

  

          ('/{branch}/provides/{name}', get_provides),

          ('/{branch}/requires/{name}', get_requires),

file modified
+10
@@ -83,6 +83,16 @@ 

      <a href="$PREFIX/rawhide/pkg/kernel">/rawhide/pkg/kernel</a>

  

  

+ You can also retrieve information about a specific package on a specific

+ branch via the name of its source package by querying:

+ 

+     /{branch}/srcpkg/{package name}

+ 

+ So for example, for the python-natsort in rawhide that only exists as src.rpm:

+ 

+     <a href="$PREFIX/rawhide/srcpkg/python-natsort">/rawhide/srcpkg/python-natsort</a>

+ 

+ 

  Retrieve the list of files in a package

  ---------------------------------------

  

file modified
+28
@@ -101,6 +101,34 @@ 

  

      return output

  

+ 

+ @asyncio.coroutine

+ def get_package_by_src(session, pkg_name):

+     ''' Return information about a package, if we can find it.

+     '''

+     cnt = 0

+     try:

+         pkg = session.query(

+             primary.Package

+         ).filter(

+             primary.Package.rpm_sourcerpm.like('{}%'.format(pkg_name))

+         ).order_by(

+             primary.Package.epoch.desc(),

+             primary.Package.version.desc(),

+             primary.Package.release.desc(),

+         )

+         output = pkg.first()

+     except SQLAlchemyError as err:

+         cnt += 1

+         if cnt > RETRY_ATTEMPT:

+             raise

+         else:

+             time.sleep(0.1)

+             output = yield from get_package(session, pkg_name)

+ 

+     return output

+ 

+ 

  @asyncio.coroutine

  def get_package_by(session, tablename, key, cnt=None):

      ''' Return information the package providing the provides, if we can find it.

no initial comment

rebased

8 years ago

1 new commit added

  • Also raise an error if both package name and source package name are set
8 years ago

if works, then looks good to me ;)

Pull-Request has been merged by pingou

8 years ago