From c13a400277fcd5f1257d538e25fabc65a3126ace Mon Sep 17 00:00:00 2001 From: Cole Greenlee Date: Mon, 25 Jul 2016 04:52:59 -0500 Subject: [PATCH] Multiple Config File Support (#771) * Multiple Config File Support Adds ability to drop config files into the 'configs' dir whilst developing and have them ignored by git * Modified .gitignore * Fixed Example files not being included * Added warnings to PokeCLI based on config availability --- .gitignore | 7 +++++++ config.json.example => configs/config.json.example | 2 +- .../release_config.json.example | 0 pokecli.py | 8 ++++++-- pokemongo_bot/__init__.py | 2 +- 5 files changed, 15 insertions(+), 4 deletions(-) rename config.json.example => configs/config.json.example (99%) rename release_config.json.example => configs/release_config.json.example (100%) diff --git a/.gitignore b/.gitignore index cb30b978fa..447925bc95 100644 --- a/.gitignore +++ b/.gitignore @@ -114,3 +114,10 @@ data/catch-ignore.yml release_config.json web/userdata.js location.json + +#Multiple config +configs/* +!configs/config.json.example +!configs/release_config.json.example +!config.json.example +!release_config.json.example \ No newline at end of file diff --git a/config.json.example b/configs/config.json.example similarity index 99% rename from config.json.example rename to configs/config.json.example index e6863521c9..0dfe442918 100644 --- a/config.json.example +++ b/configs/config.json.example @@ -15,4 +15,4 @@ "item_filter": "101,102,103,104", "evolve_all": "NONE", "use_lucky_egg": false -} +} \ No newline at end of file diff --git a/release_config.json.example b/configs/release_config.json.example similarity index 100% rename from release_config.json.example rename to configs/release_config.json.example diff --git a/pokecli.py b/pokecli.py index 296dc98829..3880d5d53c 100755 --- a/pokecli.py +++ b/pokecli.py @@ -46,8 +46,8 @@ def init_config(): parser = argparse.ArgumentParser() - config_file = "config.json" - release_config_json = "release_config.json" + config_file = "configs/config.json" + release_config_json = "configs/release_config.json" web_dir = "web" # If config file exists, load variables from json @@ -60,8 +60,12 @@ def init_config(): with open(config_arg) as data: load.update(json.load(data)) elif os.path.isfile(config_file): + logger.log('[x] No config argument specified, checking for /configs/config.json', 'yellow') with open(config_file) as data: load.update(json.load(data)) + else: + logger.log('[x] Error: No /configs/config.json or specified config', 'red') + # Read passed in Arguments required = lambda x: not x in load diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 92c54b36b1..b9c88e8c7c 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -183,7 +183,7 @@ def _setup_api(self): # check if the release_config file exists try: - with open('release_config.json') as file: + with open('configs/release_config.json') as file: pass except: # the file does not exist, warn the user and exit.