summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2009-01-22 09:58:35 -0700
committerRob Crittenden <rcritten@redhat.com>2009-02-03 15:29:00 -0500
commit6aadeb9aea60165d9c68b348dae4df456b00dfc4 (patch)
tree93f957952dd32d52eef0197d533df601b7804925
parent529819b02b1c6e78b85481b417ae896b7237f0e2 (diff)
downloadfreeipa-6aadeb9aea60165d9c68b348dae4df456b00dfc4.tar.gz
freeipa-6aadeb9aea60165d9c68b348dae4df456b00dfc4.tar.xz
freeipa-6aadeb9aea60165d9c68b348dae4df456b00dfc4.zip
Added Object.params_minus() method; various small tweaks
-rw-r--r--ipalib/__init__.py2
-rw-r--r--ipalib/constants.py32
-rw-r--r--ipalib/crud.py2
-rw-r--r--ipalib/frontend.py15
-rw-r--r--ipalib/plugable.py12
-rw-r--r--ipalib/plugins/f_user.py4
-rw-r--r--tests/test_ipalib/test_frontend.py20
7 files changed, 51 insertions, 36 deletions
diff --git a/ipalib/__init__.py b/ipalib/__init__.py
index aa0f66cc4..0f9f54970 100644
--- a/ipalib/__init__.py
+++ b/ipalib/__init__.py
@@ -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
diff --git a/ipalib/constants.py b/ipalib/constants.py
index 5687c53e6..e229b466c 100644
--- a/ipalib/constants.py
+++ b/ipalib/constants.py
@@ -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!
# ********************************************************
diff --git a/ipalib/crud.py b/ipalib/crud.py
index bf33b7ab4..5bae4fbc3 100644
--- a/ipalib/crud.py
+++ b/ipalib/crud.py
@@ -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):
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index 640b01f92..67f0a89c2 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -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.
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index b52db9008..1370d7f54 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -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,20 +571,18 @@ 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:
if self.env.mode in ('dummy', 'unit_test'):
- return # But not if in unit-test mode
+ return # But not if in unit-test mode
log_dir = path.dirname(self.env.log)
if not path.isdir(log_dir):
try:
@@ -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:
diff --git a/ipalib/plugins/f_user.py b/ipalib/plugins/f_user.py
index 506ad14d0..f1134fb2a 100644
--- a/ipalib/plugins/f_user.py
+++ b/ipalib/plugins/f_user.py
@@ -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.
diff --git a/tests/test_ipalib/test_frontend.py b/tests/test_ipalib/test_frontend.py
index 0030a41e5..1e90dbb34 100644
--- a/tests/test_ipalib/test_frontend.py
+++ b/tests/test_ipalib/test_frontend.py
@@ -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):
"""