From a4849db2658a14deebb6620fac50e9d8e9f8a0ad Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Thu, 12 Sep 2013 00:34:43 -0500 Subject: rename config.py -> configuration.py This should help cut down on the confusion between the "config" module and the "config" variable that everyone likes to use. The config variable should refer to an instance of Config, whereas before it was being shared as both the name of the module and the name of an instance. "configuration" is always the module. "config" should always be a Config instance. TODO: avoid passing around a Config instance everywhere. --- pokemontools/__init__.py | 2 +- pokemontools/config.py | 54 ------------------------------------------- pokemontools/configuration.py | 54 +++++++++++++++++++++++++++++++++++++++++++ pokemontools/gbz80disasm.py | 4 ++-- 4 files changed, 57 insertions(+), 57 deletions(-) delete mode 100644 pokemontools/config.py create mode 100644 pokemontools/configuration.py diff --git a/pokemontools/__init__.py b/pokemontools/__init__.py index 09331af..293e2f2 100644 --- a/pokemontools/__init__.py +++ b/pokemontools/__init__.py @@ -1,3 +1,3 @@ -import config +import configuration as config import crystal import preprocessor diff --git a/pokemontools/config.py b/pokemontools/config.py deleted file mode 100644 index cbf230c..0000000 --- a/pokemontools/config.py +++ /dev/null @@ -1,54 +0,0 @@ -""" -Configuration -""" - -import os - -import exceptions - -class Config(object): - """ - The Config class handles all configuration for pokemontools. Other classes - and functions use a Config object to determine where expected files can be - located. - """ - - def __init__(self, **kwargs): - """ - Store all parameters. - """ - self._config = {} - - for (key, value) in kwargs.items(): - if key not in self.__dict__: - self._config[key] = value - else: - raise exceptions.ConfigException( - "Can't store \"{0}\" in configuration because the key conflicts with an existing property." - .format(key) - ) - - if "path" not in self._config: - self._config["path"] = os.getcwd() - - # vba save states go into ./save-states/ - if "save_state_path" not in self._config: - self._config["save_state_path"] = os.path.join(self._config["path"], "save-states/") - - # assume rom is at ./baserom.gbc - if "rom" not in self._config: - self._config["rom_path"] = os.path.join(self._config["path"], "baserom.gbc") - - def __getattr__(self, key): - """ - Grab the value from the class properties, then check the configuration, - and raise an exception if nothing works. - """ - if key in self.__dict__: - return self.__dict__[key] - elif key in self._config: - return self._config[key] - else: - raise exceptions.ConfigException( - "no config found for \"{0}\"".format(key) - ) diff --git a/pokemontools/configuration.py b/pokemontools/configuration.py new file mode 100644 index 0000000..cbf230c --- /dev/null +++ b/pokemontools/configuration.py @@ -0,0 +1,54 @@ +""" +Configuration +""" + +import os + +import exceptions + +class Config(object): + """ + The Config class handles all configuration for pokemontools. Other classes + and functions use a Config object to determine where expected files can be + located. + """ + + def __init__(self, **kwargs): + """ + Store all parameters. + """ + self._config = {} + + for (key, value) in kwargs.items(): + if key not in self.__dict__: + self._config[key] = value + else: + raise exceptions.ConfigException( + "Can't store \"{0}\" in configuration because the key conflicts with an existing property." + .format(key) + ) + + if "path" not in self._config: + self._config["path"] = os.getcwd() + + # vba save states go into ./save-states/ + if "save_state_path" not in self._config: + self._config["save_state_path"] = os.path.join(self._config["path"], "save-states/") + + # assume rom is at ./baserom.gbc + if "rom" not in self._config: + self._config["rom_path"] = os.path.join(self._config["path"], "baserom.gbc") + + def __getattr__(self, key): + """ + Grab the value from the class properties, then check the configuration, + and raise an exception if nothing works. + """ + if key in self.__dict__: + return self.__dict__[key] + elif key in self._config: + return self._config[key] + else: + raise exceptions.ConfigException( + "no config found for \"{0}\"".format(key) + ) diff --git a/pokemontools/gbz80disasm.py b/pokemontools/gbz80disasm.py index 1fb9d85..a77e433 100644 --- a/pokemontools/gbz80disasm.py +++ b/pokemontools/gbz80disasm.py @@ -10,7 +10,7 @@ from ctypes import c_int8 import random import json -import config +import configuration import crystal import labels import wram @@ -929,7 +929,7 @@ class Disassembler(object): return (output, offset, last_hl_address, last_a_address, used_3d97) if __name__ == "__main__": - conf = config.Config() + conf = configuration.Config() disasm = Disassembler(conf) disasm.initialize() -- cgit v1.2.3