Skip to content

Commit d598f33

Browse files
author
Clark Perkins
committed
Finished most of stacks
1 parent 5a16b10 commit d598f33

File tree

7 files changed

+163
-300
lines changed

7 files changed

+163
-300
lines changed

stackdio/cli/__init__.py

Lines changed: 6 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22

33
from __future__ import print_function
44

5-
import json
65
import os
7-
import sys
8-
from cmd import Cmd
96

107
import click
11-
from requests import ConnectionError
128

139
from stackdio.cli.mixins import blueprints, bootstrap, formulas, stacks
1410
from stackdio.client import StackdioClient
@@ -36,13 +32,19 @@ def stackdio(ctx):
3632
@stackdio.command()
3733
@click.pass_obj
3834
def configure(obj):
35+
"""
36+
Configure the client
37+
"""
3938
client = obj['client']
4039
print('configuring')
4140

4241

4342
@stackdio.command('server-version')
4443
@click.pass_obj
4544
def server_version(obj):
45+
"""
46+
Print the version of the server
47+
"""
4648
client = obj['client']
4749
click.echo('stackdio-server, version {0}'.format(client.get_version()))
4850

@@ -52,131 +54,6 @@ def server_version(obj):
5254
stackdio.add_command(stacks.stacks)
5355

5456

55-
class StackdioShell(Cmd, bootstrap.BootstrapMixin, stacks.StackMixin,
56-
formulas.FormulaMixin):
57-
58-
CFG_DIR = os.path.expanduser("~/.stackdio-cli/")
59-
CFG_FILE = os.path.join(CFG_DIR, "config.json")
60-
BOOTSTRAP_FILE = os.path.join(CFG_DIR, "bootstrap.yaml")
61-
KEYRING_SERVICE = "stackdio_cli"
62-
PROMPT = "\n{username} @ {url}\n> "
63-
HELP_CMDS = [
64-
"account_summary",
65-
"stacks", "blueprints", "formulas",
66-
"initial_setup", "bootstrap",
67-
"help", "exit", "quit",
68-
]
69-
70-
intro = """
71-
######################################################################
72-
s t a c k d . i o
73-
######################################################################
74-
"""
75-
76-
def __init__(self):
77-
mixins.bootstrap.BootstrapMixin.__init__(self)
78-
self._load_config()
79-
if 'url' in self.config and self.config['url']:
80-
self._init_stacks()
81-
self._validate_auth()
82-
83-
def _load_config(self):
84-
"""Attempt to load config file, otherwise fallback to DEFAULT_CONFIG"""
85-
86-
try:
87-
self.config = json.loads(open(self.CFG_FILE).read())
88-
self.config['blueprint_dir'] = os.path.expanduser(self.config.get('blueprint_dir', ''))
89-
90-
except ValueError:
91-
print(self.colorize(
92-
"What happened?! The config file is not valid JSON. A "
93-
"re-install is likely the easiest fix.", "red"))
94-
raise
95-
except IOError:
96-
self.config = {
97-
'url': None,
98-
'username': None,
99-
}
100-
print(self.colorize(
101-
"It seems like this is your first time using the CLI. Please run "
102-
"'initial_setup' to configure.", "green"))
103-
# print(self.colorize(
104-
# "What happened?! Unable to find a config file. A re-install "
105-
# "is likely the easiest fix.", "red"))
106-
# raise
107-
108-
self.has_public_key = None
109-
110-
def _validate_auth(self):
111-
"""Verify that we can connect successfully to the api"""
112-
113-
# If there is no config, just force the user to go through initial setup
114-
if self.config['url'] is None:
115-
return
116-
117-
try:
118-
self.stacks.get_root()
119-
status_code = 200
120-
self.validated = (200 <= status_code <= 299)
121-
except ConnectionError:
122-
print(self.colorize(
123-
"Unable to connect to {0}".format(self.config["url"]),
124-
"red"))
125-
raise
126-
127-
if self.validated:
128-
print(self.colorize(
129-
"Config loaded and validated", "blue"))
130-
self.has_public_key = self.stacks.get_public_key()
131-
else:
132-
print(self.colorize(
133-
"ERROR: Unable to validate config", "red"))
134-
self.has_public_key = None
135-
136-
def _setprompt(self):
137-
138-
Cmd.prompt = self.colorize(
139-
self.PROMPT.format(**self.config),
140-
"blue")
141-
142-
if not self.validated and self.config['url'] is not None:
143-
print(self.colorize("""
144-
##
145-
## Unable to validate connection - one of several possibilities exist:
146-
## If this is the first time you've fired this up, you need to run
147-
## 'initial_setup' to configure your account details. If you've already
148-
## done that, there could be a network connection issue anywhere between
149-
## your computer and your stackd.io instance,
150-
## or your password may be incorrect, or ... etc.
151-
##
152-
""",
153-
"green"))
154-
155-
if self.validated and not self.has_public_key:
156-
print(self.colorize(
157-
"## Your account is missing the public key, run 'bootstrap' to fix",
158-
"red"))
159-
160-
def do_account_summary(self, args=None):
161-
"""Get a summary of your account."""
162-
sys.stdout.write("Polling {0} ... ".format(self.config["url"]))
163-
sys.stdout.flush()
164-
165-
public_key = self.stacks.get_public_key()
166-
formulas = self.stacks.list_formulas()
167-
blueprints = self.stacks.list_blueprints()
168-
stacks = self.stacks.list_stacks()
169-
170-
sys.stdout.write("done\n")
171-
172-
print("## Username: {0}".format(self.config["username"]))
173-
print("## Public Key:\n{0}".format(public_key))
174-
175-
self._print_summary("Formula", formulas)
176-
self._print_summary("Blueprint", blueprints)
177-
self._print_summary("Stack", stacks)
178-
179-
18057
def main():
18158
# Just run our CLI tool
18259
stackdio(obj={})

stackdio/cli/blueprints/generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,5 +294,5 @@ def generate(self, template_file, var_files=(), variables=None, prompt=False, de
294294
))
295295
except UndefinedError as e:
296296
self.error_exit('Missing variable: {0}'.format(str(e)))
297-
except ValueError:
298-
self.error_exit('Invalid JSON. Check your template file.')
297+
# except ValueError:
298+
# self.error_exit('Invalid JSON. Check your template file.')

stackdio/cli/mixins/blueprints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def _create_single_blueprint(config, template_file, var_files, no_prompt):
9595
for var_file in var_files:
9696
var_file = os.path.join(blueprint_dir, 'var_files', var_file)
9797
if os.path.exists(var_file):
98-
final_var_files.append(var_file)
98+
final_var_files.append(open(var_file, 'r'))
9999
else:
100100
click.secho('WARNING: Variable file {0} was not found. Ignoring.'.format(var_file),
101101
fg='magenta')

stackdio/cli/mixins/bootstrap.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ def _bootstrap_account(self):
264264
def _bootstrap_formulas(self):
265265
"""Import and wait for formulas to become ready"""
266266

267+
@poll_and_wait
267268
def _check_formulas():
268269
formulas = self.stacks.list_formulas()
269270
for formula in formulas:
@@ -282,7 +283,7 @@ def _check_formulas():
282283
sys.stdout.write("Waiting for formulas .")
283284
sys.stdout.flush()
284285
try:
285-
poll_and_wait(_check_formulas)
286+
_check_formulas()
286287
sys.stdout.write(" done!\n")
287288
except TimeoutException:
288289
print(self.colorize(

0 commit comments

Comments
 (0)