mirror of
https://github.com/pret/pokemon-reverse-engineering-tools.git
synced 2026-09-26 19:40:56 -05:00
basic config support
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
import config
|
||||
import crystal
|
||||
import preprocessor
|
||||
|
||||
46
pokemontools/config.py
Normal file
46
pokemontools/config.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""
|
||||
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()
|
||||
|
||||
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)
|
||||
)
|
||||
@@ -11,3 +11,8 @@ class TextScriptException(Exception):
|
||||
"""
|
||||
TextScript encountered an inconsistency or problem.
|
||||
"""
|
||||
|
||||
class ConfigException(Exception):
|
||||
"""
|
||||
Configuration error. Maybe a missing config variable.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user