Skip to content

Commit

Permalink
python editor interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lee212 committed Oct 26, 2016
1 parent 87e0f8b commit 246105b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
24 changes: 12 additions & 12 deletions simpleazure/azure_quickstart_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ def get_templates_cli(self):
nested = self.get_nested_cli(item)
scripts = self.get_scripts_cli(item)
templates[item] = Template({
"azuredeploy": azuredeploy,
"parameters": parameters,
"metadata": meta,
"nested": nested,
"scripts": scripts,
"etc": etc
u"azuredeploy": azuredeploy,
u"parameters": parameters,
u"metadata": meta,
u"nested": nested,
u"scripts": scripts,
u"etc": etc
})
meta = azuredeploy = parameters = nested = scripts = etc = ""
return templates
Expand Down Expand Up @@ -151,12 +151,12 @@ def get_templates_api(self):
nested = self.get_nested_api(item['path'])
scripts = self.get_scripts_api(item['path'])
templates[item['name']] = Template({
"azuredeploy": azuredeploy,
"parameters": parameters,
"metadata": meta,
"nested": nested,
"scripts": scripts,
"etc": etc
u"azuredeploy": azuredeploy,
u"parameters": parameters,
u"metadata": meta,
u"nested": nested,
u"scripts": scripts,
u"etc": etc
})
meta = azuredeploy = parameters = nested = scripts = etc = ""
return templates
Expand Down
7 changes: 4 additions & 3 deletions simpleazure/azure_resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def set_parameters(self, params):
return self.parameters

def _get_parameters_with_value(self, params):
parameters = {k: {'value': v} for k, v in params.items()}
parameters = {k: {u'value': v} for k, v in params.items()}
return parameters

def set_template(self, path_or_uri=None):
Expand All @@ -215,9 +215,10 @@ def set_template(self, path_or_uri=None):
if urlparse(path_or_uri).scheme is not "":
template = json.loads(urllib.urlopen(path_or_uri).read())
else:
with open(path_or_uri, "r") as temp:
template = temp.read()
with open(os.path.expanduser(path_or_uri), "r") as temp:
template = json.loads(temp.read())
self.template['azuredeploy'] = template
#self.set_parameters(template['parameters'])

def load_template(self, template):
self.template = template
Expand Down
17 changes: 17 additions & 0 deletions simpleazure/template/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
import pandas as pd
from collections import OrderedDict, defaultdict
from itertools import islice, izip_longest
import editor
import json
import datadiff
from datadiff.tools import assert_equal

class Templates(OrderedDict):
_list = None
Expand Down Expand Up @@ -245,6 +249,19 @@ def _key_and_value(self, dict_with_value):
pass
return new_dict

def edit(self):
changed = json.loads(editor.edit(contents=json.dumps(self, indent=4)))
return Template(changed)

def diff(self, b):
try:
datadiff.tools.assert_equal(dict(self), dict(b))
equal=True
except AssertionError as e:
equal=False
if not equal:
print datadiff.diff(dict(self), dict(b))

class Deploy(object):
"""Constructs a :class:`Deploy <Deploy>`.
Returns :class:`Deploy <Deploy>` instance.
Expand Down

0 comments on commit 246105b

Please sign in to comment.