Skip to content

Commit

Permalink
repoquery: add -l option to list files contained in the package
Browse files Browse the repository at this point in the history
  • Loading branch information
pspacek authored and radekholy24 committed Feb 2, 2015
1 parent 6821df6 commit 057be72
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/repoquery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ The following are mutually exclusive, i.e. at most one can be specified. If no q
``-i, --info``
Show detailed information about the package.

``-l, --list``
Show list of files in the package.

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

Expand Down
7 changes: 7 additions & 0 deletions plugins/repoquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@
def build_format_fn(opts):
if opts.queryinfo:
return info_format
elif opts.queryfilelist:
return filelist_format
else:
return rpm2py_format(opts.queryformat).format


def info_format(pkg):
return QUERY_INFO.format(pkg)

def filelist_format(pkg):
return "\n".join(pkg.files)

def parse_arguments(args):
# Setup ArgumentParser to handle util
Expand All @@ -89,6 +93,9 @@ def parse_arguments(args):
outform.add_argument('-i', "--info", dest='queryinfo',
default=False, action='store_true',
help=_('show detailed information about the package'))
outform.add_argument('-l', "--list", dest='queryfilelist',
default=False, action='store_true',
help=_('show list of files in the package'))
outform.add_argument('--qf', "--queryformat", dest='queryformat',
default=QFORMAT_DEFAULT,
help=_('format for displaying found packages'))
Expand Down
13 changes: 13 additions & 0 deletions tests/test_repoquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
A desc.A desc.A desc.A desc.A desc.A desc.A desc.A desc.A desc.A
desc.A desc.A desc.A desc.A desc.A desc.A desc."""

EXPECTED_FILELIST_FORMAT = """\
/tmp/foobar
/var/foobar\
"""


class PkgStub(object):
def __init__(self):
Expand All @@ -57,6 +62,7 @@ def __init__(self):
self.summary = 'it.'
self.url = 'foorl.net'
self.version = '1.0.1'
self.files = ['/tmp/foobar', '/var/foobar']


class ArgParseTest(unittest.TestCase):
Expand All @@ -82,6 +88,13 @@ def test_info(self):
self.assertEqual(repoquery.info_format(pkg), EXPECTED_INFO_FORMAT)


class FilelistFormatTest(unittest.TestCase):
def test_filelist(self):
pkg = repoquery.PackageWrapper(PkgStub())
self.assertEqual(repoquery.filelist_format(pkg),
EXPECTED_FILELIST_FORMAT)


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

0 comments on commit 057be72

Please sign in to comment.