-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
executable file
·93 lines (73 loc) · 2.03 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!env/bin/python
"""Usage: manage.py command
Options:
-h --help show this help message and exit
Subcommands:
dumpdata <path> Dump all node data to the given file.
loaddata <path> Load node data from the given file.
flushdb Destroys all data in the database.
"""
import sys, json
from config import redis
def usage(status=-1):
print "Usage: python manage.py <command>"
print "Available commands:"
print " help - Prints this help."
print " dumpdata <path> - Dumps all nodes to the given file."
print " loaddata <path> - Loads data from the given file."
print " flushdb - Destroys all data in the database."
sys.exit(status)
if len(sys.argv) < 2:
usage()
command = sys.argv[1]
if command == 'help':
usage(0)
if command == 'runserver':
from wsgi import app
app.run(debug = True)
elif command == 'dumpdata':
try:
path = sys.argv[2]
except:
usage()
with open(path, "w") as o:
o.write("[\n ")
first = True
for key in redis.keys("n:*"):
try:
src = redis.get(key)
except:
continue
if not first:
o.write(",\n ")
o.write(src)
first = False
o.write("\n]")
print "Dumped data to %s" % path
elif command == "loaddata":
try:
path = sys.argv[2]
except:
usage()
with open(path) as o:
data = json.load(o)
for node in data:
redis.set( 'n:' + node['slug'], json.dumps(node))
print "Loadded data from %s" % path
elif command == 'fixdb':
import wiki, search
types = wiki.get_types()
for k, v in types.items():
if k == 'type':
continue
try:
wiki.put_type(k, v)
except wiki.FormError, e:
print e.field
search.rebuild_index()
wiki.rebuild_nodes()
print "Wiki Rebuilt."
elif command == 'flushdb':
redis.flushdb()
else:
usage()