mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
255: CLI help, console commands now subclass from public.Application; other tweeking to make CLI utilize Application
This commit is contained in:
parent
e1f8619d4a
commit
ab81ca56fd
@ -61,4 +61,5 @@ api = plugable.API(
|
||||
public.Object,
|
||||
public.Method,
|
||||
public.Property,
|
||||
public.Application,
|
||||
)
|
||||
|
@ -44,7 +44,7 @@ def from_cli(cli_name):
|
||||
return str(cli_name).replace('-', '_')
|
||||
|
||||
|
||||
class help(public.Command):
|
||||
class help(public.Application):
|
||||
'Display help on command'
|
||||
def __call__(self, key):
|
||||
if from_cli(key) not in self.api.Command:
|
||||
@ -53,7 +53,7 @@ class help(public.Command):
|
||||
print 'Help on command %r:' % key
|
||||
|
||||
|
||||
class console(public.Command):
|
||||
class console(public.Application):
|
||||
'Start IPA Interactive Python Console'
|
||||
|
||||
def __call__(self):
|
||||
@ -95,10 +95,16 @@ class CLI(object):
|
||||
api.register(help)
|
||||
api.register(console)
|
||||
api.finalize()
|
||||
def d_iter():
|
||||
for cmd in api.Command():
|
||||
yield (to_cli(cmd.name), cmd)
|
||||
self.__d = dict(d_iter())
|
||||
for a in api.Application():
|
||||
a.set_application(self)
|
||||
self.build_map()
|
||||
|
||||
def build_map(self):
|
||||
assert self.__d is None
|
||||
self.__d = dict(
|
||||
(c.name.replace('_', '-'), c) for c in self.api.Command()
|
||||
)
|
||||
|
||||
|
||||
def run(self):
|
||||
self.finalize()
|
||||
|
@ -396,6 +396,7 @@ class Application(Command):
|
||||
|
||||
__public__ = frozenset((
|
||||
'application',
|
||||
'set_application'
|
||||
)).union(Command.__public__)
|
||||
__application = None
|
||||
|
||||
@ -404,7 +405,9 @@ class Application(Command):
|
||||
Returns external ``application`` object.
|
||||
"""
|
||||
return self.__application
|
||||
def __set_application(self, application):
|
||||
application = property(__get_application)
|
||||
|
||||
def set_application(self, application):
|
||||
"""
|
||||
Sets the external application object to ``application``.
|
||||
"""
|
||||
@ -418,4 +421,3 @@ class Application(Command):
|
||||
)
|
||||
object.__setattr__(self, '_Application__application', application)
|
||||
assert self.application is application
|
||||
application = property(__get_application, __set_application)
|
||||
|
@ -75,6 +75,7 @@ class DummyAPI(object):
|
||||
|
||||
|
||||
|
||||
|
||||
class test_CLI(ClassChecker):
|
||||
"""
|
||||
Tests the `cli.CLI` class.
|
||||
@ -117,7 +118,7 @@ class test_CLI(ClassChecker):
|
||||
len(api.Command) == cnt
|
||||
o = self.cls(api)
|
||||
assert o.mcl is None
|
||||
o.finalize()
|
||||
o.build_map()
|
||||
assert o.mcl == 6 # len('cmd_99')
|
||||
|
||||
def test_dict(self):
|
||||
@ -128,7 +129,7 @@ class test_CLI(ClassChecker):
|
||||
api = DummyAPI(cnt)
|
||||
assert len(api.Command) == cnt
|
||||
o = self.cls(api)
|
||||
o.finalize()
|
||||
o.build_map()
|
||||
for cmd in api.Command():
|
||||
key = cli.to_cli(cmd.name)
|
||||
assert key in o
|
||||
|
@ -707,19 +707,20 @@ class test_Application(ClassChecker):
|
||||
Tests the `public.Application.application` property.
|
||||
"""
|
||||
assert 'application' in self.cls.__public__ # Public
|
||||
assert 'set_application' in self.cls.__public__ # Public
|
||||
app = 'The external application'
|
||||
class example(self.cls):
|
||||
'A subclass'
|
||||
for o in (self.cls(), example()):
|
||||
assert o.application is None
|
||||
e = raises(TypeError, setattr, o, 'application', None)
|
||||
assert read_only(o, 'application') is None
|
||||
e = raises(TypeError, o.set_application, None)
|
||||
assert str(e) == (
|
||||
'%s.application cannot be None' % o.__class__.__name__
|
||||
)
|
||||
o.application = app
|
||||
assert o.application is app
|
||||
e = raises(AttributeError, setattr, o, 'application', app)
|
||||
o.set_application(app)
|
||||
assert read_only(o, 'application') is app
|
||||
e = raises(AttributeError, o.set_application, app)
|
||||
assert str(e) == (
|
||||
'%s.application can only be set once' % o.__class__.__name__
|
||||
)
|
||||
assert o.application is app
|
||||
assert read_only(o, 'application') is app
|
||||
|
Loading…
Reference in New Issue
Block a user