Zine

open source content publishing system


source: scripts/reset-instance @ 1379:5c2fab16fcec

Revision 1379:5c2fab16fcec, 2.6 KB checked in by Thomas Waldmann <tw AT waldmann-edv DOT de>, 23 months ago (diff)

scripts: fix some typos, update compile-translations docstring

  • Property exe set to *
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3"""
4    Reset the Instance
5    ~~~~~~~~~~~~~~~~~~
6
7    This script resets the development instance.
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 import mkdir, path, listdir, unlink
14from shutil import rmtree
15from optparse import OptionParser
16
17
18sys.path.append(path.dirname(__file__))
19from _init_zine import find_instance
20
21
22def main():
23    parser = OptionParser(usage='%prog [path]')
24    parser.add_option('--username', '-u', dest='username', default='admin')
25    parser.add_option('--password', '-p', dest='password', default='default')
26    parser.add_option('--blog-url', dest='blog_url', default='http://localhost:4000/')
27    parser.add_option('--database', dest='database_uri', default='sqlite:///zine.db')
28    parser.add_option('--language', dest='lang', default='en')
29    parser.add_option('--keep-plugins', default=False, action='store_true')
30
31    options, args = parser.parse_args()
32    if not args:
33        instance = find_instance()
34        if instance is None:
35            parser.error('instance not found.  Specify path to instance')
36    elif len(args) == 1:
37        instance = args[0]
38    else:
39        parser.error('incorrect number of arguments')
40
41    print 'Resetting instance', instance
42
43    if not options.keep_plugins:
44        rmtree(instance)
45        mkdir(instance)
46    else:
47        for file in listdir(instance):
48            fpath = path.join(instance, file)
49            if path.isfile(fpath):
50                unlink(fpath)
51            elif path.isdir(fpath) and file != 'plugins':
52                rmtree(fpath)
53
54    import zine.application
55    from zine import setup
56    from zine.database import users, init_database, db
57    from zine.utils.crypto import gen_pwhash, gen_secret_key
58    from zine.config import Configuration
59    e = db.create_engine(options.database_uri, instance)
60    init_database(e)
61
62    cfg = Configuration(path.join(instance, 'zine.ini'))
63    t = cfg.edit()
64    t.update(
65        maintenance_mode=False,
66        blog_url=options.blog_url,
67        secret_key=gen_secret_key(),
68        database_uri=options.database_uri,
69        language=options.lang,
70        plugins='vessel_theme',
71        theme='vessel'
72    )
73    t.commit()
74
75    from zine.models import User
76    from zine.privileges import BLOG_ADMIN
77    app = setup(instance)
78    user = User(options.username, options.password, 'admin@localhost',
79                is_author=True)
80    user.own_privileges.add(BLOG_ADMIN)
81    db.commit()
82
83    print 'All done.'
84
85
86if __name__ == '__main__':
87    main()
Note: See TracBrowser for help on using the repository browser.