Mercurial > wikked
comparison wk.py @ 158:e53a3b64dfd8
Renamed main Wikked script.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 09 Jan 2014 20:59:41 -0800 |
parents | manage.py@f32af0888382 |
children | a71822a4beed |
comparison
equal
deleted
inserted
replaced
157:8529a9d42235 | 158:e53a3b64dfd8 |
---|---|
1 #!/usr/local/bin/python | |
2 | |
3 # Configure logging. | |
4 import logging | |
5 logging.basicConfig(level=logging.DEBUG) | |
6 | |
7 # Configure a simpler log format. | |
8 from wikked import settings | |
9 settings.LOG_FORMAT = "[%(levelname)s]: %(message)s" | |
10 settings.UPDATE_WIKI_ON_START = False | |
11 | |
12 # Create the app and the wiki. | |
13 from wikked.web import app, wiki | |
14 | |
15 # Create the manager. | |
16 from flask.ext.script import Manager, prompt, prompt_pass | |
17 manager = Manager(app) | |
18 | |
19 | |
20 @manager.command | |
21 def users(): | |
22 """Lists users of this wiki.""" | |
23 print "Users:" | |
24 for user in wiki.auth.getUsers(): | |
25 print " - " + user.username | |
26 print "" | |
27 | |
28 | |
29 @manager.command | |
30 def user(username=None, password=None): | |
31 """Generates the entry for a new user so you can | |
32 copy/paste it in your `.wikirc`. | |
33 """ | |
34 username = username or prompt('Username: ') | |
35 password = password or prompt_pass('Password: ') | |
36 password = app.bcrypt.generate_password_hash(password) | |
37 print "[users]" | |
38 print "%s = %s" % (username, password) | |
39 | |
40 | |
41 @manager.command | |
42 def reset(cache=False, index_only=False): | |
43 """ Re-generates the database and the full-text-search index. | |
44 """ | |
45 if index_only: | |
46 wiki.index.reset(wiki.getPages()) | |
47 else: | |
48 wiki.reset(cache_ext_data=cache) | |
49 | |
50 | |
51 @manager.command | |
52 def update(url=None, cache=False): | |
53 """ Updates the database and the full-text-search index with any | |
54 changed/new files. | |
55 """ | |
56 wiki.update(url, cache_ext_data=cache) | |
57 | |
58 | |
59 @manager.command | |
60 def cache(): | |
61 """ Makes sure the extended cache is valid for the whole wiki. | |
62 """ | |
63 wiki._cachePages() | |
64 | |
65 | |
66 @manager.command | |
67 def list(fs=False): | |
68 """ Lists page names in the wiki. | |
69 """ | |
70 if fs: | |
71 for pi in wiki.fs.getPageInfos(): | |
72 print pi.url | |
73 else: | |
74 for url in wiki.db.getPageUrls(): | |
75 print url | |
76 | |
77 | |
78 @manager.command | |
79 def get(url, force_resolve=False, rev=None): | |
80 """ Gets a page that matches the given URL. | |
81 """ | |
82 page = wiki.getPage(url) | |
83 if force_resolve: | |
84 page._force_resolve = True | |
85 if rev is not None: | |
86 print page.getRevision(rev) | |
87 return | |
88 print page.text | |
89 | |
90 | |
91 @manager.command | |
92 def search(query): | |
93 """ Searches the wiki. | |
94 """ | |
95 hits = wiki.index.search(query) | |
96 print hits | |
97 | |
98 | |
99 @manager.command | |
100 def linksfrom(url): | |
101 page = wiki.getPage(url) | |
102 for l in page.links: | |
103 print l | |
104 | |
105 | |
106 @manager.command | |
107 def linksto(url): | |
108 page = wiki.getPage(url) | |
109 for l in page.getIncomingLinks(): | |
110 print l | |
111 | |
112 | |
113 if __name__ == "__main__": | |
114 manager.run() | |
115 |