Index: quickstart/manage.py |
=== modified file 'quickstart/manage.py' |
--- quickstart/manage.py 2013-10-15 15:40:31 +0000 |
+++ quickstart/manage.py 2013-10-16 15:23:08 +0000 |
@@ -18,6 +18,7 @@ |
from __future__ import print_function |
import argparse |
+import logging |
import os |
import quickstart |
@@ -54,7 +55,8 @@ |
'It is possible to specify the environment name by either:\n' |
' - passing the -e or --environment argument;\n' |
' - setting the JUJU_ENV environment variable;\n' |
- ' - using "juju switch" to select the default environment to use.' |
+ ' - using "juju switch" to select the default environment;\n' |
+ ' - setting the default environment in {}.'.format(env_file) |
) |
# Validate the environment file. |
try: |
@@ -70,8 +72,25 @@ |
options.env_type = env_type |
+def _configure_logging(level): |
+ """Set up the application logging.""" |
+ root = logging.getLogger() |
+ # Remove any previous handler on the root logger. |
+ for handler in root.handlers[:]: |
+ root.removeHandler(handler) |
+ logging.basicConfig( |
+ level=level, |
+ format=( |
+ '%(asctime)s %(levelname)s ' |
+ '%(module)s@%(funcName)s:%(lineno)d ' |
+ '%(message)s' |
+ ), |
+ datefmt='%H:%M:%S', |
+ ) |
+ |
+ |
def setup(): |
- """Set up the application options. |
+ """Set up the application options and logger. |
Return the options as a namespace containing the followin attributes: |
- admin_secret: the password to use to access the Juju API; |
@@ -97,6 +116,8 @@ |
help='the path to the Juju environments YAML file (%(default)s)') |
parser.add_argument( |
'--version', action='version', version='%(prog)s {}'.format(version)) |
+ parser.add_argument( |
+ '--debug', action='store_true', help='turn debug mode on') |
# This is required by juju-core: see "juju help plugins". |
parser.add_argument( |
'--description', action=_DescriptionAction, default=argparse.SUPPRESS, |
@@ -105,6 +126,8 @@ |
options = parser.parse_args() |
# Validate and process the provided arguments. |
_validate_env(options, parser) |
+ # Set up logging. |
+ _configure_logging(logging.DEBUG if options.debug else logging.INFO) |
return options |
@@ -114,3 +137,6 @@ |
print('bootstrapping the {} environment (type: {})'.format( |
options.env_name, options.env_type)) |
app.bootstrap(options.env_name) |
+ print('retrieving the Juju API address') |
+ api_url = app.get_api_url(options.env_name) |
+ print('connecting to {}'.format(api_url)) |