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