Zine

open source content publishing system


source: scripts/shell @ 1279:088d2f519391

Revision 1279:088d2f519391, 1.7 KB checked in by Georg Brandl <georg@…>, 2 years ago (diff)

Update copyright notices.

  • Property exe set to *
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3"""
4    Open a Zine Shell
5    ~~~~~~~~~~~~~~~~~
6
7    This script opens a shell for Zine.
8
9    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details.
10    :license: BSD, see LICENSE for more details.
11"""
12import sys
13from os.path import abspath, join, pardir, isfile, dirname
14from optparse import OptionParser
15from werkzeug.script import make_shell
16
17
18sys.path.append(dirname(__file__))
19from _init_zine import find_instance
20
21
22def init_func(instance):
23    from zine import setup
24    app = setup(instance)
25    del setup
26    from zine import models
27    from zine.database import db
28    return locals()
29
30
31def main():
32    parser = OptionParser(usage='%prog [options]')
33    parser.add_option('--no-ipython', dest='no_ipython', action='store_true',
34                      help='Do not launch ipython, even if present.')
35    parser.add_option('--instance', '-I', dest='instance',
36                      help='Use the path provided as Zine instance.')
37    options, args = parser.parse_args()
38    if args:
39        parser.error('incorrect number of arguments')
40    instance = options.instance or find_instance()
41    if instance is None:
42        parser.error('instance not found.  Specify path to instance')
43    if options.instance:
44        # Consume -I/--instance
45        for option in ('-I', '--instance'):
46            if option in sys.argv:
47                pop_index = sys.argv.index(option)
48                sys.argv.pop(pop_index) # pop option flag
49                sys.argv.pop(pop_index) # pop option value
50
51    make_shell(lambda: init_func(instance), banner='Zine Shell [%s]' %
52               abspath(instance))(ipython=not options.no_ipython)
53
54
55if __name__ == '__main__':
56    main()
Note: See TracBrowser for help on using the repository browser.