Mercurial > wikked
annotate manage.py @ 151:f32af0888382
Added support for ElasticSearch indexing:
- More configurable setup for wiki providers (SCM, indexing, etc.).
- Lazy importing of provider specific packages.
- Nicer search results.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 16 Dec 2013 20:59:42 -0800 |
parents | 9d22cf4d2412 |
children |
rev | line source |
---|---|
131
9d22cf4d2412
Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
129
diff
changeset
|
1 |
9d22cf4d2412
Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
129
diff
changeset
|
2 # Configure logging. |
9d22cf4d2412
Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
129
diff
changeset
|
3 import logging |
9d22cf4d2412
Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
129
diff
changeset
|
4 logging.basicConfig(level=logging.DEBUG) |
47 | 5 |
6 # Configure a simpler log format. | |
7 from wikked import settings | |
8 settings.LOG_FORMAT = "[%(levelname)s]: %(message)s" | |
55 | 9 settings.UPDATE_WIKI_ON_START = False |
47 | 10 |
11 # 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
|
12 from wikked.web import app, wiki |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
13 |
47 | 14 # Create the manager. |
15 from flask.ext.script import Manager, prompt, prompt_pass | |
0 | 16 manager = Manager(app) |
17 | |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
18 |
0 | 19 @manager.command |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
20 def users(): |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
21 """Lists users of this wiki.""" |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
22 print "Users:" |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
23 for user in wiki.auth.getUsers(): |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
24 print " - " + user.username |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
25 print "" |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
26 |
47 | 27 |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
28 @manager.command |
101
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
29 def user(username=None, password=None): |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
30 """Generates the entry for a new user so you can |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
31 copy/paste it in your `.wikirc`. |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
32 """ |
101
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
33 username = username or prompt('Username: ') |
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
34 password = password or prompt_pass('Password: ') |
13
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
35 password = app.bcrypt.generate_password_hash(password) |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
36 print "[users]" |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
37 print "%s = %s" % (username, password) |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
38 |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
39 |
30ae685b86df
Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
40 @manager.command |
151
f32af0888382
Added support for ElasticSearch indexing:
Ludovic Chabant <ludovic@chabant.com>
parents:
131
diff
changeset
|
41 def reset(cache=False, index_only=False): |
47 | 42 """ 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
|
43 """ |
151
f32af0888382
Added support for ElasticSearch indexing:
Ludovic Chabant <ludovic@chabant.com>
parents:
131
diff
changeset
|
44 if index_only: |
f32af0888382
Added support for ElasticSearch indexing:
Ludovic Chabant <ludovic@chabant.com>
parents:
131
diff
changeset
|
45 wiki.index.reset(wiki.getPages()) |
f32af0888382
Added support for ElasticSearch indexing:
Ludovic Chabant <ludovic@chabant.com>
parents:
131
diff
changeset
|
46 else: |
f32af0888382
Added support for ElasticSearch indexing:
Ludovic Chabant <ludovic@chabant.com>
parents:
131
diff
changeset
|
47 wiki.reset(cache_ext_data=cache) |
0 | 48 |
49 | |
30
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
50 @manager.command |
121
7c7f7eca51ae
Don't re-cache all pages by default with some CLI commands.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
51 def update(url=None, cache=False): |
47 | 52 """ Updates the database and the full-text-search index with any |
53 changed/new files. | |
54 """ | |
121
7c7f7eca51ae
Don't re-cache all pages by default with some CLI commands.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
55 wiki.update(url, cache_ext_data=cache) |
47 | 56 |
57 | |
58 @manager.command | |
131
9d22cf4d2412
Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
129
diff
changeset
|
59 def cache(): |
9d22cf4d2412
Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
129
diff
changeset
|
60 """ Makes sure the extended cache is valid for the whole wiki. |
9d22cf4d2412
Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
129
diff
changeset
|
61 """ |
9d22cf4d2412
Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
129
diff
changeset
|
62 wiki._cachePages() |
9d22cf4d2412
Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
129
diff
changeset
|
63 |
9d22cf4d2412
Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
129
diff
changeset
|
64 |
9d22cf4d2412
Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
129
diff
changeset
|
65 @manager.command |
129
ace48040b01d
Added CLI option to list pages from the file-system.
Ludovic Chabant <ludovic@chabant.com>
parents:
123
diff
changeset
|
66 def list(fs=False): |
30
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
67 """ 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
|
68 """ |
129
ace48040b01d
Added CLI option to list pages from the file-system.
Ludovic Chabant <ludovic@chabant.com>
parents:
123
diff
changeset
|
69 if fs: |
ace48040b01d
Added CLI option to list pages from the file-system.
Ludovic Chabant <ludovic@chabant.com>
parents:
123
diff
changeset
|
70 for pi in wiki.fs.getPageInfos(): |
ace48040b01d
Added CLI option to list pages from the file-system.
Ludovic Chabant <ludovic@chabant.com>
parents:
123
diff
changeset
|
71 print pi.url |
ace48040b01d
Added CLI option to list pages from the file-system.
Ludovic Chabant <ludovic@chabant.com>
parents:
123
diff
changeset
|
72 else: |
ace48040b01d
Added CLI option to list pages from the file-system.
Ludovic Chabant <ludovic@chabant.com>
parents:
123
diff
changeset
|
73 for url in wiki.db.getPageUrls(): |
ace48040b01d
Added CLI option to list pages from the file-system.
Ludovic Chabant <ludovic@chabant.com>
parents:
123
diff
changeset
|
74 print url |
30
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
75 |
420ff74c2e28
Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
76 |
47 | 77 @manager.command |
123
ac6166453d77
Added ability to get page revisions from the command-line.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
78 def get(url, force_resolve=False, rev=None): |
47 | 79 """ Gets a page that matches the given URL. |
80 """ | |
101
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
81 page = wiki.getPage(url) |
123
ac6166453d77
Added ability to get page revisions from the command-line.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
82 if force_resolve: |
108
5c24e8f8b095
Added support for the `force_resolve` flag.
Ludovic Chabant <ludovic@chabant.com>
parents:
101
diff
changeset
|
83 page._force_resolve = True |
123
ac6166453d77
Added ability to get page revisions from the command-line.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
84 if rev is not None: |
ac6166453d77
Added ability to get page revisions from the command-line.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
85 print page.getRevision(rev) |
ac6166453d77
Added ability to get page revisions from the command-line.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
86 return |
101
13249e5ca51c
Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
87 print page.text |
47 | 88 |
89 | |
112
a65cedc183d6
Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents:
108
diff
changeset
|
90 @manager.command |
151
f32af0888382
Added support for ElasticSearch indexing:
Ludovic Chabant <ludovic@chabant.com>
parents:
131
diff
changeset
|
91 def search(query): |
f32af0888382
Added support for ElasticSearch indexing:
Ludovic Chabant <ludovic@chabant.com>
parents:
131
diff
changeset
|
92 """ Searches the wiki. |
f32af0888382
Added support for ElasticSearch indexing:
Ludovic Chabant <ludovic@chabant.com>
parents:
131
diff
changeset
|
93 """ |
f32af0888382
Added support for ElasticSearch indexing:
Ludovic Chabant <ludovic@chabant.com>
parents:
131
diff
changeset
|
94 hits = wiki.index.search(query) |
f32af0888382
Added support for ElasticSearch indexing:
Ludovic Chabant <ludovic@chabant.com>
parents:
131
diff
changeset
|
95 print hits |
f32af0888382
Added support for ElasticSearch indexing:
Ludovic Chabant <ludovic@chabant.com>
parents:
131
diff
changeset
|
96 |
f32af0888382
Added support for ElasticSearch indexing:
Ludovic Chabant <ludovic@chabant.com>
parents:
131
diff
changeset
|
97 |
f32af0888382
Added support for ElasticSearch indexing:
Ludovic Chabant <ludovic@chabant.com>
parents:
131
diff
changeset
|
98 @manager.command |
112
a65cedc183d6
Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents:
108
diff
changeset
|
99 def linksfrom(url): |
a65cedc183d6
Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents:
108
diff
changeset
|
100 page = wiki.getPage(url) |
a65cedc183d6
Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents:
108
diff
changeset
|
101 for l in page.links: |
a65cedc183d6
Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents:
108
diff
changeset
|
102 print l |
a65cedc183d6
Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents:
108
diff
changeset
|
103 |
a65cedc183d6
Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents:
108
diff
changeset
|
104 |
a65cedc183d6
Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents:
108
diff
changeset
|
105 @manager.command |
a65cedc183d6
Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents:
108
diff
changeset
|
106 def linksto(url): |
a65cedc183d6
Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents:
108
diff
changeset
|
107 page = wiki.getPage(url) |
a65cedc183d6
Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents:
108
diff
changeset
|
108 for l in page.getIncomingLinks(): |
a65cedc183d6
Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents:
108
diff
changeset
|
109 print l |
a65cedc183d6
Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents:
108
diff
changeset
|
110 |
a65cedc183d6
Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents:
108
diff
changeset
|
111 |
0 | 112 if __name__ == "__main__": |
113 manager.run() |