Merge "Remove commandmanager subclass"
This commit is contained in:
commit
5b65b5f000
@ -3,7 +3,7 @@ amqp==2.1.1
|
||||
appdirs==1.3.0
|
||||
bandit==1.4.0
|
||||
cachetools==2.0.0
|
||||
cliff==2.8.0
|
||||
cliff==3.2.0
|
||||
cmd2==0.8.0
|
||||
contextlib2==0.4.0
|
||||
coverage==4.0
|
||||
|
@ -13,46 +13,9 @@
|
||||
# under the License.
|
||||
#
|
||||
|
||||
"""Modify cliff.CommandManager"""
|
||||
|
||||
import cliff.commandmanager
|
||||
import pkg_resources
|
||||
|
||||
|
||||
class CommandManager(cliff.commandmanager.CommandManager):
|
||||
"""Add additional functionality to cliff.CommandManager
|
||||
|
||||
Load additional command groups after initialization
|
||||
Add _command_group() methods
|
||||
"""
|
||||
|
||||
def __init__(self, namespace, convert_underscores=True):
|
||||
self.group_list = []
|
||||
super(CommandManager, self).__init__(namespace, convert_underscores)
|
||||
|
||||
def load_commands(self, namespace):
|
||||
self.group_list.append(namespace)
|
||||
return super(CommandManager, self).load_commands(namespace)
|
||||
|
||||
def add_command_group(self, group=None):
|
||||
"""Adds another group of command entrypoints"""
|
||||
if group:
|
||||
self.load_commands(group)
|
||||
|
||||
def get_command_groups(self):
|
||||
"""Returns a list of the loaded command groups"""
|
||||
return self.group_list
|
||||
|
||||
def get_command_names(self, group=None):
|
||||
"""Returns a list of commands loaded for the specified group"""
|
||||
group_list = []
|
||||
if group is not None:
|
||||
for ep in pkg_resources.iter_entry_points(group):
|
||||
cmd_name = (
|
||||
ep.name.replace('_', ' ')
|
||||
if self.convert_underscores
|
||||
else ep.name
|
||||
)
|
||||
group_list.append(cmd_name)
|
||||
return group_list
|
||||
return list(self.commands.keys())
|
||||
"""Noop subclass for transition purposes."""
|
||||
pass
|
||||
|
@ -23,6 +23,7 @@ import traceback
|
||||
|
||||
from cliff import app
|
||||
from cliff import command
|
||||
from cliff import commandmanager
|
||||
from cliff import complete
|
||||
from cliff import help
|
||||
from oslo_utils import importutils
|
||||
@ -30,7 +31,6 @@ from oslo_utils import strutils
|
||||
|
||||
from osc_lib.cli import client_config as cloud_config
|
||||
from osc_lib import clientmanager
|
||||
from osc_lib.command import commandmanager
|
||||
from osc_lib.command import timing
|
||||
from osc_lib import exceptions as exc
|
||||
from osc_lib.i18n import _
|
||||
|
@ -1,108 +0,0 @@
|
||||
# Copyright 2012-2013 OpenStack Foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
from unittest import mock
|
||||
|
||||
from osc_lib.command import commandmanager
|
||||
from osc_lib.tests import utils
|
||||
|
||||
|
||||
class FakeCommand(object):
|
||||
|
||||
@classmethod
|
||||
def load(cls):
|
||||
return cls
|
||||
|
||||
def __init__(self):
|
||||
return
|
||||
|
||||
|
||||
FAKE_CMD_ONE = FakeCommand
|
||||
FAKE_CMD_TWO = FakeCommand
|
||||
FAKE_CMD_ALPHA = FakeCommand
|
||||
FAKE_CMD_BETA = FakeCommand
|
||||
|
||||
|
||||
class FakeCommandManager(commandmanager.CommandManager):
|
||||
commands = {}
|
||||
|
||||
def load_commands(self, namespace):
|
||||
if namespace == 'test':
|
||||
self.commands['one'] = FAKE_CMD_ONE
|
||||
self.commands['two'] = FAKE_CMD_TWO
|
||||
self.group_list.append(namespace)
|
||||
elif namespace == 'greek':
|
||||
self.commands['alpha'] = FAKE_CMD_ALPHA
|
||||
self.commands['beta'] = FAKE_CMD_BETA
|
||||
self.group_list.append(namespace)
|
||||
|
||||
|
||||
class TestCommandManager(utils.TestCase):
|
||||
|
||||
def test_add_command_group(self):
|
||||
mgr = FakeCommandManager('test')
|
||||
|
||||
# Make sure add_command() still functions
|
||||
mock_cmd_one = mock.Mock()
|
||||
mgr.add_command('mock', mock_cmd_one)
|
||||
cmd_mock, name, args = mgr.find_command(['mock'])
|
||||
self.assertEqual(mock_cmd_one, cmd_mock)
|
||||
|
||||
# Find a command added in initialization
|
||||
cmd_one, name, args = mgr.find_command(['one'])
|
||||
self.assertEqual(FAKE_CMD_ONE, cmd_one)
|
||||
|
||||
# Load another command group
|
||||
mgr.add_command_group('greek')
|
||||
|
||||
# Find a new command
|
||||
cmd_alpha, name, args = mgr.find_command(['alpha'])
|
||||
self.assertEqual(FAKE_CMD_ALPHA, cmd_alpha)
|
||||
|
||||
# Ensure that the original commands were not overwritten
|
||||
cmd_two, name, args = mgr.find_command(['two'])
|
||||
self.assertEqual(FAKE_CMD_TWO, cmd_two)
|
||||
|
||||
def test_get_command_groups(self):
|
||||
mgr = FakeCommandManager('test')
|
||||
|
||||
# Make sure add_command() still functions
|
||||
mock_cmd_one = mock.Mock()
|
||||
mgr.add_command('mock', mock_cmd_one)
|
||||
cmd_mock, name, args = mgr.find_command(['mock'])
|
||||
self.assertEqual(mock_cmd_one, cmd_mock)
|
||||
|
||||
# Load another command group
|
||||
mgr.add_command_group('greek')
|
||||
|
||||
gl = mgr.get_command_groups()
|
||||
self.assertEqual(['test', 'greek'], gl)
|
||||
|
||||
def test_get_command_names(self):
|
||||
mock_cmd_one = mock.Mock()
|
||||
mock_cmd_one.name = 'one'
|
||||
mock_cmd_two = mock.Mock()
|
||||
mock_cmd_two.name = 'cmd two'
|
||||
mock_pkg_resources = mock.Mock(
|
||||
return_value=[mock_cmd_one, mock_cmd_two],
|
||||
)
|
||||
with mock.patch(
|
||||
'pkg_resources.iter_entry_points',
|
||||
mock_pkg_resources,
|
||||
) as iter_entry_points:
|
||||
mgr = commandmanager.CommandManager('test')
|
||||
iter_entry_points.assert_called_once_with('test')
|
||||
cmds = mgr.get_command_names('test')
|
||||
self.assertEqual(['one', 'cmd two'], cmds)
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
upgrade:
|
||||
- |
|
||||
The ``osc_lib.command.commandmanager.CommandManager`` class is a
|
||||
direct subclass of ``cliff.commandmanager.CommandManager``. The extra
|
||||
osc_lib functionality has been shifted upstream into cliff.
|
@ -3,7 +3,7 @@
|
||||
# process, which may cause wedges in the gate later.
|
||||
pbr!=2.1.0,>=2.0.0 # Apache-2.0
|
||||
|
||||
cliff!=2.9.0,>=2.8.0 # Apache-2.0
|
||||
cliff>=3.2.0 # Apache-2.0
|
||||
keystoneauth1>=3.14.0 # Apache-2.0
|
||||
openstacksdk>=0.15.0 # Apache-2.0
|
||||
oslo.i18n>=3.15.3 # Apache-2.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user