Skip to content

Commit 230a8c6

Browse files
committed
fix(client): convert client.yaml to client.json once if needed
Our use of YAML was very restricted, so a set of python string replace calls converts it to valid JSON without requiring PyYAML. If that succeeds, delete the old ~/.deis/client.yaml file, otherwise ignore errors and just use ~/.deis/client.json from now on.
1 parent e4d0b37 commit 230a8c6

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

client/deis.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,20 @@ def __init__(self):
189189
os.mkdir(path, 0700)
190190
self._path = os.path.join(path, 'client.json')
191191
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
192204
with open(self._path, 'w') as f:
193-
json.dump({}, f)
205+
json.dump(settings, f)
194206
# load initial settings
195207
self.load()
196208

0 commit comments

Comments
 (0)