mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Removed util.add_global_options() and frontend.Application
This commit is contained in:
@@ -866,7 +866,7 @@ freeIPA.org:
|
|||||||
import os
|
import os
|
||||||
import plugable
|
import plugable
|
||||||
from backend import Backend
|
from backend import Backend
|
||||||
from frontend import Command, LocalOrRemote, Application
|
from frontend import Command, LocalOrRemote
|
||||||
from frontend import Object, Method, Property
|
from frontend import Object, Method, Property
|
||||||
from crud import Create, Retrieve, Update, Delete, Search
|
from crud import Create, Retrieve, Update, Delete, Search
|
||||||
from parameters import DefaultFrom, Bool, Flag, Int, Float, Bytes, Str, Password,List
|
from parameters import DefaultFrom, Bool, Flag, Int, Float, Bytes, Str, Password,List
|
||||||
@@ -900,13 +900,9 @@ def create_api(mode='dummy'):
|
|||||||
|
|
||||||
- `frontend.Property`
|
- `frontend.Property`
|
||||||
|
|
||||||
- `frontend.Application`
|
|
||||||
|
|
||||||
- `backend.Backend`
|
- `backend.Backend`
|
||||||
"""
|
"""
|
||||||
api = plugable.API(
|
api = plugable.API(Command, Object, Method, Property, Backend)
|
||||||
Command, Object, Method, Property, Application, Backend
|
|
||||||
)
|
|
||||||
if mode is not None:
|
if mode is not None:
|
||||||
api.env.mode = mode
|
api.env.mode = mode
|
||||||
assert mode != 'production'
|
assert mode != 'production'
|
||||||
|
|||||||
@@ -612,7 +612,7 @@ class help(frontend.Command):
|
|||||||
print ' %s %s' % (to_cli(c.name).ljust(mcl), c.doc)
|
print ' %s %s' % (to_cli(c.name).ljust(mcl), c.doc)
|
||||||
|
|
||||||
|
|
||||||
class console(frontend.Application):
|
class console(frontend.Command):
|
||||||
"""Start the IPA interactive Python console."""
|
"""Start the IPA interactive Python console."""
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@@ -622,7 +622,7 @@ class console(frontend.Application):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class show_api(frontend.Application):
|
class show_api(frontend.Command):
|
||||||
'Show attributes on dynamic API object'
|
'Show attributes on dynamic API object'
|
||||||
|
|
||||||
takes_args = ('namespaces*',)
|
takes_args = ('namespaces*',)
|
||||||
|
|||||||
@@ -1015,44 +1015,3 @@ class Property(Attribute):
|
|||||||
attr = getattr(self, name)
|
attr = getattr(self, name)
|
||||||
if is_rule(attr):
|
if is_rule(attr):
|
||||||
yield attr
|
yield attr
|
||||||
|
|
||||||
|
|
||||||
class Application(Command):
|
|
||||||
"""
|
|
||||||
Base class for commands register by an external application.
|
|
||||||
|
|
||||||
Special commands that only apply to a particular application built atop
|
|
||||||
`ipalib` should subclass from ``Application``.
|
|
||||||
|
|
||||||
Because ``Application`` subclasses from `Command`, plugins that subclass
|
|
||||||
from ``Application`` with be available in both the ``api.Command`` and
|
|
||||||
``api.Application`` namespaces.
|
|
||||||
"""
|
|
||||||
|
|
||||||
__public__ = frozenset((
|
|
||||||
'application',
|
|
||||||
'set_application'
|
|
||||||
)).union(Command.__public__)
|
|
||||||
__application = None
|
|
||||||
|
|
||||||
def __get_application(self):
|
|
||||||
"""
|
|
||||||
Returns external ``application`` object.
|
|
||||||
"""
|
|
||||||
return self.__application
|
|
||||||
application = property(__get_application)
|
|
||||||
|
|
||||||
def set_application(self, application):
|
|
||||||
"""
|
|
||||||
Sets the external application object to ``application``.
|
|
||||||
"""
|
|
||||||
if self.__application is not None:
|
|
||||||
raise AttributeError(
|
|
||||||
'%s.application can only be set once' % self.name
|
|
||||||
)
|
|
||||||
if application is None:
|
|
||||||
raise TypeError(
|
|
||||||
'%s.application cannot be None' % self.name
|
|
||||||
)
|
|
||||||
object.__setattr__(self, '_Application__application', application)
|
|
||||||
assert self.application is application
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ Various utility functions.
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import imp
|
import imp
|
||||||
import optparse
|
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
import krbV
|
import krbV
|
||||||
@@ -95,28 +94,6 @@ def import_plugins_subpackage(name):
|
|||||||
__import__(full_name)
|
__import__(full_name)
|
||||||
|
|
||||||
|
|
||||||
def add_global_options(parser=None):
|
|
||||||
"""
|
|
||||||
Add global options to an optparse.OptionParser instance.
|
|
||||||
"""
|
|
||||||
if parser is None:
|
|
||||||
parser = optparse.OptionParser()
|
|
||||||
parser.disable_interspersed_args()
|
|
||||||
parser.add_option('-e', dest='env', metavar='KEY=VAL', action='append',
|
|
||||||
help='Set environment variable KEY to VAL',
|
|
||||||
)
|
|
||||||
parser.add_option('-c', dest='conf', metavar='FILE',
|
|
||||||
help='Load configuration from FILE',
|
|
||||||
)
|
|
||||||
parser.add_option('-d', '--debug', action='store_true',
|
|
||||||
help='Produce full debuging output',
|
|
||||||
)
|
|
||||||
parser.add_option('-v', '--verbose', action='store_true',
|
|
||||||
help='Produce more verbose output',
|
|
||||||
)
|
|
||||||
return parser
|
|
||||||
|
|
||||||
|
|
||||||
class LogFormatter(logging.Formatter):
|
class LogFormatter(logging.Formatter):
|
||||||
"""
|
"""
|
||||||
Log formatter that uses UTC for all timestamps.
|
Log formatter that uses UTC for all timestamps.
|
||||||
|
|||||||
@@ -893,40 +893,3 @@ class test_Property(ClassChecker):
|
|||||||
assert isinstance(param, parameters.Str)
|
assert isinstance(param, parameters.Str)
|
||||||
assert param.name == 'givenname'
|
assert param.name == 'givenname'
|
||||||
assert param.doc == 'User first name'
|
assert param.doc == 'User first name'
|
||||||
|
|
||||||
|
|
||||||
class test_Application(ClassChecker):
|
|
||||||
"""
|
|
||||||
Test the `ipalib.frontend.Application` class.
|
|
||||||
"""
|
|
||||||
_cls = frontend.Application
|
|
||||||
|
|
||||||
def test_class(self):
|
|
||||||
"""
|
|
||||||
Test the `ipalib.frontend.Application` class.
|
|
||||||
"""
|
|
||||||
assert self.cls.__bases__ == (frontend.Command,)
|
|
||||||
assert type(self.cls.application) is property
|
|
||||||
|
|
||||||
def test_application(self):
|
|
||||||
"""
|
|
||||||
Test the `ipalib.frontend.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 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.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 read_only(o, 'application') is app
|
|
||||||
|
|||||||
Reference in New Issue
Block a user