comparison manage.py @ 47:86ee1b696070

Big refactoring: - Trying to simplify APIs - Use SQLite to cache information
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 25 Jan 2013 22:35:56 -0800
parents f63a2062fb99
children 8167b9b6925a
comparison
equal deleted inserted replaced
46:0b6ce6837d22 47:86ee1b696070
1 import os.path 1
2 import logging 2 # Configure a simpler log format.
3 from flask.ext.script import Manager, Command, prompt, prompt_pass 3 from wikked import settings
4 settings.LOG_FORMAT = "[%(levelname)s]: %(message)s"
5
6 # Create the app and the wiki.
4 from wikked.web import app, wiki 7 from wikked.web import app, wiki
8 from wikked.page import Page, DatabasePage
5 9
6 10 # Create the manager.
11 from flask.ext.script import Manager, prompt, prompt_pass
7 manager = Manager(app) 12 manager = Manager(app)
8 13
9 14
10 @manager.command 15 @manager.command
11 def users(): 16 def users():
12 """Lists users of this wiki.""" 17 """Lists users of this wiki."""
13 print "Users:" 18 print "Users:"
14 for user in wiki.auth.getUsers(): 19 for user in wiki.auth.getUsers():
15 print " - " + user.username 20 print " - " + user.username
16 print "" 21 print ""
22
17 23
18 @manager.command 24 @manager.command
19 def new_user(): 25 def new_user():
20 """Generates the entry for a new user so you can 26 """Generates the entry for a new user so you can
21 copy/paste it in your `.wikirc`. 27 copy/paste it in your `.wikirc`.
26 print "[users]" 32 print "[users]"
27 print "%s = %s" % (username, password) 33 print "%s = %s" % (username, password)
28 34
29 35
30 @manager.command 36 @manager.command
31 def reset_index(): 37 def reset():
32 """ Re-generates the index, if search is broken 38 """ Re-generates the database and the full-text-search index.
33 somehow in your wiki.
34 """ 39 """
40 wiki.db.reset(wiki.getPages(from_db=False, factory=Page.factory))
35 wiki.index.reset(wiki.getPages()) 41 wiki.index.reset(wiki.getPages())
42
43
44 @manager.command
45 def update():
46 """ Updates the database and the full-text-search index with any
47 changed/new files.
48 """
49 wiki.db.update(wiki.getPages(from_db=False, factory=Page.factory))
50 wiki.index.update(wiki.getPages())
36 51
37 52
38 @manager.command 53 @manager.command
39 def list(): 54 def list():
40 """ Lists page names in the wiki. 55 """ Lists page names in the wiki.
41 """ 56 """
42 for url in wiki.getPageUrls(): 57 for url in wiki.db.getPageUrls():
43 print url 58 print url
59
60
61 @manager.command
62 def get(url):
63 """ Gets a page that matches the given URL.
64 """
65 page = wiki.getPage(url)
66 print page.text
44 67
45 68
46 if __name__ == "__main__": 69 if __name__ == "__main__":
47 manager.run() 70 manager.run()
48