Skip to content

Commit

Permalink
repoquery: Added -s/--source switch, test case and documentation for …
Browse files Browse the repository at this point in the history
…querying source rpm name
  • Loading branch information
pnemade authored and Jan Silhan committed Mar 10, 2015
1 parent 4060dcc commit 0f72f4c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/repoquery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ The following are mutually exclusive, i.e. at most one can be specified. If no q
``-l, --list``
Show list of files in the package.

``-s, --source``
Show package source RPM name.

``--obsoletes``
Display capabilities that the package obsoletes. Same as ``--qf "%{obsoletes}``.

Expand All @@ -103,6 +106,10 @@ Display requires of all ligttpd packages::

dnf repoquery --requires lighttpd

Display source rpm of ligttpd package::

dnf repoquery --source lighttpd

Display package name that owns the given file::

dnf repoquery --file /etc/lighttpd/lighttpd.conf
Expand Down
8 changes: 8 additions & 0 deletions plugins/repoquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def build_format_fn(opts):
return info_format
elif opts.queryfilelist:
return filelist_format
elif opts.querysourcerpm:
return sourcerpm_format
else:
return rpm2py_format(opts.queryformat).format

Expand All @@ -73,6 +75,9 @@ def info_format(pkg):
def filelist_format(pkg):
return "\n".join(pkg.files)

def sourcerpm_format(pkg):
return pkg.sourcerpm

def parse_arguments(args):
# Setup ArgumentParser to handle util
parser = dnfpluginscore.ArgumentParser(RepoQueryCommand.aliases[0])
Expand All @@ -99,6 +104,9 @@ def parse_arguments(args):
outform.add_argument('-l', "--list", dest='queryfilelist',
default=False, action='store_true',
help=_('show list of files in the package'))
outform.add_argument('-s', "--source", dest='querysourcerpm',
default=False, action='store_true',
help=_('show package source RPM name'))
outform.add_argument('--qf', "--queryformat", dest='queryformat',
default=QFORMAT_DEFAULT,
help=_('format for displaying found packages'))
Expand Down
7 changes: 7 additions & 0 deletions tests/test_repoquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
/var/foobar\
"""

EXPECTED_SOURCERPM_FORMAT = """\
foo-1.0.1-1.f20.src.rpm"""

class PkgStub(object):
def __init__(self):
Expand Down Expand Up @@ -97,6 +99,11 @@ def test_filelist(self):
self.assertEqual(repoquery.filelist_format(pkg),
EXPECTED_FILELIST_FORMAT)

class SourceRPMFormatTest(unittest.TestCase):
def test_info(self):
pkg = repoquery.PackageWrapper(PkgStub())
self.assertEqual(repoquery.sourcerpm_format(pkg),
EXPECTED_SOURCERPM_FORMAT)

class OutputTest(unittest.TestCase):
def test_output(self):
Expand Down

0 comments on commit 0f72f4c

Please sign in to comment.