Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1216)

Unified Diff: quickstart/manage.py

Issue 14441074: Bootstrap the Juju environment.
Patch Set: Bootstrap the Juju environment. Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « quickstart/app.py ('k') | quickstart/tests/helpers.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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))
« no previous file with comments | « quickstart/app.py ('k') | quickstart/tests/helpers.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b