Switch branches/tags
Find file
Fetching contributors…
Cannot retrieve contributors at this time
143 lines (107 sloc) 4.35 KB
from zope.interface import implements
import sys
from twisted.python import usage, reflect
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"),
("config", "c", "warpconfig", "Default config module")
class NodeOptions(usage.Options):
def parseArgs(self, name):
self['name'] = name
class CrudOptions(usage.Options):
def parseArgs(self, name, model):
self['name'] = name
self['model'] = model
class CommandOptions(usage.Options):
def parseArgs(self, fqn):
self['fqn'] = fqn
class Options(usage.Options):
optParameters = (
("siteDir", "d", ".", "Base directory of the warp site"),
("config", "w", "warpconfig", "Config filename"),
subCommands = (
("skeleton", None, SkeletonOptions, "Copy Warp site skeleton into current directory"),
("node", None, NodeOptions, "Create a new node"),
("crud", None, CrudOptions, "Create a new CRUD node"),
("adduser", None, usage.Options, "Add a user (interactive)"),
("console", None, usage.Options, "Python console with Warp runtime available"),
("command", "c", CommandOptions, "Run a site-specific command"),
class WarpServiceMaker(object):
implements(IServiceMaker, IPlugin, IWarpService)
tapname = "warp"
description = "Warp webserver"
options = Options
def makeService(self, options):
siteDir = FilePath(options['siteDir'])
sys.path.insert(0, siteDir.path)
if options.subCommand == "skeleton":
print "Creating skeleton..."
from import skeleton
raise SystemExit
<<<<<<< HEAD
>>>>>>> brendon-master/master
configModule = reflect.namedModule(options['config'])
config = configModule.config
runtime.config['siteDir'] = siteDir
runtime.config['warpDir'] = FilePath(runtime.__file__).parent()
if options.subCommand == "node":
nodes = siteDir.child("nodes")
if not nodes.exists():
print "Please run this from a Warp site directory"
raise SystemExit
from import skeleton
skeleton.createNode(nodes, options.subOptions['name'])
raise SystemExit
elif options.subCommand == 'crud':
nodes = siteDir.child("nodes")
if not nodes.exists():
print "Please run this from a Warp site directory"
raise SystemExit
from import autocrud
autocrud.autocrud(nodes, options.subOptions['name'], options.subOptions['model'])
raise SystemExit
elif options.subCommand == 'adduser':
from import adduser
raise SystemExit
factory = site.WarpSite(resource.WarpResourceWrapper())
runtime.config['warpSite'] = factory
if hasattr(configModule, 'startup'):
if options.subCommand == "console":
import code
locals = {'store':}
c = code.InteractiveConsole(locals)
raise SystemExit
if options.subCommand == 'command':
obj = reflect.namedObject(options.subOptions['fqn'])
raise SystemExit
if config.get('ssl'):
from warp.webserver import sslcontext
service = internet.SSLServer(config['port'], factory,
service = internet.TCPServer(config["port"], factory)
if hasattr(configModule, 'mungeService'):
service = configModule.mungeService(service)
return service
serviceMaker = WarpServiceMaker()