Mercurial > wikked
annotate 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 |
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 |
47 | 8 from wikked.page import Page, DatabasePage |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
9 |
47 | 10 # Create the manager. |
11 from flask.ext.script import Manager, prompt, prompt_pass | |
0 | 12 manager = Manager(app) |
13 | |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
14 |
0 | 15 @manager.command |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
16 def users(): |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
17 """Lists users of this wiki.""" |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
18 print "Users:" |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
19 for user in wiki.auth.getUsers(): |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
20 print " - " + user.username |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
21 print "" |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
22 |
47 | 23 |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
24 @manager.command |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
25 def new_user(): |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
26 """Generates the entry for a new user so you can |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
27 copy/paste it in your `.wikirc`. |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
28 """ |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
29 username = prompt('Username: ') |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
30 password = prompt_pass('Password: ') |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
31 password = app.bcrypt.generate_password_hash(password) |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
32 print "[users]" |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
33 print "%s = %s" % (username, password) |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
34 |
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 @manager.command |
47 | 37 def reset(): |
38 """ 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
|
39 """ |
47 | 40 wiki.db.reset(wiki.getPages(from_db=False, factory=Page.factory)) |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
41 wiki.index.reset(wiki.getPages()) |
0 | 42 |
43 | |
30
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
44 @manager.command |
47 | 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()) | |
51 | |
52 | |
53 @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
|
54 def list(): |
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
55 """ 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
|
56 """ |
47 | 57 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
|
58 print url |
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
59 |
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 @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 | |
67 | |
68 | |
0 | 69 if __name__ == "__main__": |
70 manager.run() |