def command(self): if self.options.reload: if os.environ.get(self._reloader_environ_key): from paste import reloader if self.verbose > 1: print 'Running reloading file monitor' reloader.install(int(self.options.reload_interval)) else: self.restart_with_reloader() if self.verbose > 0: if hasattr(os, 'getpid'): msg = 'Starting server in PID %i.' % os.getpid() else: msg = 'Starting server.' print msg try: self.serve() except (SystemExit, KeyboardInterrupt), e: if self.verbose > 1: raise if str(e): msg = ' '+str(e) else: msg = '' print 'Exiting%s (-v to see traceback)' % msg
def reloader(): from paste import reloader reloader.install() reloader.watch_file(cfgfile) import glob # Restart on "compile_catalog" # TODO: make more generic, and more robust for lang in glob.glob('*/locale/*/LC_MESSAGES/*.mo'): reloader.watch_file(lang) for lang in glob.glob('*/i18n/*/LC_MESSAGES/*.mo'): reloader.watch_file(lang)
def make_server(global_conf, port, host='', use_reloader=False): port = int(port) if use_reloader: from paste import reloader reloader.install() def serve(app): from paste import httpserver httpserver.serve(app, host=host, port=port) return serve
def _initConfig(): """Setup configuration dictionary from default, command line and configuration file.""" cmdLineOpts = _initCommandLineOptions() # Set config defaults config = DEFAULT_CONFIG.copy() # Configuration file overrides defaults config_file = cmdLineOpts.get("config_file") if config_file: verbose = cmdLineOpts.get("verbose", 2) fileConf = _readConfigFile(config_file, verbose) config.update(fileConf) else: if cmdLineOpts["verbose"] >= 2: print "Running without configuration file." # Command line overrides file if cmdLineOpts.get("port"): config["port"] = cmdLineOpts.get("port") if cmdLineOpts.get("host"): config["host"] = cmdLineOpts.get("host") if cmdLineOpts.get("verbose") is not None: config["verbose"] = cmdLineOpts.get("verbose") if cmdLineOpts.get("profile") is not None: config["profile"] = True if cmdLineOpts.get("root_path"): root_path = os.path.abspath(cmdLineOpts.get("root_path")) config["provider_mapping"]["/"] = FilesystemProvider(root_path) if cmdLineOpts["verbose"] >= 3: print "Configuration(%s):" % cmdLineOpts["config_file"] pprint(config) if not config["provider_mapping"]: print >> sys.stderr, "ERROR: No DAV provider defined. Try --help option." sys.exit(-1) # raise RuntimeWarning("At least one DAV provider must be specified by a --root option, or in a configuration file.") if cmdLineOpts.get("reload"): print >> sys.stderr, "Installing paste.reloader." from paste import reloader #@UnresolvedImport reloader.install() if config_file: # Add config file changes reloader.watch_file(config_file) # import pydevd # pydevd.settrace() return config
def run_script(script): if not os.path.isfile(script): print script, "does not exist" sys.exit(1) reloader.install() reloader.watch_file(script) script_locals = {} execfile(script, {'__file__': script}, script_locals) app = script_locals['application'] app = EvalException(app) app = PrintDebugMiddleware(app) serve(app)
def _initConfig(): """Setup configuration dictionary from default, command line and configuration file.""" cmdLineOpts = _initCommandLineOptions() # Set config defaults config = DEFAULT_CONFIG.copy() # Configuration file overrides defaults config_file = cmdLineOpts.get("config_file") if config_file: verbose = cmdLineOpts.get("verbose", 2) fileConf = _readConfigFile(config_file, verbose) config.update(fileConf) else: if cmdLineOpts["verbose"] >= 2: print "Running without configuration file." # Command line overrides file if cmdLineOpts.get("port"): config["port"] = cmdLineOpts.get("port") if cmdLineOpts.get("host"): config["host"] = cmdLineOpts.get("host") if cmdLineOpts.get("verbose") is not None: config["verbose"] = cmdLineOpts.get("verbose") if cmdLineOpts.get("profile") is not None: config["profile"] = True if cmdLineOpts.get("root_path"): root_path = os.path.abspath(cmdLineOpts.get("root_path")) config["provider_mapping"]["/"] = FilesystemProvider(root_path) if cmdLineOpts["verbose"] >= 3: print "Configuration(%s):" % cmdLineOpts["config_file"] pprint(config) if not config["provider_mapping"]: print >>sys.stderr, "ERROR: No DAV provider defined. Try --help option." sys.exit(-1) # raise RuntimeWarning("At least one DAV provider must be specified by a --root option, or in a configuration file.") if cmdLineOpts.get("reload"): print >>sys.stderr, "Installing paste.reloader." from paste import reloader #@UnresolvedImport reloader.install() if config_file: # Add config file changes reloader.watch_file(config_file) # import pydevd # pydevd.settrace() return config
def wsgi_serve(self, with_reloader): if not with_reloader or self._reloader_key not in os.environ: self.logger.info('Listening on: %s:%s' % (self.host, self.port)) if self._reloader_key in os.environ: self.logger.info('Monitoring code files') reloader.install() if self._reloader_key in os.environ or not with_reloader: if self.use_rfoo: from rfoo.utils import rconsole rconsole.spawn_server(self.rfoo_namespace, self.rfoo_port) self.logger.info('Rfoo listening on port %i' % self.rfoo_port) self.logger.info('http ready') server = WSGIServer(self.application, self.host, self.port, get_http_logger(self.logger)) server.serve_forever() return self.restart_with_reloader()
def main(): parser = ArgumentParser(description="DVDev: Distributed Versioned Development") parser.add_argument( 'repositories', metavar='repository', type=str, nargs='*', default=[os.getcwd()], help='List of repositories to serve. If left blank, DVDev will search ' 'the current and subdirectories for existing repositories.') parser.add_argument( '-d', '--debug', action='store_true', default=False, help='Start dvdev in debugging mode. This causes dvdev to monitor ' 'it\'s own source files and reload if they have changed. Normally, ' 'only DVDev developers will ever have need of this functionality.') parser.add_argument( '-f', '--fragile', action='store_true', default=False, help='INTERNAL USE ONLY. When specified, start a thread that watches ' 'DVDev\'s source files. If any change, then quit this process.') parser.add_argument( '-c', '--create', action='store_true', default=False, help='For any directories passed in on the command line (or the ' 'current directory, if none), initialize them as a repository if they ' 'do not already contain one.') parser.add_argument( '-n', '--nolaunch', action='store_true', default=False, help='Don\'t launch a web browser after starting the http server.') parser.add_argument( '-p', '--port', type=int, default=4000, help='The port to serve on (by default: 4000). If this port is in ' 'use, dvdev will try to randomly select an open port.') parser.add_argument( '-i', '--ip', default='0.0.0.0', help='The IP address to listen on. Defaults to 0.0.0.0, which means ' 'all IPv4 addresses') args = parser.parse_args() # We're gonna implement magic reload functionality, as seen in paster # serve. (Thanks, Ian Bicking, for the code and the explanation of what to # do.) # When this command is called with --debug, it does no actual serving. It # opens a new process with a special flag that will tell DVDev to launch in # 'fragile mode'. This means that it will call paste.reload.install(), # which starts a thread that kills the process if any of it's files change. # Meanwhile, back at the ranch (this process) we'll watch to see if our # subprocess dies and simply launch it again. At the same time, we'll # watch for a Ctrl-C so that the user can interrupt us (and by extension, # the server.) if args.debug: nolaunch = args.nolaunch while True: child = None try: try: print "Launching server process" exit_code, child = launch_and_watch_child(_server_args(args, nolaunch)) if not child: break # We only let nolaunch be False on the first subprocess launch. # After that, we never want to launch a webbrowser. nolaunch = True except (SystemExit, KeyboardInterrupt): "^C Pressed, shutting down server" return finally: if child and hasattr(os, 'kill'): # Apparantly, windows will litter processes in the case of # catastrophic failure. try: os.kill(child, signal.SIGTERM) except (OSError, IOError): pass if exit_code != 3: # The child exited non-normally, so we will too. return exit_code if args.fragile: # This simple form does not work in jython, so I should fix that, since # the code is already written into paste.serve from paste import reloader # Do we need to allow a way to slow this down? Defaults to checking # once per second. reloader.install() # If we ever add a config file, we need to add that to the watch list # like this: # reloader.watch_file(my_config_file) for index, repository in enumerate(args.repositories): if os.path.exists(repository): continue # Maybe this is a repository URL that mercurial recognizes? myui = ui.ui() myui.pushbuffer() from urllib2 import URLError try: commands.clone(myui, repository) except (RepoError, URLError): if args.create: try: os.makedirs(repository) try: commands.init(myui, repository) continue except: os.unlink(repository) except IOError: pass print "Bad repository: %s" % repository import sys sys.exit(1) destination = myui.popbuffer().split('\n')[0] destination = destination.split('destination directory: ')[1] if not os.path.exists(destination): print "Successfully cloned repository %s but unable to read "\ "local copy at %s" % (repository, destination) import sys sys.exit(1) print "Cloned repository %s in local directory %s" % (repository, destination) # Update our repository list with the new local copy args.repositories[index] = destination if args.create: all_repos = [] for repo in args.repositories: found_repos = flatten(build_repo_tree(repo)) if not found_repos: # Initialize myui = ui.ui() commands.init(myui, repo) else: all_repos += found_repos else: all_repos = filter(None, flatten([build_repo_tree(repo) for repo in args.repositories])) print "All repositories: %r" % all_repos config = { 'use': 'egg:DVDev', 'full_stack': 'true', 'static_files': 'true', 'reporoot': os.getcwd(), 'cache_dir': os.path.join(os.getcwd(), 'data'), 'beaker.session.key': 'dvdev', 'beaker.session.secret': 'somesecret', 'repo': ' '.join(all_repos), 'project_home': 'issues', 'who.log_level': 'debug', 'who.log_file': 'stdout', 'workspace': os.path.join(os.getcwd(), 'workspace'), } from dvdev.config.middleware import make_app app = make_app({'debug':(args.debug or args.fragile) and 'true' or 'false'}, **config) import webbrowser def webhelper(url): """\ Curry the webbrowser.open method so that we can cancel it with a threaded timer.""" def _launch_closure(): webbrowser.open(url) return _launch_closure # Paste's httpserver doesn't return once it's started serving (which is # pretty normal). The only problem is that we don't know if it # successfully captured the port unless it didn't return. We don't want to # open the user's webbrowser unless we're successfully serving, so it's # sort of a chicken and egg problem. We'll start a timer with a half # second delay (forever in computer time) in another thread. If the server # returns, we'll cancel the timer, and try again. if not args.nolaunch: from threading import Timer safelaunch = Timer(0.7, webhelper('http://%s:%d/' % (args.ip, args.port))) safelaunch.start() import socket from paste.httpserver import serve try: serve(app, host=args.ip, port=args.port) except socket.error, e: safelaunch.cancel() print "Unable to serve on port %d : Error message was: %s" % (args.port, e[1])
def _init_config(): """Setup configuration dictionary from default, command line and configuration file.""" cli_opts = _init_command_line_options() cli_verbose = cli_opts["verbose"] # Set config defaults # config = DEFAULT_CONFIG.copy() config = copy.deepcopy(DEFAULT_CONFIG) # Configuration file overrides defaults config_file = cli_opts.get("config_file") if config_file: file_opts = _read_config_file(config_file, cli_verbose) # config.update(file_opts) util.deep_update(config, file_opts) if cli_verbose != DEFAULT_VERBOSE and "verbose" in file_opts: if cli_verbose >= 2: print("Config file defines 'verbose: {}' but is overridden by command line: {}." .format(file_opts["verbose"], cli_verbose)) config["verbose"] = cli_verbose else: if cli_verbose >= 2: print("Running without configuration file.") # Command line overrides file if cli_opts.get("port"): config["port"] = cli_opts.get("port") if cli_opts.get("host"): config["host"] = cli_opts.get("host") if cli_opts.get("verbose") is not None: config["verbose"] = cli_opts.get("verbose") if cli_opts.get("profile") is not None: config["profile"] = True if cli_opts.get("server") is not None: config["server"] = cli_opts.get("server") if cli_opts.get("ssl_adapter") is not None: config["ssl_adapter"] = cli_opts.get("ssl_adapter") if cli_opts.get("root_path"): root_path = os.path.abspath(cli_opts.get("root_path")) config["provider_mapping"]["/"] = FilesystemProvider(root_path) if config["verbose"] >= 5: print("Configuration({}):\n{}" .format(cli_opts["config_file"], pformat(config))) if not config["provider_mapping"]: print("ERROR: No DAV provider defined. Try --help option.", file=sys.stderr) sys.exit(-1) if cli_opts.get("reload"): print("Installing paste.reloader.", file=sys.stderr) from paste import reloader # @UnresolvedImport reloader.install() if config_file: # Add config file changes reloader.watch_file(config_file) # import pydevd # pydevd.settrace() return config
metavar="PORT", default = 8051) parser.add_option("-s", "--scheduler", dest="scheduler", help="The scheduling algorithm to be used by The Grid", metavar="SCHEDULER", default = "FCFS") (options, args) = parser.parse_args() # Bring the Grid online try: model.grid = Grid(options.username, options.password, options.scheduler) except InvalidSchedulerException: print "Invalid Scheduler %s. Valid schedulers: %s." % (options.scheduler, ", ".join(Grid.SCHEDULERS)) sys.exit(1) # Initalise the WSGI Server reloader.install() host = options.host port = options.port app = gridservice.utils.make_app(routes) try: httpserver.serve(app, host = host, port = port) except Exception: print 'Unable to start The Grid on this host and port, please try a different host and port.' sys.exit(1)
def install(cls): from paste import reloader reloader.install(int(1))
def command(self): if self.options.stop_daemon: return self.stop_daemon() if not hasattr(self.options, 'set_user'): # Windows case: self.options.set_user = self.options.set_group = None # @@: Is this the right stage to set the user at? self.change_user_group( self.options.set_user, self.options.set_group) if self.requires_config_file: if not self.args: raise BadCommand('You must give a config file') app_spec = self.args[0] if len(self.args) > 1 and self.args[1] in self.possible_subcommands: cmd = self.args[1] restvars = self.args[2:] else: cmd = None restvars = self.args[1:] else: app_spec = "" if self.args and self.args[0] in self.possible_subcommands: cmd = self.args[0] restvars = self.args[1:] else: cmd = None restvars = self.args[:] if (getattr(self.options, 'daemon', False) and getattr(self.options, 'reload', False)): raise BadCommand('The --daemon and --reload options may not be used together') jython_monitor = False if self.options.reload: if jython and not self.options.disable_jython_reloader: # JythonMonitor raises the special SystemRestart # exception that'll cause the Jython interpreter to # reload in the existing Java process (avoiding # subprocess startup time) try: from paste.reloader import JythonMonitor except ImportError: pass else: jython_monitor = JythonMonitor(poll_interval=int( self.options.reload_interval)) if self.requires_config_file: jython_monitor.watch_file(self.args[0]) if not jython_monitor: if os.environ.get(self._reloader_environ_key): from paste import reloader if self.verbose > 1: print('Running reloading file monitor') reloader.install(int(self.options.reload_interval)) if self.requires_config_file: reloader.watch_file(self.args[0]) else: return self.restart_with_reloader() if cmd not in (None, 'start', 'stop', 'restart', 'status'): raise BadCommand( f'Error: must give start|stop|restart (not {cmd})') if cmd == 'status' or self.options.show_status: return self.show_status() if cmd == 'restart' or cmd == 'stop': result = self.stop_daemon() if result: print("Could not stop daemon") # It's ok to continue trying to restart if stop_daemon returns # a 1, otherwise shortcut and return. if cmd == 'restart' and result != 1: return result if cmd == 'stop': return result self.options.daemon = True if cmd == 'start': self.options.daemon = True app_name = self.options.app_name vars = self.parse_vars(restvars) if not self._scheme_re.search(app_spec): app_spec = f"config:{app_spec}" server_name = self.options.server_name if self.options.server: server_spec = 'egg:PasteScript' assert server_name is None server_name = self.options.server else: server_spec = app_spec base = os.getcwd() if getattr(self.options, 'daemon', False): if not self.options.pid_file: self.options.pid_file = 'paster.pid' if not self.options.log_file: self.options.log_file = 'paster.log' # Ensure the log file is writeable if self.options.log_file: try: writeable_log_file = open(self.options.log_file, 'a') except OSError as ioe: msg = f'Error: Unable to write to log file: {ioe}' raise BadCommand(msg) writeable_log_file.close() # Ensure the pid file is writeable if self.options.pid_file: try: writeable_pid_file = open(self.options.pid_file, 'a') except OSError as ioe: msg = f'Error: Unable to write to pid file: {ioe}' raise BadCommand(msg) writeable_pid_file.close() if getattr(self.options, 'daemon', False): try: self.daemonize() except DaemonizeException as ex: if self.verbose > 0: print(str(ex)) return if (self.options.monitor_restart and not os.environ.get(self._monitor_environ_key)): return self.restart_with_monitor() if self.options.pid_file: self.record_pid(self.options.pid_file) if self.options.log_file: stdout_log = LazyWriter(self.options.log_file, 'a') sys.stdout = stdout_log sys.stderr = stdout_log logging.basicConfig(stream=stdout_log) log_fn = app_spec if log_fn.startswith('config:'): log_fn = app_spec[len('config:'):] elif log_fn.startswith('egg:'): log_fn = None if log_fn: log_fn = os.path.join(base, log_fn) self.logging_file_config(log_fn) server = loadserver(server_spec, name=server_name, relative_to=base, global_conf=vars) app = loadapp(app_spec, name=app_name, relative_to=base, global_conf=vars) if self.verbose > 0: if hasattr(os, 'getpid'): msg = 'Starting server in PID %i.' % os.getpid() else: msg = 'Starting server.' print(msg) def serve(): try: server(app) except (SystemExit, KeyboardInterrupt) as e: if self.verbose > 1: raise if str(e): msg = f" {str(e)}" else: msg = '' print(f'Exiting{msg} (-v to see traceback)') except AttributeError as e: # Capturing bad error response from paste if str(e) == "'WSGIThreadPoolServer' object has no attribute 'thread_pool'": raise OSError(98, 'Address already in use') else: raise AttributeError(e) if jython_monitor: # JythonMonitor has to be ran from the main thread threading.Thread(target=serve).start() print('Starting Jython file monitor') jython_monitor.periodic_reload() else: serve()
class Webapp2HandlerAdapter(webapp2.BaseHandlerAdapter): def __call__(self, request, response, exception): request.route_args = { 'exception': exception } logging.exception(exception) handler = self.handler(request, response) return handler.get() app.error_handlers[403] = Webapp2HandlerAdapter(errors.Error403Handler) app.error_handlers[404] = Webapp2HandlerAdapter(errors.Error404Handler) app.error_handlers[503] = Webapp2HandlerAdapter(errors.Error503Handler) app.error_handlers[500] = Webapp2HandlerAdapter(errors.Error500Handler) # Static File Serving static_app = StaticURLParser("static/") # Check static files first then fallback application = Cascade([static_app, app]) if __name__ == '__main__' and basehandler.IS_DEV: import paste.reloader as reloader reloader.install(10) from paste.translogger import TransLogger application = TransLogger(application, logger_name=None) from paste import httpserver httpserver.serve(application, host='127.0.0.1', port='8080')
def _init_config(): """Setup configuration dictionary from default, command line and configuration file.""" cli_opts, parser = _init_command_line_options() cli_verbose = cli_opts["verbose"] # Set config defaults config = copy.deepcopy(DEFAULT_CONFIG) # Configuration file overrides defaults config_file = cli_opts.get("config_file") if config_file: file_opts = _read_config_file(config_file, cli_verbose) util.deep_update(config, file_opts) if cli_verbose != DEFAULT_VERBOSE and "verbose" in file_opts: if cli_verbose >= 2: print( "Config file defines 'verbose: {}' but is overridden by command line: {}.".format( file_opts["verbose"], cli_verbose ) ) config["verbose"] = cli_verbose else: if cli_verbose >= 2: print("Running without configuration file.") # Command line overrides file if cli_opts.get("port"): config["port"] = cli_opts.get("port") if cli_opts.get("host"): config["host"] = cli_opts.get("host") if cli_opts.get("profile") is not None: config["profile"] = True if cli_opts.get("server") is not None: config["server"] = cli_opts.get("server") if cli_opts.get("ssl_adapter") is not None: config["ssl_adapter"] = cli_opts.get("ssl_adapter") # Command line overrides file only if -v or -q where passed: if cli_opts.get("verbose") != DEFAULT_VERBOSE: config["verbose"] = cli_opts.get("verbose") if cli_opts.get("root_path"): root_path = os.path.abspath(cli_opts.get("root_path")) config["provider_mapping"]["/"] = FilesystemProvider(root_path) if config["verbose"] >= 5: # TODO: remove passwords from user_mapping # config_cleaned = copy.deepcopy(config) print("Configuration({}):\n{}".format(cli_opts["config_file"], pformat(config))) if not config["provider_mapping"]: parser.error("No DAV provider defined.") # Quick-configuration of DomainController auth = cli_opts.get("auth") auth_conf = config.get("http_authenticator", {}) if auth and auth_conf.get("domain_controller"): parser.error( "--auth option can only be used when no domain_controller is configured" ) if auth == "anonymous": if config["simple_dc"]["user_mapping"]: parser.error( "--auth=anonymous can only be used when no user_mapping is configured" ) auth_conf.update( { "domain_controller": "wsgidav.dc.simple_dc.SimpleDomainController", "accept_basic": True, "accept_digest": True, "default_to_digest": True, } ) config["simple_dc"]["user_mapping"] = {"*": True} elif auth == "nt": if config.get("nt_dc"): parser.error( "--auth=nt can only be used when no nt_dc settings are configured" ) auth_conf.update( { "domain_controller": "wsgidav.dc.nt_dc.NTDomainController", "accept_basic": True, "accept_digest": False, "default_to_digest": False, } ) config["nt_dc"] = {} elif auth == "pam-login": if config.get("pam_dc"): parser.error( "--auth=pam-login can only be used when no pam_dc settings are configured" ) auth_conf.update( { "domain_controller": "wsgidav.dc.pam_dc.PAMDomainController", "accept_basic": True, "accept_digest": False, "default_to_digest": False, } ) config["pam_dc"] = {"service": "login"} # print(config) if cli_opts.get("reload"): print("Installing paste.reloader.", file=sys.stderr) from paste import reloader # @UnresolvedImport reloader.install() if config_file: # Add config file changes reloader.watch_file(config_file) # import pydevd # pydevd.settrace() return config
def command(self): if self.options.stop_daemon: return self.stop_daemon() if not hasattr(self.options, 'set_user'): # Windows case: self.options.set_user = self.options.set_group = None # @@: Is this the right stage to set the user at? self.change_user_group(self.options.set_user, self.options.set_group) if self.requires_config_file: if not self.args: raise BadCommand('You must give a config file') app_spec = self.args[0] if (len(self.args) > 1 and self.args[1] in self.possible_subcommands): cmd = self.args[1] restvars = self.args[2:] else: cmd = None restvars = self.args[1:] else: app_spec = "" if (self.args and self.args[0] in self.possible_subcommands): cmd = self.args[0] restvars = self.args[1:] else: cmd = None restvars = self.args[:] if self.options.reload: if os.environ.get(self._reloader_environ_key): from paste import reloader if self.verbose > 1: print 'Running reloading file monitor' reloader.install(int(self.options.reload_interval)) if self.requires_config_file: reloader.watch_file(self.args[0]) else: return self.restart_with_reloader() if (self.options.monitor_restart and not os.environ.get(self._monitor_environ_key)): return self.restart_with_monitor() if cmd not in (None, 'start', 'stop', 'restart', 'status'): raise BadCommand('Error: must give start|stop|restart (not %s)' % cmd) if cmd == 'status' or self.options.show_status: return self.show_status() if cmd == 'restart' or cmd == 'stop': result = self.stop_daemon() if result: if cmd == 'restart': print "Could not stop daemon; aborting" else: print "Could not stop daemon" return result if cmd == 'stop': return result app_name = self.options.app_name vars = self.parse_vars(restvars) if not self._scheme_re.search(app_spec): app_spec = 'config:' + app_spec server_name = self.options.server_name if self.options.server: server_spec = 'egg:PasteScript' assert server_name is None server_name = self.options.server else: server_spec = app_spec base = os.getcwd() # Ensure the log file is writeable if self.options.log_file: try: writeable_log_file = open(self.options.log_file, 'a') except IOError, ioe: msg = 'Error: Unable to write to log file: %s' % ioe raise BadCommand(msg) writeable_log_file.close()
def command(self): if self.options.stop_daemon: return self.stop_daemon() if not hasattr(self.options, 'set_user'): # Windows case: self.options.set_user = self.options.set_group = None # @@: Is this the right stage to set the user at? self.change_user_group( self.options.set_user, self.options.set_group) if self.requires_config_file: if not self.args: raise BadCommand('You must give a config file') app_spec = self.args[0] if (len(self.args) > 1 and self.args[1] in self.possible_subcommands): cmd = self.args[1] restvars = self.args[2:] else: cmd = None restvars = self.args[1:] else: app_spec = "" if (self.args and self.args[0] in self.possible_subcommands): cmd = self.args[0] restvars = self.args[1:] else: cmd = None restvars = self.args[:] if (getattr(self.options, 'daemon', False) and getattr(self.options, 'reload', False)): raise BadCommand('The --daemon and --reload options may not be used together') jython_monitor = False if self.options.reload: if jython and not self.options.disable_jython_reloader: # JythonMonitor raises the special SystemRestart # exception that'll cause the Jython interpreter to # reload in the existing Java process (avoiding # subprocess startup time) try: from paste.reloader import JythonMonitor except ImportError: pass else: jython_monitor = JythonMonitor(poll_interval=int( self.options.reload_interval)) if self.requires_config_file: jython_monitor.watch_file(self.args[0]) if not jython_monitor: if os.environ.get(self._reloader_environ_key): from paste import reloader if self.verbose > 1: print 'Running reloading file monitor' reloader.install(int(self.options.reload_interval)) if self.requires_config_file: reloader.watch_file(self.args[0]) else: return self.restart_with_reloader() if cmd not in (None, 'start', 'stop', 'restart', 'status'): raise BadCommand( 'Error: must give start|stop|restart (not %s)' % cmd) if cmd == 'status' or self.options.show_status: return self.show_status() if cmd == 'restart' or cmd == 'stop': result = self.stop_daemon() if result: if cmd == 'restart': print "Could not stop daemon; aborting" else: print "Could not stop daemon" return result if cmd == 'stop': return result self.options.daemon = True if cmd == 'start': self.options.daemon = True app_name = self.options.app_name vars = self.parse_vars(restvars) if not self._scheme_re.search(app_spec): app_spec = 'config:' + app_spec server_name = self.options.server_name if self.options.server: server_spec = 'egg:PasteScript' assert server_name is None server_name = self.options.server else: server_spec = app_spec base = os.getcwd() if getattr(self.options, 'daemon', False): if not self.options.pid_file: self.options.pid_file = 'paster.pid' if not self.options.log_file: self.options.log_file = 'paster.log' # Ensure the log file is writeable if self.options.log_file: try: writeable_log_file = open(self.options.log_file, 'a') except IOError, ioe: msg = 'Error: Unable to write to log file: %s' % ioe raise BadCommand(msg) writeable_log_file.close()
def main(): parser = OptionParser(description="Community Almanac: A place to tell your stories.") parser.add_option( '-d', '--debug', action='store_true', default=False, help='Start community almanac in debugging mode. This causes ' 'community almanac to monitor it\'s own source files and reload if ' 'they have changed. Normally, only community almanac developers will ' 'ever have need of this functionality.') parser.add_option( '-f', '--fragile', action='store_true', default=False, help='INTERNAL USE ONLY. When specified, start a thread that watches ' 'Community Almanac\'s source files. If any change, then quit this ' 'process.') parser.add_option( '-n', '--nolaunch', action='store_true', default=False, help='Don\'t launch a web browser after starting the http server.') parser.add_option( '-p', '--port', type=int, default=4000, help='The port to serve on (by default: 4000). If this port is in ' 'use, community almanac will try to randomly select an open port.') parser.add_option( '-i', '--ip', default='0.0.0.0', help='The IP address to listen on. Defaults to 0.0.0.0, which means ' 'all IPv4 addresses') parser.add_option( '-e', '--emailserver', default='mail.openplans.org', help='The SMTP server to use for sending emails. This needs to be an ' 'open relay.') parser.add_option( '-u', '--url', default='postgres://*****:*****@localhost/almanac', help='The DB url to pass to sqlalchemy. It defaults to ' '"postgres://*****:*****@localhost/almanac"') parser.add_option( '-s', '--setup', action='store_true', default=False, help='Run the community almanac setup. This creates any necessary models.') parser.add_option( '-m', '--map-key', default='ABQIAAAArBPF8riaRhqOCRInVOpLVhS7l0GBSa1x8uTWSQog_urT4TWq5xQAsIXoWoBjWzF7uvuoy8WT3pGQQA', help='The google maps api key to use') parser.add_option( '--recaptcha-public', default='6Le2wAcAAAAAAMAt001e7rSZgigoGgbFFyFN_jWi', help='The recaptcha public key to use') parser.add_option( '--recaptcha-private', default='6Le2wAcAAAAAAGKOoOcrBrNpYlaP3xW4RcWE1YX2', help='The recaptcha private key to use') args = parser.parse_args()[0] config = { 'use': 'egg:communityalmanac', 'full_stack': 'true', 'static_files': 'true', 'cache_dir': os.path.join(os.getcwd(), 'data'), 'beaker.session.key': 'almanac', 'beaker.session.secret': 'somesecret', 'smtp_server': args.emailserver, 'smtp_port': 25, 'sqlalchemy.url': args.url, 'map_key': args.map_key, 'captcha_pubkey': args.recaptcha_public, 'captcha_privkey': args.recaptcha_private, 'captcha_enabled': 'True', 'host_whitelist': 'player.soundcloud.com,soundcloud.com,youtube.com,video.google.com,vimeo.com,blip.tv'.split(','), 'allow_tags': 'embed,object,param'.split(','), 'support_sending_enabled': False, 'support_email': 'nobody@localhost', } if args.setup: conf = type('TempConfig', (object,), dict(global_conf=config, local_conf=config)) from communityalmanac.websetup import setup_app setup_app(None, conf, {}) sys.exit(0) # We're gonna implement magic reload functionality, as seen in paster # serve. (Thanks, Ian Bicking, for the code and the explanation of what to # do.) # When this command is called with --debug, it does no actual serving. It # opens a new process with a special flag that will tell Community Almanac # to launch in 'fragile mode'. This means that it will call # paste.reload.install(), which starts a thread that kills the process if # any of it's files change. # Meanwhile, back at the ranch (this process) we'll watch to see if our # subprocess dies and simply launch it again. At the same time, we'll # watch for a Ctrl-C so that the user can interrupt us (and by extension, # the server.) if args.debug: nolaunch = args.nolaunch while True: child = None try: try: print "Launching server process" exit_code, child = launch_and_watch_child(_server_args(args, nolaunch)) if not child: break # We only let nolaunch be False on the first subprocess launch. # After that, we never want to launch a webbrowser. nolaunch = True except (SystemExit, KeyboardInterrupt): "^C Pressed, shutting down server" return finally: if child and hasattr(os, 'kill'): # Apparantly, windows will litter processes in the case of # catastrophic failure. try: os.kill(child, signal.SIGTERM) except (OSError, IOError): pass if exit_code != 3: # The child exited non-normally, so we will too. return exit_code if args.fragile: # This simple form does not work in jython, so I should fix that, since # the code is already written into paste.serve from paste import reloader # Do we need to allow a way to slow this down? Defaults to checking # once per second. reloader.install() # If we ever add a config file, we need to add that to the watch list # like this: # reloader.watch_file(my_config_file) from communityalmanac.config.middleware import make_app app = make_app({'debug':(args.debug or args.fragile) and 'true' or 'false'}, **config) import webbrowser def webhelper(url): """\ Curry the webbrowser.open method so that we can cancel it with a threaded timer.""" def _launch_closure(): webbrowser.open(url) return _launch_closure import socket from paste.httpserver import serve # Paste's httpserver doesn't return once it's started serving (which is # pretty normal). The only problem is that we don't know if it # successfully captured the port unless it didn't return. We don't want to # open the user's webbrowser unless we're successfully serving, so it's # sort of a chicken and egg problem. We'll start a timer with a half # second delay (forever in computer time) in another thread. If the server # returns, we'll cancel the timer, and try again. if not args.nolaunch: from threading import Timer safelaunch = Timer(0.5, webhelper('http://%s:%d/' % (args.ip, args.port))) safelaunch.start() try: serve(app, host=args.ip, port=args.port) except socket.error, e: try: safelaunch.cancel() except NameError: pass print "Unable to serve on port %d : Error message was: %s" % (args.port, e[1])
# defined custom error handlers class Webapp2HandlerAdapter(webapp2.BaseHandlerAdapter): def __call__(self, request, response, exception): request.route_args = {'exception': exception} logging.exception(exception) handler = self.handler(request, response) return handler.get() app.error_handlers[403] = Webapp2HandlerAdapter(errors.Error403Handler) app.error_handlers[404] = Webapp2HandlerAdapter(errors.Error404Handler) app.error_handlers[503] = Webapp2HandlerAdapter(errors.Error503Handler) app.error_handlers[500] = Webapp2HandlerAdapter(errors.Error500Handler) # Static File Serving static_app = StaticURLParser("static/") # Check static files first then fallback application = Cascade([static_app, app]) if __name__ == '__main__' and basehandler.IS_DEV: import paste.reloader as reloader reloader.install(10) from paste.translogger import TransLogger application = TransLogger(application, logger_name=None) from paste import httpserver httpserver.serve(application, host='127.0.0.1', port='8080')
def command(self): if self.options.stop_daemon: return self.stop_daemon() if not hasattr(self.options, 'set_user'): # Windows case: self.options.set_user = self.options.set_group = None # @@: Is this the right stage to set the user at? self.change_user_group( self.options.set_user, self.options.set_group) if self.requires_config_file: if not self.args: raise BadCommand('You must give a config file') app_spec = self.args[0] if (len(self.args) > 1 and self.args[1] in self.possible_subcommands): cmd = self.args[1] restvars = self.args[2:] else: cmd = None restvars = self.args[1:] else: app_spec = "" if (self.args and self.args[0] in self.possible_subcommands): cmd = self.args[0] restvars = self.args[1:] else: cmd = None restvars = self.args[:] if self.options.reload: if os.environ.get(self._reloader_environ_key): from paste import reloader if self.verbose > 1: print 'Running reloading file monitor' reloader.install(int(self.options.reload_interval)) if self.requires_config_file: reloader.watch_file(self.args[0]) else: return self.restart_with_reloader() if (self.options.monitor_restart and not os.environ.get(self._monitor_environ_key)): return self.restart_with_monitor() if cmd not in (None, 'start', 'stop', 'restart', 'status'): raise BadCommand( 'Error: must give start|stop|restart (not %s)' % cmd) if cmd == 'status' or self.options.show_status: return self.show_status() if cmd == 'restart' or cmd == 'stop': result = self.stop_daemon() if result: if cmd == 'restart': print "Could not stop daemon; aborting" else: print "Could not stop daemon" return result if cmd == 'stop': return result app_name = self.options.app_name vars = self.parse_vars(restvars) if not self._scheme_re.search(app_spec): app_spec = 'config:' + app_spec server_name = self.options.server_name if self.options.server: server_spec = 'egg:PasteScript' assert server_name is None server_name = self.options.server else: server_spec = app_spec base = os.getcwd() # Ensure the log file is writeable if self.options.log_file: try: writeable_log_file = open(self.options.log_file, 'a') except IOError, ioe: msg = 'Error: Unable to write to log file: %s' % ioe raise BadCommand(msg) writeable_log_file.close()
input_timezone = environ['PATH_INFO'][1:] if input_timezone: try: input_timezone = timezone(input_timezone) except UnknownTimeZoneError: start_response('200 OK', [('Content-Type', 'text/plain')]) return [b'Unknown time zone'] else: input_timezone = None msg = 'Time ' if input_timezone: msg += 'in %s:\n' % input_timezone else: msg += 'on server:\n' start_response('200 OK', [('Content-Type', 'text/plain')]) return [ bytes(msg + datetime.now(tz=input_timezone).time().isoformat() + '\nAdd needed timezone to the url\n', encoding='utf-8') ] if __name__ == '__main__': from paste import reloader from paste.httpserver import serve reloader.install() serve(app)
def _initConfig(): """Setup configuration dictionary from default, command line and configuration file.""" cmdLineOpts, args = _initCommandLineOptions() # Set config defaults config = DEFAULT_CONFIG.copy() if cmdLineOpts["verbose"] is None: temp_verbose = config["verbose"] else: temp_verbose = cmdLineOpts["verbose"] # print "verbose #1: ", temp_verbose # Configuration file overrides defaults config_file = cmdLineOpts.get("config_file") if config_file: fileConf = _readConfigFile(config_file, temp_verbose) config.update(fileConf) else: if temp_verbose >= 2: print "Running without configuration file." # print "verbose #2: ", config.get("verbose") # Command line overrides file if cmdLineOpts.get("port"): config["port"] = cmdLineOpts.get("port") if cmdLineOpts.get("host"): config["host"] = cmdLineOpts.get("host") if cmdLineOpts.get("verbose") is not None: config["verbose"] = cmdLineOpts.get("verbose") if cmdLineOpts.get("profile") is not None: config["profile"] = True if cmdLineOpts.get("root_path"): root_path = os.path.abspath(cmdLineOpts.get("root_path")) config["provider_mapping"]["/"] = FilesystemProvider(root_path) if config["verbose"] >= 3: print "Configuration(%s):" % cmdLineOpts["config_file"] pprint(config) log_path = cmdLineOpts.get("log_path", "") if log_path: log_path = os.path.abspath(log_path) config["log_path"] = log_path pid_file = cmdLineOpts.get("pid_file", "") if pid_file: pid_file = os.path.abspath(pid_file) config["pid_file"] = pid_file if not useLxml and config["verbose"] >= 1: print "WARNING: Could not import lxml: using xml instead (slower). Consider installing lxml from http://codespeak.net/lxml/." # print "verbose #3: ", config.get("verbose") if not config["provider_mapping"]: print >>sys.stderr, "ERROR: No DAV provider defined. Try --help option." sys.exit(-1) # raise RuntimeWarning("At least one DAV provider must be specified by a --root option, or in a configuration file.") if cmdLineOpts.get("reload"): print >>sys.stderr, "Installing paste.reloader." from paste import reloader #@UnresolvedImport reloader.install() if config_file: # Add config file changes reloader.watch_file(config_file) # import pydevd # pydevd.settrace() return config, args
def command(self): if self.options.stop_daemon: return self.stop_daemon() if not hasattr(self.options, 'set_user'): # Windows case: self.options.set_user = self.options.set_group = None # @@: Is this the right stage to set the user at? self.change_user_group( self.options.set_user, self.options.set_group) if self.requires_config_file: if not self.args: raise BadCommand('You must give a config file') app_spec = self.args[0] if (len(self.args) > 1 and self.args[1] in self.possible_subcommands): cmd = self.args[1] restvars = self.args[2:] else: cmd = None restvars = self.args[1:] else: app_spec = "" if (self.args and self.args[0] in self.possible_subcommands): cmd = self.args[0] restvars = self.args[1:] else: cmd = None restvars = self.args[:] if (getattr(self.options, 'daemon', False) and getattr(self.options, 'reload', False)): raise BadCommand('The --daemon and --reload options may not be used together') jython_monitor = False if self.options.reload: if jython and not self.options.disable_jython_reloader: # JythonMonitor raises the special SystemRestart # exception that'll cause the Jython interpreter to # reload in the existing Java process (avoiding # subprocess startup time) try: from paste.reloader import JythonMonitor except ImportError: pass else: jython_monitor = JythonMonitor(poll_interval=int( self.options.reload_interval)) if self.requires_config_file: jython_monitor.watch_file(self.args[0]) if not jython_monitor: if os.environ.get(self._reloader_environ_key): from paste import reloader if self.verbose > 1: print('Running reloading file monitor') reloader.install(int(self.options.reload_interval)) if self.requires_config_file: reloader.watch_file(self.args[0]) else: return self.restart_with_reloader() if cmd not in (None, 'start', 'stop', 'restart', 'status'): raise BadCommand( 'Error: must give start|stop|restart (not %s)' % cmd) if cmd == 'status' or self.options.show_status: return self.show_status() if cmd == 'restart' or cmd == 'stop': result = self.stop_daemon() if result: print("Could not stop daemon") # It's ok to continue trying to restart if stop_daemon returns # a 1, otherwise shortcut and return. if cmd == 'restart' and result != 1: return result if cmd == 'stop': return result self.options.daemon = True if cmd == 'start': self.options.daemon = True app_name = self.options.app_name vars = self.parse_vars(restvars) if not self._scheme_re.search(app_spec): app_spec = 'config:' + app_spec server_name = self.options.server_name if self.options.server: server_spec = 'egg:PasteScript' assert server_name is None server_name = self.options.server else: server_spec = app_spec base = os.getcwd() if getattr(self.options, 'daemon', False): if not self.options.pid_file: self.options.pid_file = 'paster.pid' if not self.options.log_file: self.options.log_file = 'paster.log' # Ensure the log file is writeable if self.options.log_file: try: writeable_log_file = open(self.options.log_file, 'a') except IOError as ioe: msg = 'Error: Unable to write to log file: %s' % ioe raise BadCommand(msg) writeable_log_file.close() # Ensure the pid file is writeable if self.options.pid_file: try: writeable_pid_file = open(self.options.pid_file, 'a') except IOError as ioe: msg = 'Error: Unable to write to pid file: %s' % ioe raise BadCommand(msg) writeable_pid_file.close() if getattr(self.options, 'daemon', False): try: self.daemonize() except DaemonizeException as ex: if self.verbose > 0: print(str(ex)) return if (self.options.monitor_restart and not os.environ.get(self._monitor_environ_key)): return self.restart_with_monitor() if self.options.pid_file: self.record_pid(self.options.pid_file) if self.options.log_file: stdout_log = LazyWriter(self.options.log_file, 'a') sys.stdout = stdout_log sys.stderr = stdout_log logging.basicConfig(stream=stdout_log) log_fn = app_spec if log_fn.startswith('config:'): log_fn = app_spec[len('config:'):] elif log_fn.startswith('egg:'): log_fn = None if log_fn: log_fn = os.path.join(base, log_fn) self.logging_file_config(log_fn) server = loadserver(server_spec, name=server_name, relative_to=base, global_conf=vars) app = loadapp( app_spec, name=app_name, relative_to=base, global_conf=vars) if self.verbose > 0: if hasattr(os, 'getpid'): msg = 'Starting server in PID %i.' % os.getpid() else: msg = 'Starting server.' print(msg) def serve(): try: server(app) except (SystemExit, KeyboardInterrupt) as e: if self.verbose > 1: raise if str(e): msg = ' ' + str(e) else: msg = '' print('Exiting%s (-v to see traceback)' % msg) except AttributeError as e: # Capturing bad error response from paste if str(e) == "'WSGIThreadPoolServer' object has no attribute 'thread_pool'": import socket raise socket.error(98, 'Address already in use') else: raise AttributeError(e) if jython_monitor: # JythonMonitor has to be ran from the main thread threading.Thread(target=serve).start() print('Starting Jython file monitor') jython_monitor.periodic_reload() else: serve()
def command(self): if self.options.stop_daemon: return self.stop_daemon() if not hasattr(self.options, 'set_user'): # Windows case: self.options.set_user = self.options.set_group = None # @@: Is this the right stage to set the user at? self.change_user_group(self.options.set_user, self.options.set_group) if self.requires_config_file: if not self.args: raise BadCommand('You must give a config file') app_spec = self.args[0] if (len(self.args) > 1 and self.args[1] in self.possible_subcommands): cmd = self.args[1] restvars = self.args[2:] else: cmd = None restvars = self.args[1:] else: app_spec = "" if (self.args and self.args[0] in self.possible_subcommands): cmd = self.args[0] restvars = self.args[1:] else: cmd = None restvars = self.args[:] if (getattr(self.options, 'daemon', False) and getattr(self.options, 'reload', False)): raise BadCommand( 'The --daemon and --reload options may not be used together') jython_monitor = False if self.options.reload: if jython and not self.options.disable_jython_reloader: # JythonMonitor raises the special SystemRestart # exception that'll cause the Jython interpreter to # reload in the existing Java process (avoiding # subprocess startup time) try: from paste.reloader import JythonMonitor except ImportError: pass else: jython_monitor = JythonMonitor( poll_interval=int(self.options.reload_interval)) if self.requires_config_file: jython_monitor.watch_file(self.args[0]) if not jython_monitor: if os.environ.get(self._reloader_environ_key): from paste import reloader if self.verbose > 1: print 'Running reloading file monitor' reloader.install(int(self.options.reload_interval)) if self.requires_config_file: reloader.watch_file(self.args[0]) else: return self.restart_with_reloader() if cmd not in (None, 'start', 'stop', 'restart', 'status'): raise BadCommand('Error: must give start|stop|restart (not %s)' % cmd) if cmd == 'status' or self.options.show_status: return self.show_status() if cmd == 'restart' or cmd == 'stop': result = self.stop_daemon() if result: if cmd == 'restart': print "Could not stop daemon; aborting" else: print "Could not stop daemon" return result if cmd == 'stop': return result self.options.daemon = True if cmd == 'start': self.options.daemon = True app_name = self.options.app_name vars = self.parse_vars(restvars) if not self._scheme_re.search(app_spec): app_spec = 'config:' + app_spec server_name = self.options.server_name if self.options.server: server_spec = 'egg:PasteScript' assert server_name is None server_name = self.options.server else: server_spec = app_spec base = os.getcwd() if getattr(self.options, 'daemon', False): if not self.options.pid_file: self.options.pid_file = 'paster.pid' if not self.options.log_file: self.options.log_file = 'paster.log' # Ensure the log file is writeable if self.options.log_file: try: writeable_log_file = open(self.options.log_file, 'a') except IOError, ioe: msg = 'Error: Unable to write to log file: %s' % ioe raise BadCommand(msg) writeable_log_file.close()
def _initConfig(): """Setup configuration dictionary from default, command line and configuration file.""" cmdLineOpts = _initCommandLineOptions() # Set config defaults config = DEFAULT_CONFIG.copy() if cmdLineOpts["verbose"] is None: temp_verbose = config["verbose"] else: temp_verbose = cmdLineOpts["verbose"] # print "verbose #1: ", temp_verbose # Configuration file overrides defaults config_file = cmdLineOpts.get("config_file") if config_file: fileConf = _readConfigFile(config_file, temp_verbose) config.update(fileConf) else: if temp_verbose >= 2: print("Running without configuration file.") # print "verbose #2: ", config.get("verbose") # Command line overrides file if cmdLineOpts.get("port"): config["port"] = cmdLineOpts.get("port") if cmdLineOpts.get("host"): config["host"] = cmdLineOpts.get("host") if cmdLineOpts.get("verbose") is not None: config["verbose"] = cmdLineOpts.get("verbose") if cmdLineOpts.get("profile") is not None: config["profile"] = True if cmdLineOpts.get("server") is not None: config["server"] = cmdLineOpts.get("server") if cmdLineOpts.get("ssl_adapter") is not None: config["ssl_adapter"] = cmdLineOpts.get("ssl_adapter") if cmdLineOpts.get("root_path"): root_path = os.path.abspath(cmdLineOpts.get("root_path")) config["provider_mapping"]["/"] = FilesystemProvider(root_path) if config["verbose"] >= 4: print("Configuration({}):\n{}".format(cmdLineOpts["config_file"], pformat(config))) # if not useLxml and config["verbose"] >= 1: # print("WARNING: Could not import lxml: using xml instead (slower). Consider installing" # "lxml from http://codespeak.net/lxml/.") # print "verbose #3: ", config.get("verbose") if not config["provider_mapping"]: print("ERROR: No DAV provider defined. Try --help option.", file=sys.stderr) sys.exit(-1) # raise RuntimeWarning("At least one DAV provider must be specified by a --root option," # or in a configuration file.") if cmdLineOpts.get("reload"): print("Installing paste.reloader.", file=sys.stderr) from paste import reloader # @UnresolvedImport reloader.install() if config_file: # Add config file changes reloader.watch_file(config_file) # import pydevd # pydevd.settrace() return config
def command(self): if self.options.stop_daemon: return self.stop_daemon() if not hasattr(self.options, "set_user"): # Windows case: self.options.set_user = self.options.set_group = None # @@: Is this the right stage to set the user at? self.change_user_group(self.options.set_user, self.options.set_group) if self.requires_config_file: if not self.args: raise BadCommand("You must give a config file") app_spec = self.args[0] if len(self.args) > 1 and self.args[1] in self.possible_subcommands: cmd = self.args[1] restvars = self.args[2:] else: cmd = None restvars = self.args[1:] else: app_spec = "" if self.args and self.args[0] in self.possible_subcommands: cmd = self.args[0] restvars = self.args[1:] else: cmd = None restvars = self.args[:] if self.options.reload: if os.environ.get(self._reloader_environ_key): from paste import reloader if self.verbose > 1: print "Running reloading file monitor" reloader.install(int(self.options.reload_interval)) if self.requires_config_file: reloader.watch_file(self.args[0]) else: return self.restart_with_reloader() if cmd not in (None, "start", "stop", "restart", "status"): raise BadCommand("Error: must give start|stop|restart (not %s)" % cmd) if cmd == "status" or self.options.show_status: return self.show_status() if cmd == "restart" or cmd == "stop": result = self.stop_daemon() if result: if cmd == "restart": print "Could not stop daemon; aborting" else: print "Could not stop daemon" return result if cmd == "stop": return result app_name = self.options.app_name vars = self.parse_vars(restvars) if not self._scheme_re.search(app_spec): app_spec = "config:" + app_spec server_name = self.options.server_name if self.options.server: server_spec = "egg:PasteScript" assert server_name is None server_name = self.options.server else: server_spec = app_spec base = os.getcwd() if getattr(self.options, "daemon", False): if not self.options.pid_file: self.options.pid_file = "paster.pid" if not self.options.log_file: self.options.log_file = "paster.log" # Ensure the log file is writeable if self.options.log_file: try: writeable_log_file = open(self.options.log_file, "a") except IOError, ioe: msg = "Error: Unable to write to log file: %s" % ioe raise BadCommand(msg) writeable_log_file.close()