~frankban/juju-gui/quickstart-initial

« back to all changes in this revision

Viewing changes to quickstart/manage.py

  • Committer: Francesco Banconi
  • Date: 2013-10-14 11:27:50 UTC
  • Revision ID: francesco.banconi@canonical.com-20131014112750-ki6rg20mmcoldqzf
Base structure for the application.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This file is part of the Juju GUI, which lets users view and manage Juju
 
2
# environments within a graphical interface (https://launchpad.net/juju-gui).
 
3
# Copyright (C) 2013 Canonical Ltd.
 
4
#
 
5
# This program is free software: you can redistribute it and/or modify it under
 
6
# the terms of the GNU Affero General Public License version 3, as published by
 
7
# the Free Software Foundation.
 
8
#
 
9
# This program is distributed in the hope that it will be useful, but WITHOUT
 
10
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
 
11
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
# Affero General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU Affero General Public License
 
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
 
 
17
"""Juju Quickstart application management."""
 
18
 
 
19
from __future__ import print_function
 
20
import argparse
 
21
import os
 
22
import sys
 
23
 
 
24
from tornado.ioloop import IOLoop
 
25
 
 
26
import quickstart
 
27
 
 
28
 
 
29
default_envfile = os.path.expanduser('~/.juju/environments.yaml')
 
30
version = quickstart.get_version()
 
31
 
 
32
 
 
33
def setup():
 
34
    """Set up the application options."""
 
35
    parser = argparse.ArgumentParser(description=quickstart.__doc__)
 
36
    parser.add_argument(
 
37
        '-e', '--environment', required=True, dest='env_name',
 
38
        help='the name of the Juju environment to use')
 
39
    parser.add_argument(
 
40
        '--environments-file', dest='env_file', type=file,
 
41
        default=default_envfile,
 
42
        help='the path to the Juju environments YAML file')
 
43
    parser.add_argument(
 
44
        '--version', action='version', version='%(prog)s {}'.format(version))
 
45
    return parser.parse_args()
 
46
 
 
47
 
 
48
def run(options):
 
49
    """Run the application"""
 
50
    print('juju quickstart v{}'.format(version))
 
51
    # TODO: everything!
 
52
    exit()
 
53
 
 
54
 
 
55
def exit(error=None):
 
56
    """Exit the application.
 
57
 
 
58
    If error is not None, print the error to stderr and exit with an error.
 
59
    """
 
60
    IOLoop.instance().stop()
 
61
    sys.exit(error)