diff options
author | yenatch <yenatch@gmail.com> | 2013-11-05 14:11:04 -0500 |
---|---|---|
committer | yenatch <yenatch@gmail.com> | 2013-11-05 14:11:04 -0500 |
commit | da7b863b8e20d5d8da07d9eb44e0fd4f5f0848d0 (patch) | |
tree | 09a02add28a0d34589fce85ec2fde3da81c8eb05 /pokemontools/configuration.py | |
parent | 4a7373d8e79d17f10ebafa3ccef7b822a5b139af (diff) | |
parent | dafb5518df768f93ac94c59d4bf5981e95f7aba0 (diff) |
Merge branch 'master' of github.com:kanzure/pokemon-reverse-engineering-tools
Diffstat (limited to 'pokemontools/configuration.py')
-rw-r--r-- | pokemontools/configuration.py | 54 |
1 files changed, 54 insertions, 0 deletions
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) + ) |