182: Renamed plublic.cmd base class to Command

This commit is contained in:
Jason Gerard DeRose 2008-08-15 19:49:04 +00:00
parent 99450358af
commit b0ec8fe551
5 changed files with 38 additions and 34 deletions

View File

@ -43,10 +43,10 @@ def from_cli(cli_name):
return str(cli_name).replace('-', '_')
class help(public.cmd):
class help(public.Command):
'display help on command'
def __call__(self, key):
if from_cli(key) not in self.api.cmd:
if from_cli(key) not in self.api.Command:
print 'help: no such command %r' % key
sys.exit(2)
print 'Help on command %r:' % key
@ -65,7 +65,7 @@ class CLI(object):
def print_commands(self):
print 'Available Commands:'
for cmd in self.api.cmd():
for cmd in self.api.Command():
print ' %s %s' % (
to_cli(cmd.name).ljust(self.mcl),
cmd.doc,
@ -84,7 +84,7 @@ class CLI(object):
api.register(help)
api.finalize()
def d_iter():
for cmd in api.cmd():
for cmd in api.Command():
yield (to_cli(cmd.name), cmd)
self.__d = dict(d_iter())

View File

@ -27,11 +27,11 @@ from ipalib.api import api
# Hypothetical functional commands (not associated with any object):
class krbtest(public.cmd):
class krbtest(public.Command):
'Test your Kerberos ticket'
api.register(krbtest)
class discover(public.cmd):
class discover(public.Command):
'Discover IPA servers on network'
api.register(discover)

View File

@ -127,7 +127,7 @@ class option(plugable.Plugin):
return None
class cmd(plugable.Plugin):
class Command(plugable.Plugin):
__public__ = frozenset((
'normalize',
'default',
@ -167,7 +167,7 @@ class cmd(plugable.Plugin):
Returns the NameSpace containing the option proxy objects.
"""
if self.__options is None:
object.__setattr__(self, '_cmd__options',
object.__setattr__(self, '_Command__options',
plugable.NameSpace(self.get_options()),
)
return self.__options
@ -294,11 +294,11 @@ class attr(plugable.Plugin):
self.__obj = api.obj[self.obj_name]
class mthd(attr, cmd):
__public__ = attr.__public__.union(cmd.__public__)
class mthd(attr, Command):
__public__ = attr.__public__.union(Command.__public__)
def get_options(self):
for proxy in cmd.get_options(self):
for proxy in Command.get_options(self):
yield proxy
if self.obj is not None and self.obj.prop is not None:
for proxy in self.obj.prop():
@ -314,4 +314,4 @@ class prop(attr, option):
class PublicAPI(plugable.API):
def __init__(self):
super(PublicAPI, self).__init__(cmd, obj, mthd, prop)
super(PublicAPI, self).__init__(Command, obj, mthd, prop)

View File

@ -46,7 +46,7 @@ def test_from_cli():
def get_cmd_name(i):
return 'cmd_%d' % i
class DummyCmd(object):
class DummyCommand(object):
def __init__(self, name):
self.__name = name
@ -60,11 +60,11 @@ class DummyAPI(object):
def __get_cmd(self):
return self.__cmd
cmd = property(__get_cmd)
Command = property(__get_cmd)
def __cmd_iter(self, cnt):
for i in xrange(cnt):
yield DummyCmd(get_cmd_name(i))
yield DummyCommand(get_cmd_name(i))
def finalize(self):
pass
@ -114,7 +114,7 @@ class test_CLI(ClassChecker):
"""
cnt = 100
api = DummyAPI(cnt)
len(api.cmd) == cnt
len(api.Command) == cnt
o = self.cls(api)
assert o.mcl is None
o.finalize()
@ -126,10 +126,10 @@ class test_CLI(ClassChecker):
"""
cnt = 25
api = DummyAPI(cnt)
assert len(api.cmd) == cnt
assert len(api.Command) == cnt
o = self.cls(api)
o.finalize()
for cmd in api.cmd():
for cmd in api.Command():
key = cli.to_cli(cmd.name)
assert key in o
assert o[key] is cmd

View File

@ -159,9 +159,9 @@ class test_option(ClassChecker):
class test_cmd(ClassChecker):
"""
Tests the `public.cmd` class.
Tests the `public.Command` class.
"""
_cls = public.cmd
_cls = public.Command
def get_subcls(self):
class my_option(public.option):
@ -188,7 +188,7 @@ class test_cmd(ClassChecker):
def test_get_options(self):
"""
Tests the `public.cmd.get_options` method.
Tests the `public.Command.get_options` method.
"""
assert list(self.cls().get_options()) == []
sub = self.subcls()
@ -200,7 +200,7 @@ class test_cmd(ClassChecker):
def test_options(self):
"""
Tests the `public.cmd.options` property.
Tests the `public.Command.options` property.
"""
assert 'options' in self.cls.__public__ # Public
sub = self.subcls()
@ -216,7 +216,7 @@ class test_cmd(ClassChecker):
def test_normalize(self):
"""
Tests the `public.cmd.normalize` method.
Tests the `public.Command.normalize` method.
"""
assert 'normalize' in self.cls.__public__ # Public
kw = dict(
@ -230,7 +230,7 @@ class test_cmd(ClassChecker):
def test_default(self):
"""
Tests the `public.cmd.default` method.
Tests the `public.Command.default` method.
"""
assert 'default' in self.cls.__public__ # Public
no_fill = dict(
@ -251,7 +251,7 @@ class test_cmd(ClassChecker):
def test_validate(self):
"""
Tests the `public.cmd.validate` method.
Tests the `public.Command.validate` method.
"""
assert 'validate' in self.cls.__public__ # Public
@ -281,7 +281,7 @@ class test_cmd(ClassChecker):
def test_execute(self):
"""
Tests the `public.cmd.execute` method.
Tests the `public.Command.execute` method.
"""
assert 'execute' in self.cls.__public__ # Public
@ -322,8 +322,8 @@ class test_mthd(ClassChecker):
_cls = public.mthd
def test_class(self):
assert self.cls.__bases__ == (public.attr, public.cmd)
assert self.cls.implements(public.cmd)
assert self.cls.__bases__ == (public.attr, public.Command)
assert self.cls.implements(public.Command)
def get_subcls(self):
class option0(public.option):
@ -338,10 +338,14 @@ class test_mthd(ClassChecker):
__prop = None
def __get_prop(self):
if self.__prop is None:
self.__prop = (
plugable.PluginProxy(public.prop, example_prop0(), 'attr_name'),
plugable.PluginProxy(public.prop, example_prop1(), 'attr_name'),
)
self.__prop = plugable.NameSpace([
plugable.PluginProxy(
public.prop, example_prop0(), 'attr_name'
),
plugable.PluginProxy(
public.prop, example_prop1(), 'attr_name'
),
])
return self.__prop
prop = property(__get_prop)
class noun_verb(self.cls):
@ -377,11 +381,11 @@ def test_PublicAPI():
api = cls()
class cmd1(public.cmd):
class cmd1(public.Command):
pass
api.register(cmd1)
class cmd2(public.cmd):
class cmd2(public.Command):
pass
api.register(cmd2)