File: manage-simplewiki.py

package info (click to toggle)
python-werkzeug 0.8.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,940 kB
  • sloc: python: 16,194; makefile: 143; pascal: 66; xml: 16
file content (46 lines) | stat: -rwxr-xr-x 1,119 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
    Manage SimpleWiki
    ~~~~~~~~~~~~~~~~~

    This script provides some basic commands to debug and test SimpleWiki.

    :copyright: (c) 2009 by the Werkzeug Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
"""
import os
from werkzeug import script


def make_wiki():
    """Helper function that creates a new wiki instance."""
    from simplewiki import SimpleWiki
    database_uri = os.environ.get('SIMPLEWIKI_DATABASE_URI')
    return SimpleWiki(database_uri or 'sqlite:////tmp/simplewiki.db')


def shell_init_func():
    """
    Called on shell initialization.  Adds useful stuff to the namespace.
    """
    from simplewiki import database
    wiki = make_wiki()
    wiki.bind_to_context()
    return {
        'wiki':     wiki,
        'db':       database
    }


action_runserver = script.make_runserver(make_wiki, use_reloader=True)
action_shell = script.make_shell(shell_init_func)


def action_initdb():
    """Initialize the database"""
    make_wiki().init_database()


if __name__ == '__main__':
    script.run()