Skip to content

Instantly share code, notes, and snippets.

@karlcow karlcow/ Secret
Created Aug 25, 2017

What would you like to do?
convert and into a JSON file.
#!/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
"""Convert from the old config file to the new format."""
import fileinput
import json
config_keys = [
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("'")
config_value = ''
if config_key.strip() == 'env.BACKUP_DEFAULT_DEST':
return None, None
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] == '':
elif config_key is None:
if config_key == 'OAUTH_TOKEN':
config[config_key] = {"oauthkey": config_value}
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
You can’t perform that action at this time.