-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadmin.py
58 lines (45 loc) · 1.44 KB
/
admin.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
#!/usr/bin/env python
# encoding: utf-8
"""
admin.py
Created by mark henderson on 2013-01-12.
Copyright (c) 2013 __MyCompanyName__. All rights reserved.
"""
import sys
import os
import config
from tornado.options import options
class Theme(object):
usage = 'admin.py theme [enable|disable] theme_name'
def __init__(self, name):
self.name = name
self.source = os.path.join(options.site_root, options.theme_dir, self.name, 'static')
self.dest = os.path.join(options.site_root, options.static_dir, self.name)
def enable(self):
if not os.path.lexists(self.dest):
os.symlink(self.source, self.dest)
return 'Theme: %s enabled' % self.name
else:
raise Exception('Theme: %s is already enabled' % self.name)
def disable(self):
if os.path.lexists(self.dest):
os.unlink(self.dest)
return 'Theme: %s disabled' % self.name
else:
raise Exception('Theme: %s is not enabled' % self.name)
def get_help():
return """
Usage:
Theme management:
%s
""" % (Theme.usage)
if __name__ == '__main__':
try:
args = sys.argv
if len(args) < 4 or args[1] != 'theme' or args[2] not in ['enable', 'disable']:
print get_help()
else:
theme = Theme(args[3])
print getattr(theme, args[2])()
except Exception, e:
print e