Sorry, forgot the new paster command; it's not in svn so it wasn't included in the svn diff.
pastescript's ServerCommand could be rewritten to subclass this run.py's RunCommand command. -- David D. Smith
#!/usr/bin/env python
# -*- mode: python; coding: utf-8 -*-
"""
==============================
PasteDeploy Command runner
==============================
:Copyright: (c) 2007 David Smith
:Author: David Smith
:Contact: [EMAIL PROTECTED]
:Date: <2007-01-05 01:00:44 dds>
"""
import os,sys,re
from command import Command, BadCommand
from serve import LazyWriter, change_user_group
from paste.deploy import loadcmd
class RunCommand(Command):
usage = 'CONFIG_FILE [var=value]'
summary = "Run the named command defined in the config file"
#description = ""
min_args = 0
takes_config_file = 1
requires_config_file = True
default_verbosity = 1
parser = Command.standard_parser(quiet=True)
parser.add_option('-n', '--cmd-name',
dest='cmd_name',
metavar='NAME',
help="Load the named command (default main)")
parser.add_option('--log-file',
dest='log_file',
metavar='LOG_FILE',
help="Save output to the given log file (redirects stdout)")
if hasattr(os, 'setuid'):
parser.add_option('--user',
dest='set_user',
metavar='USERNAME',
help="Set the user (usually only possible when run as root)")
parser.add_option('--group',
dest='set_group',
metavar='GROUP',
help="Set the group (usually only possible when run as root)")
_scheme_re = re.compile(r'^[a-zA-Z0-9_-]+:')
def command(self):
if not hasattr(self.options, 'set_user'):
# Windows case:
self.options.set_user = self.options.set_group = None
change_user_group(
self, self.options.set_user, self.options.set_group)
if self.requires_config_file:
if not self.args:
raise BadCommand("You must specify a config file")
cmd_spec = self.args[0]
arg_list = self.args[1:]
else:
cmd_spec = ""
cmd = None
arg_list = self.args[:]
cmd_name = self.options.cmd_name
arg_dict = self.parse_vars(arg_list)
if not self._scheme_re.search(cmd_spec):
cmd_spec = 'config:' + cmd_spec
base = os.getcwd()
if self.options.log_file:
stdout_log = LazyWriter(self.options.log_file)
sys.stdout = stdout_log
sys.stderr = stdout_log
cmd = self.loadcmd(cmd_spec, name=cmd_name,
relative_to=base, global_conf=arg_dict)
if self.verbose > 0:
print "Executing command in PID %i" % os.getpid()
try:
cmd()
except KeyboardInterrupt, e:
if self.verbose > 1:
raise
if str(e):
msg = ' '+str(e)
else:
msg = ''
print 'Exiting%s (-v to see traceback)' % msg
def loadcmd(self, app_spec, name, relative_to, **kw):
return loadcmd(
app_spec, name=name, relative_to=relative_to, **kw)
# Local Variables: #
# time-stamp-pattern: "10/^:Date: <%%>" #
# End: #
pgpurNOmqGX9t.pgp
Description: PGP signature
_______________________________________________ Paste-users mailing list [email protected] http://webwareforpython.org/cgi-bin/mailman/listinfo/paste-users
