Revision 29921401 lib/utils.py
b/lib/utils.py | ||
---|---|---|
396 | 396 |
if target[key] in allowed_values: |
397 | 397 |
continue |
398 | 398 |
|
399 |
type = key_types[key] |
|
400 |
if type not in constants.ENFORCEABLE_TYPES: |
|
401 |
msg = "'%s' has non-enforceable type %s" % (key, type) |
|
399 |
ktype = key_types[key]
|
|
400 |
if ktype not in constants.ENFORCEABLE_TYPES:
|
|
401 |
msg = "'%s' has non-enforceable type %s" % (key, ktype)
|
|
402 | 402 |
raise errors.ProgrammerError(msg) |
403 | 403 |
|
404 |
if type == constants.VTYPE_STRING: |
|
404 |
if ktype == constants.VTYPE_STRING:
|
|
405 | 405 |
if not isinstance(target[key], basestring): |
406 | 406 |
if isinstance(target[key], bool) and not target[key]: |
407 | 407 |
target[key] = '' |
408 | 408 |
else: |
409 | 409 |
msg = "'%s' (value %s) is not a valid string" % (key, target[key]) |
410 | 410 |
raise errors.TypeEnforcementError(msg) |
411 |
elif type == constants.VTYPE_BOOL: |
|
411 |
elif ktype == constants.VTYPE_BOOL:
|
|
412 | 412 |
if isinstance(target[key], basestring) and target[key]: |
413 | 413 |
if target[key].lower() == constants.VALUE_FALSE: |
414 | 414 |
target[key] = False |
... | ... | |
421 | 421 |
target[key] = True |
422 | 422 |
else: |
423 | 423 |
target[key] = False |
424 |
elif type == constants.VTYPE_SIZE: |
|
424 |
elif ktype == constants.VTYPE_SIZE:
|
|
425 | 425 |
try: |
426 | 426 |
target[key] = ParseUnit(target[key]) |
427 | 427 |
except errors.UnitParseError, err: |
428 | 428 |
msg = "'%s' (value %s) is not a valid size. error: %s" % \ |
429 | 429 |
(key, target[key], err) |
430 | 430 |
raise errors.TypeEnforcementError(msg) |
431 |
elif type == constants.VTYPE_INT: |
|
431 |
elif ktype == constants.VTYPE_INT:
|
|
432 | 432 |
try: |
433 | 433 |
target[key] = int(target[key]) |
434 | 434 |
except (ValueError, TypeError): |
... | ... | |
1526 | 1526 |
@param name: the daemon name used to derive the pidfile name |
1527 | 1527 |
|
1528 | 1528 |
""" |
1529 |
pid = os.getpid() |
|
1530 | 1529 |
pidfilename = DaemonPidFileName(name) |
1531 | 1530 |
# TODO: we could check here that the file contains our pid |
1532 | 1531 |
try: |
Also available in: Unified diff