Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 54 additions & 48 deletions lib/rift/Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,58 @@ def action_sync(args, config):
)
synchronizer.run()

def action_query(args, config):
"""Action for 'query' command."""
staff, modules = staff_modules(config)
pkglist = sorted(Package.list(config, staff, modules, args.packages),
key=attrgetter('name'))

tbl = TextTable()
tbl.fmt = args.fmt or '%name %module %maintainers %version %release '\
'%modulemanager'
tbl.show_header = args.headers
tbl.color = True

supported_keys = set(('name', 'module', 'origin', 'reason', 'tests',
'version', 'arch', 'release', 'changelogname',
'changelogtime', 'maintainers', 'modulemanager',
'buildrequires'))
diff_keys = set(tbl.pattern_fields()) - supported_keys
if diff_keys:
raise RiftError(f"Unknown placeholder(s): {', '.join(diff_keys)} "
f"(supported keys are: {', '.join(supported_keys)})")

for pkg in pkglist:
logging.debug('Loading package %s', pkg.name)
try:
pkg.load()
spec = Spec(config=config)
if args.spec:
spec.filepath = pkg.specfile
spec.load()
except RiftError as exp:
logging.error("%s: %s", pkg.name, str(exp))
continue

date = str(time.strftime("%Y-%m-%d", time.localtime(spec.changelog_time)))
modulemanager = staff.get(modules.get(pkg.module).get('manager')[0])
tbl.append({'name': pkg.name,
'module': pkg.module,
'origin': pkg.origin,
'reason': pkg.reason,
'tests': str(len(list(pkg.tests()))),
'version': spec.version,
'arch': spec.arch,
'release': spec.release,
'changelogname': spec.changelog_name,
'changelogtime': date,
'buildrequires': spec.buildrequires,
'modulemanager': modulemanager['email'],
'maintainers': ', '.join(pkg.maintainers)})
print(tbl)

return 0

def create_staging_repo(config):
"""
Create and return staging temporary repository with a 2-tuple containing
Expand Down Expand Up @@ -1104,55 +1156,9 @@ def action(config, args):
elif args.command == 'validdiff':
return action_validdiff(args, config)

# QUERY
elif args.command == 'query':

staff, modules = staff_modules(config)
pkglist = sorted(Package.list(config, staff, modules, args.packages),
key=attrgetter('name'))

tbl = TextTable()
tbl.fmt = args.fmt or '%name %module %maintainers %version %release '\
'%modulemanager'
tbl.show_header = args.headers
tbl.color = True

supported_keys = set(('name', 'module', 'origin', 'reason', 'tests',
'version', 'arch', 'release', 'changelogname',
'changelogtime', 'maintainers', 'modulemanager',
'buildrequires'))
diff_keys = set(tbl.pattern_fields()) - supported_keys
if diff_keys:
raise RiftError(f"Unknown placeholder(s): {', '.join(diff_keys)} "
f"(supported keys are: {', '.join(supported_keys)})")

for pkg in pkglist:
logging.debug('Loading package %s', pkg.name)
try:
pkg.load()
spec = Spec(config=config)
if args.spec:
spec.filepath = pkg.specfile
spec.load()
except RiftError as exp:
logging.error("%s: %s", pkg.name, str(exp))
continue

date = str(time.strftime("%Y-%m-%d", time.localtime(spec.changelog_time)))
modulemanager = staff.get(modules.get(pkg.module).get('manager')[0])
tbl.append({'name': pkg.name,
'module': pkg.module,
'origin': pkg.origin,
'reason': pkg.reason,
'tests': str(len(list(pkg.tests()))),
'version': spec.version,
'arch': spec.arch,
'release': spec.release,
'changelogname': spec.changelog_name,
'changelogtime': date,
'buildrequires': spec.buildrequires,
'modulemanager': modulemanager['email'],
'maintainers': ', '.join(pkg.maintainers)})
print(tbl)
return action_query(args, config)

elif args.command == 'changelog':

Expand Down
70 changes: 57 additions & 13 deletions tests/Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from unittest.mock import patch, Mock
import subprocess
from io import StringIO
import textwrap

from TestUtils import (
make_temp_dir, RiftTestCase, RiftProjectTestCase
Expand Down Expand Up @@ -44,22 +45,11 @@ def test_main_version(self):
self.assert_except(SystemExit, "0", main, ['--version'])


class ControllerProjectTest(RiftProjectTestCase):
class ControllerProjectActionQueryTest(RiftProjectTestCase):
"""
Tests class for Controller
Tests class for Controller action query
"""

def _check_qemuuserstatic(self):
"""Skip the test if none qemu-$arch-static executable is found for all
architectures declared in project configuration."""
if not any(
[
os.path.exists(f"/usr/bin/qemu-{arch}-static")
for arch in self.config.get('arch')
]
):
self.skipTest("qemu-user-static is not available")

def test_action_query(self):
"""simple 'rift query' is ok """
self.assertEqual(main(['query']), 0)
Expand All @@ -77,6 +67,60 @@ def test_action_query_on_bad_pkg(self):
self.make_pkg(name='pkg2', metadata={})
self.assertEqual(main(['query']), 0)

@patch('sys.stdout', new_callable=StringIO)
def test_action_query_output_default(self, mock_stdout):
self.make_pkg(name="pkg1")
self.make_pkg(name="pkg2", version='2.1', release='3')
self.assertEqual(main(['query']), 0)
self.assertIn(
"NAME MODULE MAINTAINERS VERSION RELEASE MODULEMANAGER",
mock_stdout.getvalue())
self.assertIn(textwrap.dedent("""
---- ------ ----------- ------- ------- -------------
pkg1 Great module Myself 1.0 1 [email protected]
pkg2 Great module Myself 2.1 3 [email protected]
"""),
mock_stdout.getvalue())

@patch('sys.stdout', new_callable=StringIO)
def test_action_query_output_format(self, mock_stdout):
self.make_pkg(name="pkg1")
self.make_pkg(name="pkg2", version='2.1', release='3')
self.assertEqual(
main([
'query', '--format',
'%name %module %origin %reason %tests %version %arch %release '
'%changelogname %changelogtime %maintainers %modulemanager '
'%buildrequires']), 0)
self.assertIn(
"NAME MODULE ORIGIN REASON TESTS VERSION ARCH "
"RELEASE CHANGELOGNAME CHANGELOGTIME "
"MAINTAINERS MODULEMANAGER BUILDREQUIRES",
mock_stdout.getvalue())
self.assertIn(textwrap.dedent("""
---- ------ ------ ------ ----- ------- ---- ------- ------------- ------------- ----------- ------------- -------------
pkg1 Great module Vendor Missing feature 0 1.0 noarch 1 Myself <[email protected]> 1.0-1 2019-02-26 Myself [email protected] br-package
pkg2 Great module Vendor Missing feature 0 2.1 noarch 3 Myself <[email protected]> 2.1-3 2019-02-26 Myself [email protected] br-package
"""),
mock_stdout.getvalue())


class ControllerProjectTest(RiftProjectTestCase):
"""
Tests class for Controller
"""

def _check_qemuuserstatic(self):
"""Skip the test if none qemu-$arch-static executable is found for all
architectures declared in project configuration."""
if not any(
[
os.path.exists(f"/usr/bin/qemu-{arch}-static")
for arch in self.config.get('arch')
]
):
self.skipTest("qemu-user-static is not available")

@patch('rift.Controller.remove_packages')
@patch('rift.Controller.validate_pkgs')
@patch('rift.Controller.get_packages_from_patch')
Expand Down