Skip to content

Commit fb6269b

Browse files
author
Clark Perkins
committed
Added script to convert config file
1 parent 6bcb57a commit fb6269b

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def test_python_version():
8585
'console_scripts': [
8686
'stackdio-cli=stackdio.cli:main',
8787
'blueprint-generator=stackdio.cli.blueprints:main',
88+
'stackdio-config-convert=stackdio.client.config:main',
8889
],
8990
},
9091
classifiers=[

stackdio/client/config.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,48 @@ def get_blueprint_dir(self):
221221
prompt_suffix='? ',
222222
type=UserPath(exists=True, file_okay=False,
223223
resolve_path=True))
224+
225+
226+
# FOR BACKWARDS COMPATIBILITY!!! To be removed at some point.
227+
@click.command(context_settings=dict(help_option_names=['-h', '--help']))
228+
@click.option('-o', '--old-file', default=os.path.expanduser('~/.stackdio-cli/config.json'),
229+
type=click.Path(exists=True), help='Path to the old JSON config file')
230+
@click.option('-n', '--new-file', default=CFG_FILE, type=click.Path(),
231+
help='Path to the new cfg format file. Must not already exist.')
232+
def migrate_old_config(old_file, new_file):
233+
"""
234+
Used to migrate an old JSON config file to a new one
235+
"""
236+
if os.path.exists(new_file):
237+
raise click.UsageError('The new config file must not already exist')
238+
239+
old_keys = ['username', 'url', 'verify', 'blueprint_dir']
240+
241+
config = StackdioConfig(new_file)
242+
243+
import json
244+
with open(old_file, 'r') as f:
245+
old_config = json.load(f)
246+
247+
for key in old_keys:
248+
if key in old_config:
249+
config[key] = old_config[key]
250+
251+
if 'url' not in config:
252+
config.get_url()
253+
254+
if 'username' not in config or config.get_password() is None:
255+
config.get_username()
256+
257+
if 'blueprint_dir' not in config:
258+
config.get_blueprint_dir()
259+
260+
config.save()
261+
262+
263+
def main():
264+
migrate_old_config()
265+
266+
267+
if __name__ == '__main__':
268+
main()

0 commit comments

Comments
 (0)