diff --git a/overviewer_core/configParser.py b/overviewer_core/configParser.py index e312d77..c6070d0 100644 --- a/overviewer_core/configParser.py +++ b/overviewer_core/configParser.py @@ -1,4 +1,3 @@ -import optparse import sys import os.path import logging @@ -7,13 +6,14 @@ import traceback from . import settingsDefinition from . import settingsValidators -class MissingConfigException(Exception): - "To be thrown when the config file can't be found" - pass -class MultiWorldParser(object): +class MissingConfigException(Exception): + """"To be thrown when the config file can't be found""" + + +class MultiWorldParser: """A class that is used to parse a settings.py file. - + This class's job is to compile and validate the configuration settings for a set of renders. It can read in configuration from the given file with the parse() method, and one can set configuration options directly with the @@ -39,7 +39,7 @@ class MultiWorldParser(object): continue self._settings[settingname] = setting - + # Set top level defaults. This is intended to be for container # types, so they can initialize a config file with an empty # container (like a dict) @@ -72,7 +72,9 @@ class MultiWorldParser(object): """ if not os.path.exists(settings_file) and not os.path.isfile(settings_file): - raise MissingConfigException("The settings file you specified (%r) does not exist, or is not a file" % settings_file) + raise MissingConfigException( + "The settings file you specified (%r) does not exist, or is not a file." + % settings_file) # The global environment should be the rendermode module, so the config # file has access to those resources. @@ -82,17 +84,19 @@ class MultiWorldParser(object): with open(settings_file, "rb") as settings_file_handle: exec(compile(settings_file_handle.read(), settings_file, 'exec'), rendermodes.__dict__, self._config_state) - + except Exception as ex: if isinstance(ex, SyntaxError): - logging.error("Syntax error parsing %s" % settings_file) - logging.error("The traceback below will tell you which line triggered the syntax error\n") + logging.error("Syntax error parsing '%s'.", settings_file) + logging.error("The traceback below will tell you which line triggered the " + "syntax error.\n") elif isinstance(ex, NameError): - logging.error("NameError parsing %s" % settings_file) - logging.error("The traceback below will tell you which line referenced the non-existent variable\n") + logging.error("NameError parsing '%s'.", settings_file) + logging.error("The traceback below will tell you which line referenced the " + "non-existent variable.\n") else: - logging.error("Error parsing %s" % settings_file) - logging.error("The traceback below will tell you which line triggered the error\n") + logging.error("Error parsing '%s'.", settings_file) + logging.error("The traceback below will tell you which line triggered the error.\n") # skip the execfile part of the traceback exc_type, exc_value, exc_traceback = sys.exc_info() @@ -100,12 +104,16 @@ class MultiWorldParser(object): print_rest = False lines = [] for l in formatted_lines: - if print_rest: lines.append(l) + if print_rest: + lines.append(l) else: - if "execfile" in l: print_rest = True + if "execfile" in l: + print_rest = True # on windows, our traceback as no 'execfile'. in this case, print everything - if print_rest: logging.error("Partial traceback:\n" + "\n".join(lines)) - else: logging.error("Partial traceback:\n" + "\n".join(formatted_lines)) + if print_rest: + logging.error("Partial traceback:\n" + "\n".join(lines)) + else: + logging.error("Partial traceback:\n" + "\n".join(formatted_lines)) sys.exit(1) # At this point, make a pass through the file to possibly set global @@ -117,17 +125,17 @@ class MultiWorldParser(object): setting = render_settings[key] setting.default = self._config_state[key] - def get_validated_config(self): """Validate and return the configuration. Raises a ValidationException if there was a problem validating the config. Could also raise a ValueError - + """ # Okay, this is okay, isn't it? We're going to create the validation # routine right here, right now. I hope this works! - validator = settingsValidators.make_configDictValidator(self._settings, ignore_undefined=True) + validator = settingsValidators.make_configDictValidator(self._settings, + ignore_undefined=True) # Woah. What just happened? No. WAIT, WHAT ARE YOU... validated_config = validator(self._config_state) # WHAT HAVE YOU DONE?