Mercurial > wikked
annotate manage.py @ 86:d04f15af79ad
Added `data-action` info on wiki links, removed unecessary templating.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 03 Apr 2013 23:58:30 -0700 |
parents | 494f3c4660ed |
children | 13249e5ca51c |
rev | line source |
---|---|
47 | 1 |
2 # Configure a simpler log format. | |
3 from wikked import settings | |
4 settings.LOG_FORMAT = "[%(levelname)s]: %(message)s" | |
55 | 5 settings.UPDATE_WIKI_ON_START = False |
47 | 6 |
7 # 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
|
8 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
|
9 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
|
10 from wikked.db import conn_scope |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
11 |
47 | 12 # Create the manager. |
13 from flask.ext.script import Manager, prompt, prompt_pass | |
0 | 14 manager = Manager(app) |
15 | |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
16 |
0 | 17 @manager.command |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
18 def users(): |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
19 """Lists users of this wiki.""" |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
20 print "Users:" |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
21 for user in wiki.auth.getUsers(): |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
22 print " - " + user.username |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
23 print "" |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
24 |
47 | 25 |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
26 @manager.command |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
27 def new_user(): |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
28 """Generates the entry for a new user so you can |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
29 copy/paste it in your `.wikirc`. |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
30 """ |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
31 username = prompt('Username: ') |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
32 password = prompt_pass('Password: ') |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
33 password = app.bcrypt.generate_password_hash(password) |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
34 print "[users]" |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
35 print "%s = %s" % (username, password) |
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 |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
38 @manager.command |
47 | 39 def reset(): |
40 """ 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
|
41 """ |
52
8167b9b6925a
Don't open/close connections all the time in command-line.
Ludovic Chabant <ludovic@chabant.com>
parents:
47
diff
changeset
|
42 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
|
43 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
|
44 wiki.index.reset(wiki.getPages()) |
0 | 45 |
46 | |
30
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
47 @manager.command |
47 | 48 def update(): |
49 """ Updates the database and the full-text-search index with any | |
50 changed/new files. | |
51 """ | |
52
8167b9b6925a
Don't open/close connections all the time in command-line.
Ludovic Chabant <ludovic@chabant.com>
parents:
47
diff
changeset
|
52 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
|
53 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
|
54 wiki.index.update(wiki.getPages()) |
47 | 55 |
56 | |
57 @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
|
58 def list(): |
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
59 """ 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
|
60 """ |
47 | 61 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
|
62 print url |
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
63 |
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
64 |
47 | 65 @manager.command |
66 def get(url): | |
67 """ Gets a page that matches the given URL. | |
68 """ | |
55 | 69 with conn_scope(wiki.db): |
70 page = wiki.getPage(url) | |
71 print page.text | |
47 | 72 |
73 | |
0 | 74 if __name__ == "__main__": |
75 manager.run() |