/
warp_plugin.py
97 lines (70 loc) · 2.76 KB
/
warp_plugin.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
94
95
96
97
from zope.interface import implements
import sys
from twisted.python import usage
from twisted.plugin import IPlugin
from twisted.application.service import IServiceMaker
from twisted.application import internet
from twisted.web.server import Site
from twisted.python.filepath import FilePath
from warp.webserver import resource, site
from warp.common import store, translate
from warp.iwarp import IWarpService
from warp import runtime
class SkeletonOptions(usage.Options):
optParameters = (
("siteDir", "d", ".", "Base directory of the warp site"),
)
class NodeOptions(usage.Options):
def parseArgs(self, name):
self['name'] = name
class Options(usage.Options):
optParameters = (
("siteDir", "d", ".", "Base directory of the warp site"),
)
subCommands = (
("skeleton", None, SkeletonOptions, "Copy Warp site skeleton into current directory"),
("node", None, NodeOptions, "Create a new node"),
("console", None, usage.Options, "Python console with Warp runtime available"),
)
class WarpServiceMaker(object):
implements(IServiceMaker, IPlugin, IWarpService)
tapname = "warp"
description = "Warp webserver"
options = Options
def makeService(self, options):
siteDir = FilePath(options['siteDir'])
if options.subCommand == "skeleton":
print "Creating skeleton..."
from warp.tools import skeleton
skeleton.createSkeleton(siteDir)
raise SystemExit
elif options.subCommand == "node":
nodes = siteDir.child("nodes")
if not nodes.exists():
print "Please run this from a Warp site directory"
raise SystemExit
from warp.tools import skeleton
skeleton.createNode(nodes, options.subOptions['name'])
raise SystemExit
sys.path.insert(0, siteDir.path)
configModule = __import__('warpconfig')
config = configModule.config
runtime.config.update(config)
runtime.config['siteDir'] = siteDir
runtime.config['warpDir'] = FilePath(runtime.__file__).parent()
store.setupStore(config)
translate.loadMessages()
if hasattr(configModule, 'startup'):
configModule.startup()
if options.subCommand == "console":
import code
locals = {'store': runtime.store}
c = code.InteractiveConsole(locals)
c.interact()
raise SystemExit
factory = site.WarpSite(resource.WarpResourceWrapper())
service = internet.TCPServer(config["port"], factory)
if hasattr(configModule, 'mungeService'):
service = configModule.mungeService(service)
return service
serviceMaker = WarpServiceMaker()