-
-
Save karlcow/b3f275e020fbfd5e7fd7ce130fb28c61 to your computer and use it in GitHub Desktop.
convert secrets.py and environment.py into a JSON file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# This Source Code Form is subject to the terms of the Mozilla Public | |
# License, v. 2.0. If a copy of the MPL was not distributed with this | |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
"""Convert from the old config file to the new format.""" | |
import fileinput | |
import json | |
config_keys = [ | |
"OAUTH_TOKEN", | |
"ISSUES_REPO_URI", | |
"GITHUB_CLIENT_ID", | |
"GITHUB_CLIENT_SECRET", | |
"GITHUB_CALLBACK_URL", | |
"SECRET_KEY", | |
"HOOK_SECRET_KEY", | |
"UPLOADS_DEFAULT_DEST", | |
"UPLOADS_DEFAULT_URL", | |
"BACKUP_DEFAULT_DEST"] | |
config = {} | |
def grab_key(line): | |
"""Extract the keys from the config files.""" | |
config_key, config_line = line.split('=') | |
config_value = config_line.strip() | |
if not config_value == "''": | |
if ' or ' in config_value: | |
config_value = config_value.split(' ')[2] | |
if ' + ' in config_value: | |
config_value = config_value.split(' ')[2] | |
config_value = config_value.strip("'") | |
else: | |
config_value = '' | |
if config_key.strip() == 'env.BACKUP_DEFAULT_DEST': | |
return None, None | |
else: | |
return config_key.strip(), config_value | |
for line in fileinput.input(): | |
for key in config_keys: | |
if key in line: | |
config_key, config_value = grab_key(line.strip()) | |
print(config_key, config_value) | |
if config_key in config and not config[config_key] == '': | |
continue | |
elif config_key is None: | |
continue | |
else: | |
if config_key == 'OAUTH_TOKEN': | |
config[config_key] = {"oauthkey": config_value} | |
else: | |
config[config_key] = config_value | |
print(json.dumps(config, indent=2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment