mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Added Object.params_minus() method; various small tweaks
This commit is contained in:
parent
529819b02b
commit
6aadeb9aea
@ -701,7 +701,7 @@ plugin (or plugins) is imported. For example:
|
||||
1
|
||||
>>> api.bootstrap(in_server=True) # We want to execute, not forward
|
||||
>>> len(api.env)
|
||||
35
|
||||
32
|
||||
|
||||
`Env._bootstrap()`, which is called by `API.bootstrap()`, will create several
|
||||
run-time variables that connot be overriden in configuration files or through
|
||||
|
@ -51,31 +51,20 @@ CLI_TAB = ' ' # Two spaces
|
||||
# The section to read in the config files, i.e. [global]
|
||||
CONFIG_SECTION = 'global'
|
||||
|
||||
|
||||
# Log format for console output
|
||||
LOG_FORMAT_STDERR = ': '.join([
|
||||
'%(name)s',
|
||||
# Log format for stderr:
|
||||
FORMAT_STDERR = ': '.join([
|
||||
'ipa',
|
||||
'%(levelname)s',
|
||||
'%(message)s',
|
||||
])
|
||||
|
||||
|
||||
# Log format for console output when env.dubug is True:
|
||||
LOG_FORMAT_STDERR_DEBUG = ' '.join([
|
||||
'%(levelname)s',
|
||||
'%(message)r',
|
||||
'%(lineno)d',
|
||||
'%(filename)s',
|
||||
])
|
||||
|
||||
|
||||
# Tab-delimited log format for file (easy to opened in a spreadsheet):
|
||||
LOG_FORMAT_FILE = '\t'.join([
|
||||
'%(asctime)s',
|
||||
# Log format for log file:
|
||||
FORMAT_FILE = '\t'.join([
|
||||
'%(created)f',
|
||||
'%(levelname)s',
|
||||
'%(message)r', # Using %r for repr() so message is a single line
|
||||
'%(lineno)d',
|
||||
'%(pathname)s',
|
||||
'%(process)d',
|
||||
'%(threadName)s',
|
||||
])
|
||||
|
||||
|
||||
@ -110,11 +99,6 @@ DEFAULT_CONFIG = (
|
||||
('debug', False),
|
||||
('mode', 'production'),
|
||||
|
||||
# Logging:
|
||||
('log_format_stderr', LOG_FORMAT_STDERR),
|
||||
('log_format_stderr_debug', LOG_FORMAT_STDERR_DEBUG),
|
||||
('log_format_file', LOG_FORMAT_FILE),
|
||||
|
||||
# ********************************************************
|
||||
# The remaining keys are never set from the values here!
|
||||
# ********************************************************
|
||||
|
@ -85,7 +85,7 @@ class PKQuery(frontend.Method):
|
||||
"""
|
||||
|
||||
def get_args(self):
|
||||
yield self.obj.primary_key.clone(query=True, multivalue=True)
|
||||
yield self.obj.primary_key.clone(query=True)
|
||||
|
||||
|
||||
class Retrieve(PKQuery):
|
||||
|
@ -27,7 +27,7 @@ import plugable
|
||||
from plugable import lock, check_name
|
||||
import errors
|
||||
from errors import check_type, check_isinstance, raise_TypeError
|
||||
from parameters import create_param, Param, Str, Flag
|
||||
from parameters import create_param, Param, Str, Flag, Password
|
||||
from util import make_repr
|
||||
|
||||
from errors2 import ZeroArgumentError, MaxArgumentError, OverlapError
|
||||
@ -102,6 +102,7 @@ class Command(plugable.Plugin):
|
||||
params.update(self.get_default(**params))
|
||||
self.validate(**params)
|
||||
(args, options) = self.params_2_args_options(**params)
|
||||
self.debug(make_repr(self.name, *args, **options))
|
||||
result = self.run(*args, **options)
|
||||
self.debug('%s result: %r', self.name, result)
|
||||
return result
|
||||
@ -447,6 +448,18 @@ class Object(plugable.Plugin):
|
||||
if 'Backend' in self.api and self.backend_name in self.api.Backend:
|
||||
self.backend = self.api.Backend[self.backend_name]
|
||||
|
||||
def params_minus(self, *names):
|
||||
"""
|
||||
Yield all Param whose name is not in ``names``.
|
||||
"""
|
||||
if len(names) == 1 and not isinstance(names[0], (Param, str)):
|
||||
names = names[0]
|
||||
minus = frozenset(names)
|
||||
for param in self.params():
|
||||
if param.name in minus or param in minus:
|
||||
continue
|
||||
yield param
|
||||
|
||||
def get_dn(self, primary_key):
|
||||
"""
|
||||
Construct an LDAP DN from a primary_key.
|
||||
|
@ -37,7 +37,7 @@ import errors2
|
||||
from config import Env
|
||||
import util
|
||||
from base import ReadOnly, NameSpace, lock, islocked, check_name
|
||||
from constants import DEFAULT_CONFIG
|
||||
from constants import DEFAULT_CONFIG, FORMAT_STDERR, FORMAT_FILE
|
||||
|
||||
|
||||
class SetProxy(ReadOnly):
|
||||
@ -562,7 +562,7 @@ class API(DictProxy):
|
||||
self.__doing('bootstrap')
|
||||
self.env._bootstrap(**overrides)
|
||||
self.env._finalize_core(**dict(DEFAULT_CONFIG))
|
||||
log = logging.getLogger('ipa')
|
||||
log = logging.getLogger()
|
||||
object.__setattr__(self, 'log', log)
|
||||
if self.env.debug:
|
||||
log.setLevel(logging.DEBUG)
|
||||
@ -571,15 +571,13 @@ class API(DictProxy):
|
||||
|
||||
# Add stderr handler:
|
||||
stderr = logging.StreamHandler()
|
||||
format = self.env.log_format_stderr
|
||||
if self.env.debug:
|
||||
format = self.env.log_format_stderr_debug
|
||||
stderr.setLevel(logging.DEBUG)
|
||||
elif self.env.verbose:
|
||||
stderr.setLevel(logging.INFO)
|
||||
else:
|
||||
stderr.setLevel(logging.WARNING)
|
||||
stderr.setFormatter(util.LogFormatter(format))
|
||||
stderr.setFormatter(util.LogFormatter(FORMAT_STDERR))
|
||||
log.addHandler(stderr)
|
||||
|
||||
# Add file handler:
|
||||
@ -593,7 +591,7 @@ class API(DictProxy):
|
||||
log.warn('Could not create log_dir %r', log_dir)
|
||||
return
|
||||
handler = logging.FileHandler(self.env.log)
|
||||
handler.setFormatter(util.LogFormatter(self.env.log_format_file))
|
||||
handler.setFormatter(util.LogFormatter(FORMAT_FILE))
|
||||
if self.env.debug:
|
||||
handler.setLevel(logging.DEBUG)
|
||||
else:
|
||||
|
@ -183,10 +183,10 @@ class user_add(crud.Add):
|
||||
api.register(user_add)
|
||||
|
||||
|
||||
class user_del(crud.Del):
|
||||
class user_del(crud.Delete):
|
||||
'Delete an existing user.'
|
||||
|
||||
def execute(self, uid, **kw):
|
||||
def execute(self, uid):
|
||||
"""Delete a user. Not to be confused with inactivate_user. This
|
||||
makes the entry go away completely.
|
||||
|
||||
|
@ -25,6 +25,7 @@ from tests.util import raises, getitem, no_set, no_del, read_only
|
||||
from tests.util import check_TypeError, ClassChecker, create_test_api
|
||||
from tests.util import assert_equal
|
||||
from ipalib.constants import TYPE_ERROR
|
||||
from ipalib.base import NameSpace
|
||||
from ipalib import frontend, backend, plugable, errors2, errors, parameters, config
|
||||
|
||||
|
||||
@ -638,6 +639,25 @@ class test_Object(ClassChecker):
|
||||
e = raises(NotImplementedError, o.get_dn, 'primary key')
|
||||
assert str(e) == 'user.get_dn()'
|
||||
|
||||
def test_params_minus(self):
|
||||
"""
|
||||
Test the `ipalib.frontend.Object.params_minus` method.
|
||||
"""
|
||||
class example(self.cls):
|
||||
takes_params = ('one', 'two', 'three', 'four')
|
||||
o = example()
|
||||
(api, home) = create_test_api()
|
||||
o.set_api(api)
|
||||
p = o.params
|
||||
assert tuple(o.params_minus()) == tuple(p())
|
||||
assert tuple(o.params_minus([])) == tuple(p())
|
||||
assert tuple(o.params_minus('two', 'three')) == (p.one, p.four)
|
||||
assert tuple(o.params_minus(['two', 'three'])) == (p.one, p.four)
|
||||
assert tuple(o.params_minus(p.two, p.three)) == (p.one, p.four)
|
||||
assert tuple(o.params_minus([p.two, p.three])) == (p.one, p.four)
|
||||
ns = NameSpace([p.two, p.three])
|
||||
assert tuple(o.params_minus(ns)) == (p.one, p.four)
|
||||
|
||||
|
||||
class test_Attribute(ClassChecker):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user