annotate manage.py @ 125:886f36b05e5f

More optimized `watch` mode for `grunt`.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 24 Nov 2013 14:04:05 -0800
parents ac6166453d77
children ace48040b01d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
1
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
2 # Configure a simpler log format.
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
3 from wikked import settings
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
4 settings.LOG_FORMAT = "[%(levelname)s]: %(message)s"
55
494f3c4660ed Various changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
5 settings.UPDATE_WIKI_ON_START = False
47
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
6
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
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
13
30ae685b86df Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
9
47
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
10 # Create the manager.
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
11 from flask.ext.script import Manager, prompt, prompt_pass
0
c946f4facfa2 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 manager = Manager(app)
c946f4facfa2 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13
13
30ae685b86df Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
14
0
c946f4facfa2 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
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
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
23
13
30ae685b86df Added support for authentatication
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
24 @manager.command
101
13249e5ca51c Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents: 55
diff changeset
25 def user(username=None, password=None):
13
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 """
101
13249e5ca51c Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents: 55
diff changeset
29 username = username or prompt('Username: ')
13249e5ca51c Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents: 55
diff changeset
30 password = password or prompt_pass('Password: ')
13
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
121
7c7f7eca51ae Don't re-cache all pages by default with some CLI commands.
Ludovic Chabant <ludovic@chabant.com>
parents: 112
diff changeset
37 def reset(cache=False):
47
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
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 """
121
7c7f7eca51ae Don't re-cache all pages by default with some CLI commands.
Ludovic Chabant <ludovic@chabant.com>
parents: 112
diff changeset
40 wiki.reset(cache_ext_data=cache)
0
c946f4facfa2 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41
c946f4facfa2 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42
30
420ff74c2e28 Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents: 13
diff changeset
43 @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
44 def update(url=None, cache=False):
47
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
45 """ Updates the database and the full-text-search index with any
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
46 changed/new files.
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
47 """
121
7c7f7eca51ae Don't re-cache all pages by default with some CLI commands.
Ludovic Chabant <ludovic@chabant.com>
parents: 112
diff changeset
48 wiki.update(url, cache_ext_data=cache)
47
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
49
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
50
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
51 @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
52 def list():
420ff74c2e28 Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents: 13
diff changeset
53 """ 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
54 """
47
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
55 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
56 print url
420ff74c2e28 Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents: 13
diff changeset
57
420ff74c2e28 Added a shell command to list all the pages in the wiki.
Ludovic Chabant <ludovic@chabant.com>
parents: 13
diff changeset
58
47
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
59 @manager.command
123
ac6166453d77 Added ability to get page revisions from the command-line.
Ludovic Chabant <ludovic@chabant.com>
parents: 121
diff changeset
60 def get(url, force_resolve=False, rev=None):
47
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
61 """ Gets a page that matches the given URL.
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
62 """
101
13249e5ca51c Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents: 55
diff changeset
63 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
64 if force_resolve:
108
5c24e8f8b095 Added support for the `force_resolve` flag.
Ludovic Chabant <ludovic@chabant.com>
parents: 101
diff changeset
65 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
66 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
67 print page.getRevision(rev)
ac6166453d77 Added ability to get page revisions from the command-line.
Ludovic Chabant <ludovic@chabant.com>
parents: 121
diff changeset
68 return
101
13249e5ca51c Big refactor for better database caching:
Ludovic Chabant <ludovic@chabant.com>
parents: 55
diff changeset
69 print page.text
47
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
70
86ee1b696070 Big refactoring:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
71
112
a65cedc183d6 Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents: 108
diff changeset
72 @manager.command
a65cedc183d6 Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents: 108
diff changeset
73 def linksfrom(url):
a65cedc183d6 Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents: 108
diff changeset
74 page = wiki.getPage(url)
a65cedc183d6 Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents: 108
diff changeset
75 for l in page.links:
a65cedc183d6 Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents: 108
diff changeset
76 print l
a65cedc183d6 Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents: 108
diff changeset
77
a65cedc183d6 Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents: 108
diff changeset
78
a65cedc183d6 Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents: 108
diff changeset
79 @manager.command
a65cedc183d6 Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents: 108
diff changeset
80 def linksto(url):
a65cedc183d6 Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents: 108
diff changeset
81 page = wiki.getPage(url)
a65cedc183d6 Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents: 108
diff changeset
82 for l in page.getIncomingLinks():
a65cedc183d6 Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents: 108
diff changeset
83 print l
a65cedc183d6 Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents: 108
diff changeset
84
a65cedc183d6 Added more functions to the `manage` CLI tool.
Ludovic Chabant <ludovic@chabant.com>
parents: 108
diff changeset
85
0
c946f4facfa2 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 if __name__ == "__main__":
c946f4facfa2 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87 manager.run()