Mercurial > wikked
annotate manage.py @ 101:13249e5ca51c
Big refactor for better database caching:
- Using SQL alchemy instead of raw SQLite.
- Better architecture and internal APIs.
- Fixed some issues where the database was not used correctly.
- Fixed some problems with querying pages.
Got rid of `Makefile`, now using `grunt`.
Now using a custom `Bootstrap` include file.
| author | Ludovic Chabant <ludovic@chabant.com> |
|---|---|
| date | Tue, 05 Nov 2013 08:13:18 -0800 |
| parents | 494f3c4660ed |
| children | 5c24e8f8b095 |
| 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 |
|
101
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
9 from wikked.page import FileSystemPage |
|
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 |
|
101
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
26 def user(username=None, password=None): |
|
13
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 """ |
|
101
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
30 username = username or prompt('Username: ') |
|
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
31 password = password or prompt_pass('Password: ') |
|
13
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 """ |
|
101
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
41 page_infos = wiki.fs.getPageInfos() |
|
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
42 fs_pages = FileSystemPage.fromPageInfos(wiki, page_infos) |
|
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
43 wiki.db.reset(fs_pages) |
|
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
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 """ | |
|
101
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
52 page_infos = wiki.fs.getPageInfos() |
|
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
53 fs_pages = FileSystemPage.fromPageInfos(wiki, page_infos) |
|
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
54 wiki.db.update(fs_pages) |
|
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
55 wiki.index.update(wiki.getPages()) |
| 47 | 56 |
| 57 | |
| 58 @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
|
59 def list(): |
|
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
60 """ 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
|
61 """ |
| 47 | 62 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
|
63 print url |
|
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
64 |
|
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
65 |
| 47 | 66 @manager.command |
| 67 def get(url): | |
| 68 """ Gets a page that matches the given URL. | |
| 69 """ | |
|
101
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
70 page = wiki.getPage(url) |
|
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
71 print page.text |
| 47 | 72 |
| 73 | |
| 0 | 74 if __name__ == "__main__": |
| 75 manager.run() |
