PageRenderTime 78ms CodeModel.GetById 45ms app.highlight 6ms RepoModel.GetById 25ms app.codeStats 1ms

/kai/websetup.py

https://bitbucket.org/bbangert/kai/
Python | 49 lines | 32 code | 14 blank | 3 comment | 2 complexity | db98e0b1c260b1b67d1dcbe2e750259c MD5 | raw file
 1"""Setup the kai application"""
 2import logging
 3
 4from couchdb.design import ViewDefinition
 5import pylons
 6import pylons.test
 7
 8from kai.config.environment import load_environment
 9from kai.model import Article, Comment, Documentation, Human, Paste, Rating, Snippet, Traceback
10from kai.model.generics import all_doc_tags
11
12log = logging.getLogger(__name__)
13
14def sync_db(db):
15    ViewDefinition.sync_many(db, [
16        all_doc_tags,
17        
18        Article.all_months, Article.all_tags, Article.by_month,
19        Article.by_tag, Article.by_time, Article.by_slug,
20        
21        Comment.by_time, Comment.comment_count, Comment.by_anytime,
22        
23        Documentation.by_path, Documentation.ids_for_version,
24        Documentation.doc_key,
25        
26        Human.by_displayname, Human.by_email, Human.by_email_token,
27        Human.by_openid, Human.by_password_token,
28        
29        Paste.by_author, Paste.by_tag, Paste.all_tags, Paste.by_time,
30        Paste.by_old_id, Paste.by_tag_time, Paste.by_session_id,
31        
32        Rating.all_raters,
33        
34        Snippet.by_date, Snippet.by_author, Snippet.by_slug, Snippet.by_title,
35        Snippet.by_author_id, Snippet.by_tag, Snippet.all_tags,
36        Snippet.author_totals,
37        
38        Traceback.by_uuid, Traceback.by_time, Traceback.by_session_id,
39    ])
40
41def setup_app(command, conf, vars):
42    """Place any commands to setup kai here"""
43    # Don't reload the app if it was loaded under the testing environment
44    if not pylons.test.pylonsapp:
45        load_environment(conf.global_conf, conf.local_conf)
46    
47    server = pylons.config['kai.server']
48    db = pylons.config['kai.db']
49    sync_db(db)