Mercurial > wikked
annotate manage.py @ 54:9dfbc2a40b71
Formatter changes:
- Refactored `PageResolver` with something that makes more sense.
- Fixed some bugs with advanced include/meta scenarios.
- Added more tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 02 Feb 2013 20:16:54 -0800 |
parents | 8167b9b6925a |
children | 494f3c4660ed |
rev | line source |
---|---|
47 | 1 |
2 # Configure a simpler log format. | |
3 from wikked import settings | |
4 settings.LOG_FORMAT = "[%(levelname)s]: %(message)s" | |
5 | |
6 # Create the app and the wiki. | |
45
f63a2062fb99
Moved application init to a standalone `web` module.
Ludovic Chabant <ludovic@chabant.com>
parents:
30
diff
changeset
|
7 from wikked.web import app, wiki |
52
8167b9b6925a
Don't open/close connections all the time in command-line.
Ludovic Chabant <ludovic@chabant.com>
parents:
47
diff
changeset
|
8 from wikked.page import Page |
8167b9b6925a
Don't open/close connections all the time in command-line.
Ludovic Chabant <ludovic@chabant.com>
parents:
47
diff
changeset
|
9 from wikked.db import conn_scope |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
10 |
47 | 11 # Create the manager. |
12 from flask.ext.script import Manager, prompt, prompt_pass | |
0 | 13 manager = Manager(app) |
14 | |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
15 |
0 | 16 @manager.command |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
17 def users(): |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
18 """Lists users of this wiki.""" |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
19 print "Users:" |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
20 for user in wiki.auth.getUsers(): |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
21 print " - " + user.username |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
22 print "" |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
23 |
47 | 24 |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
25 @manager.command |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
26 def new_user(): |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
27 """Generates the entry for a new user so you can |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
28 copy/paste it in your `.wikirc`. |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
29 """ |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
30 username = prompt('Username: ') |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
31 password = prompt_pass('Password: ') |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
32 password = app.bcrypt.generate_password_hash(password) |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
33 print "[users]" |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
34 print "%s = %s" % (username, password) |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
35 |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
36 |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
37 @manager.command |
47 | 38 def reset(): |
39 """ Re-generates the database and the full-text-search index. | |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
40 """ |
52
8167b9b6925a
Don't open/close connections all the time in command-line.
Ludovic Chabant <ludovic@chabant.com>
parents:
47
diff
changeset
|
41 with conn_scope(wiki.db): |
8167b9b6925a
Don't open/close connections all the time in command-line.
Ludovic Chabant <ludovic@chabant.com>
parents:
47
diff
changeset
|
42 wiki.db.reset(wiki.getPages(from_db=False, factory=Page.factory)) |
8167b9b6925a
Don't open/close connections all the time in command-line.
Ludovic Chabant <ludovic@chabant.com>
parents:
47
diff
changeset
|
43 wiki.index.reset(wiki.getPages()) |
0 | 44 |
45 | |
30
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
46 @manager.command |
47 | 47 def update(): |
48 """ Updates the database and the full-text-search index with any | |
49 changed/new files. | |
50 """ | |
52
8167b9b6925a
Don't open/close connections all the time in command-line.
Ludovic Chabant <ludovic@chabant.com>
parents:
47
diff
changeset
|
51 with conn_scope(wiki.db): |
8167b9b6925a
Don't open/close connections all the time in command-line.
Ludovic Chabant <ludovic@chabant.com>
parents:
47
diff
changeset
|
52 wiki.db.update(wiki.getPages(from_db=False, factory=Page.factory)) |
8167b9b6925a
Don't open/close connections all the time in command-line.
Ludovic Chabant <ludovic@chabant.com>
parents:
47
diff
changeset
|
53 wiki.index.update(wiki.getPages()) |
47 | 54 |
55 | |
56 @manager.command | |
30
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
57 def list(): |
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
58 """ Lists page names in the wiki. |
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
59 """ |
47 | 60 for url in wiki.db.getPageUrls(): |
30
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
61 print url |
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
62 |
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
63 |
47 | 64 @manager.command |
65 def get(url): | |
66 """ Gets a page that matches the given URL. | |
67 """ | |
68 page = wiki.getPage(url) | |
69 print page.text | |
70 | |
71 | |
0 | 72 if __name__ == "__main__": |
73 manager.run() |