Преглед изворни кода

wrap parse_config() to catch ConfigParseExceptions and report them to the user cleanly; some minor doc changes.

tags/v0.1^2
Ben Kurtovic пре 13 година
родитељ
комит
94848ab0bc
1 измењених фајлова са 13 додато и 3 уклоњено
  1. +13
    -3
      core/config.py

+ 13
- 3
core/config.py Прегледај датотеку

@@ -118,7 +118,7 @@ def attribute_to_bool(element, attribute, default=None):

def get_first_element(parent, tag_name):
"""Return the first child of the parent element with the given tag name, or
return None."""
return None if no child of that name exists."""
try:
return parent.getElementsByTagName(tag_name)[0]
except IndexError:
@@ -129,8 +129,8 @@ def get_required_element(parent, tag_name):
raise MissingElementException() if no child of that name exists."""
element = get_first_element(parent, tag_name)
if not element:
e = "<{0}> is missing a required <{1}> tag.".format(parent.tagName,
tag_name)
e = "A <{0}> tag is missing a required <{1}> child tag.".format(
parent.tagName, tag_name)
raise MissingElementException(e)
return element

@@ -145,6 +145,16 @@ def get_required_attribute(element, attr_name):
return attribute

def parse_config(key):
"""A thin wrapper for the actual config parser in _parse_config(): catch
parsing exceptions and report them to the user cleanly."""
try:
_parse_config(key)
except ConfigParseException as e:
print "\nError parsing config file:"
print e
exit(1)

def _parse_config(key):
"""Parse config data from a DOM object into the 'config' global variable.
The key is used to unencrypt passwords stored in the XML config file."""
_load_config() # we might be re-loading unnecessarily here, but no harm in


Loading…
Откажи
Сачувај