comparison manage.py @ 101:13249e5ca51c

Big refactor for better database caching: - Using SQL alchemy instead of raw SQLite. - Better architecture and internal APIs. - Fixed some issues where the database was not used correctly. - Fixed some problems with querying pages. Got rid of `Makefile`, now using `grunt`. Now using a custom `Bootstrap` include file.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 05 Nov 2013 08:13:18 -0800
parents 494f3c4660ed
children 5c24e8f8b095
comparison
equal deleted inserted replaced
100:fd6eccb24882 101:13249e5ca51c
4 settings.LOG_FORMAT = "[%(levelname)s]: %(message)s" 4 settings.LOG_FORMAT = "[%(levelname)s]: %(message)s"
5 settings.UPDATE_WIKI_ON_START = False 5 settings.UPDATE_WIKI_ON_START = False
6 6
7 # Create the app and the wiki. 7 # Create the app and the wiki.
8 from wikked.web import app, wiki 8 from wikked.web import app, wiki
9 from wikked.page import Page 9 from wikked.page import FileSystemPage
10 from wikked.db import conn_scope
11 10
12 # Create the manager. 11 # Create the manager.
13 from flask.ext.script import Manager, prompt, prompt_pass 12 from flask.ext.script import Manager, prompt, prompt_pass
14 manager = Manager(app) 13 manager = Manager(app)
15 14
22 print " - " + user.username 21 print " - " + user.username
23 print "" 22 print ""
24 23
25 24
26 @manager.command 25 @manager.command
27 def new_user(): 26 def user(username=None, password=None):
28 """Generates the entry for a new user so you can 27 """Generates the entry for a new user so you can
29 copy/paste it in your `.wikirc`. 28 copy/paste it in your `.wikirc`.
30 """ 29 """
31 username = prompt('Username: ') 30 username = username or prompt('Username: ')
32 password = prompt_pass('Password: ') 31 password = password or prompt_pass('Password: ')
33 password = app.bcrypt.generate_password_hash(password) 32 password = app.bcrypt.generate_password_hash(password)
34 print "[users]" 33 print "[users]"
35 print "%s = %s" % (username, password) 34 print "%s = %s" % (username, password)
36 35
37 36
38 @manager.command 37 @manager.command
39 def reset(): 38 def reset():
40 """ Re-generates the database and the full-text-search index. 39 """ Re-generates the database and the full-text-search index.
41 """ 40 """
42 with conn_scope(wiki.db): 41 page_infos = wiki.fs.getPageInfos()
43 wiki.db.reset(wiki.getPages(from_db=False, factory=Page.factory)) 42 fs_pages = FileSystemPage.fromPageInfos(wiki, page_infos)
44 wiki.index.reset(wiki.getPages()) 43 wiki.db.reset(fs_pages)
44 wiki.index.reset(wiki.getPages())
45 45
46 46
47 @manager.command 47 @manager.command
48 def update(): 48 def update():
49 """ Updates the database and the full-text-search index with any 49 """ Updates the database and the full-text-search index with any
50 changed/new files. 50 changed/new files.
51 """ 51 """
52 with conn_scope(wiki.db): 52 page_infos = wiki.fs.getPageInfos()
53 wiki.db.update(wiki.getPages(from_db=False, factory=Page.factory)) 53 fs_pages = FileSystemPage.fromPageInfos(wiki, page_infos)
54 wiki.index.update(wiki.getPages()) 54 wiki.db.update(fs_pages)
55 wiki.index.update(wiki.getPages())
55 56
56 57
57 @manager.command 58 @manager.command
58 def list(): 59 def list():
59 """ Lists page names in the wiki. 60 """ Lists page names in the wiki.
64 65
65 @manager.command 66 @manager.command
66 def get(url): 67 def get(url):
67 """ Gets a page that matches the given URL. 68 """ Gets a page that matches the given URL.
68 """ 69 """
69 with conn_scope(wiki.db): 70 page = wiki.getPage(url)
70 page = wiki.getPage(url) 71 print page.text
71 print page.text
72 72
73 73
74 if __name__ == "__main__": 74 if __name__ == "__main__":
75 manager.run() 75 manager.run()