From 61de70f7829066edb4b72d4e5d6e0aa1483e3753 Mon Sep 17 00:00:00 2001 From: rawgni Date: Sat, 27 Aug 2016 12:26:14 +0700 Subject: [PATCH 1/2] added separate config --- .gitignore | 1 + configs/auth.json.example | 11 +++++++++++ configs/config.json.cluster.example | 9 --------- configs/config.json.example | 9 --------- configs/config.json.map.example | 9 --------- configs/config.json.optimizer.example | 9 --------- configs/config.json.path.example | 9 --------- configs/config.json.pokemon.example | 9 --------- pokecli.py | 23 +++++++++++++---------- setup.sh | 3 ++- 10 files changed, 27 insertions(+), 65 deletions(-) create mode 100644 configs/auth.json.example diff --git a/.gitignore b/.gitignore index d42bc72861..849a6613c3 100644 --- a/.gitignore +++ b/.gitignore @@ -126,6 +126,7 @@ configs/* !configs/path.example.json !config.json.cluster.example !config.json.optimizer.example +!auth.json.example # Virtualenv folders bin/ diff --git a/configs/auth.json.example b/configs/auth.json.example new file mode 100644 index 0000000000..04c8fa5e35 --- /dev/null +++ b/configs/auth.json.example @@ -0,0 +1,11 @@ +{ + "auth_service": "google", + "username": "YOUR_USERNAME", + "password": "YOUR_PASSWORD", + "location": "SOME_LOCATION", + "favorite_locations":[ + {"name": "Milan", "coords": "45.472849,9.177567"} + ], + "gmapkey": "GOOGLE_MAPS_API_KEY", + "encrypt_location": "" +} diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index 41eac1e31c..77fc049df3 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -1,13 +1,4 @@ { - "auth_service": "google", - "username": "YOUR_USERNAME", - "password": "YOUR_PASSWORD", - "location": "SOME_LOCATION", - "favorite_locations":[ - {"name": "Milan", "coords": "45.472849,9.177567"} - ], - "gmapkey": "GOOGLE_MAPS_API_KEY", - "encrypt_location": "", "websocket_server": false, "heartbeat_threshold": 10, "enable_social": true, diff --git a/configs/config.json.example b/configs/config.json.example index 867083875c..a0878aabb0 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -1,13 +1,4 @@ { - "auth_service": "google", - "username": "YOUR_USERNAME", - "password": "YOUR_PASSWORD", - "location": "SOME_LOCATION", - "favorite_locations":[ - {"name": "Milan", "coords": "45.472849,9.177567"} - ], - "gmapkey": "GOOGLE_MAPS_API_KEY", - "encrypt_location": "", "websocket_server": false, "heartbeat_threshold": 10, "enable_social": true, diff --git a/configs/config.json.map.example b/configs/config.json.map.example index 780901c44f..9cfcd34f37 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -1,13 +1,4 @@ { - "auth_service": "google", - "username": "YOUR_USERNAME", - "password": "YOUR_PASSWORD", - "location": "SOME_LOCATION", - "favorite_locations":[ - {"name": "Milan", "coords": "45.472849,9.177567"} - ], - "gmapkey": "GOOGLE_MAPS_API_KEY", - "encrypt_location": "", "websocket_server": false, "heartbeat_threshold": 10, "enable_social": true, diff --git a/configs/config.json.optimizer.example b/configs/config.json.optimizer.example index e1d9f206f1..beead0c07d 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -1,13 +1,4 @@ { - "auth_service": "google", - "username": "YOUR_USERNAME", - "password": "YOUR_PASSWORD", - "location": "SOME_LOCATION", - "favorite_locations":[ - {"name": "Milan", "coords": "45.472849,9.177567"} - ], - "gmapkey": "GOOGLE_MAPS_API_KEY", - "encrypt_location": "", "websocket_server": false, "heartbeat_threshold": 10, "enable_social": true, diff --git a/configs/config.json.path.example b/configs/config.json.path.example index 2482bea1a2..51927b1c33 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -1,13 +1,4 @@ { - "auth_service": "google", - "username": "YOUR_USERNAME", - "password": "YOUR_PASSWORD", - "location": "SOME_LOCATION", - "favorite_locations":[ - {"name": "Milan", "coords": "45.472849,9.177567"} - ], - "gmapkey": "GOOGLE_MAPS_API_KEY", - "encrypt_location": "", "websocket_server": false, "heartbeat_threshold": 10, "enable_social": true, diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 98a2dea740..4dda53e0f0 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -1,13 +1,4 @@ { - "auth_service": "google", - "username": "YOUR_USERNAME", - "password": "YOUR_PASSWORD", - "location": "SOME_LOCATION", - "favorite_locations":[ - {"name": "Milan", "coords": "45.472849,9.177567"} - ], - "gmapkey": "GOOGLE_MAPS_API_KEY", - "encrypt_location": "", "websocket_server": false, "heartbeat_threshold": 10, "enable_social": true, diff --git a/pokecli.py b/pokecli.py index 82221d0688..f42feedbdc 100644 --- a/pokecli.py +++ b/pokecli.py @@ -287,16 +287,19 @@ def _json_loader(filename): # Select a config file code parser.add_argument("-cf", "--config", help="Config File to use") - config_arg = parser.parse_known_args() and parser.parse_known_args()[0].config or None - - if config_arg and os.path.isfile(config_arg): - _json_loader(config_arg) - config_file = config_arg - elif os.path.isfile(config_file): - logger.info('No config argument specified, checking for /configs/config.json') - _json_loader(config_file) - else: - logger.info('Error: No /configs/config.json or specified config') + parser.add_argument("-af", "--auth", help="Auth File to use") + + for _config in ['auth', 'config']: + config_arg = parser.parse_known_args() and parser.parse_known_args()[0].__dict__[_config] or None + + if config_arg and os.path.isfile(config_arg): + _json_loader(config_arg) + config_file = config_arg if _config == 'config' else config_file + elif os.path.isfile(config_file): + logger.info('No ' + _config + ' argument specified, checking for /configs/' + _config + '.json') + _json_loader(config_file) + else: + logger.info('Error: No /configs/config.json or specified config') # Read passed in Arguments required = lambda x: not x in load diff --git a/setup.sh b/setup.sh index 5cd3b52798..400a8e9a66 100755 --- a/setup.sh +++ b/setup.sh @@ -51,7 +51,8 @@ read -p "Input gmapkey [[ $auth = "2" || $auth = "ptc" ]] && auth="ptc" || auth="google" sed -e "s/YOUR_USERNAME/$username/g" -e "s/YOUR_PASSWORD/$password/g" \ -e "s/SOME_LOCATION/$location/g" -e "s/GOOGLE_MAPS_API_KEY/$gmapkey/g" \ - -e "s/google/$auth/g" configs/config.json.example > configs/config.json + -e "s/google/$auth/g" configs/auth.json.example > configs/auth.json +cp configs/config.json.example configs/config.json echo "Edit ./configs/config.json to modify any other config." } From 38a8dba42420a8fdb6cc020fa5375f76da7c6bfe Mon Sep 17 00:00:00 2001 From: rawgni Date: Sat, 27 Aug 2016 12:39:22 +0700 Subject: [PATCH 2/2] fix test file to load auth --- tests/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/__init__.py b/tests/__init__.py index e5f7be11fd..17f4615145 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -11,7 +11,8 @@ def get_fake_conf(): class ConfObj: pass - conf_dict = json.load(open('configs/config.json.example')) + conf_dict = json.load(open('configs/auth.json.example')) + conf_dict.update(json.load(open('configs/config.json.example'))) conf_obj = ConfObj() for key, value in conf_dict.items(): setattr(conf_obj, key, value)