6868from docopt import DocoptExit
6969import requests
7070from termcolor import colored
71- import yaml
7271
7372__version__ = '0.12.0-dev'
7473
@@ -180,18 +179,30 @@ class Settings(dict):
180179 """
181180 Settings backed by a file in the user's home directory
182181
183- On init, settings are loaded from ~/.deis/client.yaml
182+ On init, settings are loaded from ~/.deis/client.json
184183 """
185184
186185 def __init__ (self ):
187186 path = os .path .expanduser ('~/.deis' )
188187 # Create the $HOME/.deis dir if it doesn't exist
189188 if not os .path .isdir (path ):
190189 os .mkdir (path , 0700 )
191- self ._path = os .path .join (path , 'client.yaml ' )
190+ self ._path = os .path .join (path , 'client.json ' )
192191 if not os .path .exists (self ._path ):
192+ settings = {}
193+ # try once to convert the old settings file if it exists
194+ # FIXME: this code can be removed in November 2014 or thereabouts, that's long enough.
195+ old_path = os .path .join (path , 'client.yaml' )
196+ if os .path .exists (old_path ):
197+ try :
198+ with open (old_path , 'r' ) as f :
199+ txt = f .read ().replace ('{' , '{"' , 1 ).replace (':' , '":' , 1 ).replace ("'" , '"' )
200+ settings = json .loads (txt )
201+ os .remove (old_path )
202+ except :
203+ pass # ignore errors, at least we tried to convert it
193204 with open (self ._path , 'w' ) as f :
194- f . write ( yaml . safe_dump ({}) )
205+ json . dump ( settings , f )
195206 # load initial settings
196207 self .load ()
197208
@@ -201,15 +212,15 @@ def load(self):
201212 """
202213 with open (self ._path ) as f :
203214 data = f .read ()
204- settings = yaml . safe_load (data )
215+ settings = json . loads (data )
205216 self .update (settings )
206217 return settings
207218
208219 def save (self ):
209220 """
210221 Serialize and save settings to the filesystem
211222 """
212- data = yaml . safe_dump (dict (self ))
223+ data = json . dumps (dict (self ))
213224 with open (self ._path , 'w' ) as f :
214225 f .write (data )
215226 return data
0 commit comments