Example #1
0
    def __init__(self, path=None):
        self._startTime = time.time()

        global globalAppServer
        assert globalAppServer is None, 'more than one app server; or __init__() invoked more than once'
        globalAppServer = self

        ConfigurableForServerSidePath.__init__(self)
        Object.__init__(self)
        if path is None:
            path = os.path.dirname(__file__)  #os.getcwd()
        self._serverSidePath = os.path.abspath(path)
        self._webKitPath = os.path.abspath(os.path.dirname(__file__))
        self._webwarePath = os.path.dirname(self._webKitPath)

        self._verbose = self.setting('Verbose')
        self._plugIns = []
        self._reqCount = 0

        self.checkForInstall()
        self.config()  # cache the config
        self.printStartUpMessage()
        sys.setcheckinterval(self.setting('CheckInterval'))
        self._app = self.createApplication()
        self.loadPlugIns()

        self.running = 1

        if self.isPersistent():
            self._closeEvent = Event()
            self._closeThread = Thread(target=self.closeThread)
            ##			self._closeThread.setDaemon(1)
            self._closeThread.start()
Example #2
0
    def __init__(self, path=None):
        """Sets up and starts the `AppServer`.

        `path` is the working directory for the AppServer
        (directory in which AppServer is contained, by default)

        This method loads plugins, creates the Application object,
        and starts the request handling loop.
        """
        self._running = 0
        self._startTime = time()

        global globalAppServer
        if globalAppServer:
            raise ProcessRunning('More than one AppServer'
                ' or __init__() invoked more than once.')
        globalAppServer = self

        # Set up the import manager:
        self._imp = ImportManager()

        ConfigurableForServerSidePath.__init__(self)
        if path is None:
            path = os.path.dirname(__file__)  # os.getcwd()
        self._serverSidePath = os.path.abspath(path)
        self._webKitPath = os.path.abspath(os.path.dirname(__file__))
        self._webwarePath = os.path.dirname(self._webKitPath)

        self.recordPID()

        self._verbose = self.setting('Verbose')
        if self._verbose:
            self._silentURIs = self.setting('SilentURIs')
            if self._silentURIs:
                import re
                self._silentURIs = re.compile(self._silentURIs)
        else:
            self._silentURIs = None
        self._plugIns = []
        self._requestID = 0

        self.checkForInstall()
        self.config()  # cache the config
        self.printStartUpMessage()
        if self.setting('CheckInterval') is not None:
            sys.setcheckinterval(self.setting('CheckInterval'))
        self._app = self.createApplication()
        self.loadPlugIns()

        # @@ 2003-03 ib: shouldn't this just be in a subclass's __init__?
        if self.isPersistent():
            self._closeEvent = Event()
            self._closeThread = Thread(target=self.closeThread,
                name="CloseThread")
            # self._closeThread.setDaemon(1)
            self._closeThread.start()
        self._running = 1
Example #3
0
    def __init__(self, path=None):
        """Sets up and starts the `AppServer`.

        `path` is the working directory for the AppServer
        (directory in which AppServer is contained, by default)

        This method loads plugins, creates the Application object,
        and starts the request handling loop.

        """
        self._running = 0
        self._startTime = time()

        global globalAppServer
        if globalAppServer:
            raise ProcessRunning("More than one AppServer" " or __init__() invoked more than once.")
        globalAppServer = self

        # Set up the import manager:
        self._imp = ImportManager()

        ConfigurableForServerSidePath.__init__(self)
        if path is None:
            path = os.path.dirname(__file__)  # os.getcwd()
        self._serverSidePath = os.path.abspath(path)
        self._webKitPath = os.path.abspath(os.path.dirname(__file__))
        self._webwarePath = os.path.dirname(self._webKitPath)

        self.recordPID()

        self._verbose = self.setting("Verbose")
        if self._verbose:
            self._silentURIs = self.setting("SilentURIs")
            if self._silentURIs:
                import re

                self._silentURIs = re.compile(self._silentURIs)
        else:
            self._silentURIs = None
        self._plugIns = []
        self._requestID = 0

        self.checkForInstall()
        self.config()  # cache the config
        self.printStartUpMessage()
        if self.setting("CheckInterval") is not None:
            sys.setcheckinterval(self.setting("CheckInterval"))
        self._app = self.createApplication()
        self.loadPlugIns()

        # @@ 2003-03 ib: shouldn't this just be in a subclass's __init__?
        if self.isPersistent():
            self._closeEvent = Event()
            self._closeThread = Thread(target=self.closeThread, name="CloseThread")
            # self._closeThread.setDaemon(1)
            self._closeThread.start()
        self._running = 1
Example #4
0
	def __init__(self, server, useSessionSweeper=1):
		"""Called only by `AppServer`, sets up the Application."""

		self._server = server
		self._serverSidePath = server.serverSidePath()

		self._imp = server._imp # the import manager

		ConfigurableForServerSidePath.__init__(self)
		Object.__init__(self)

		print 'Initializing Application...'
		print 'Current directory:', os.getcwd()

		if self.setting('PrintConfigAtStartUp'):
			self.printConfig()

		self.initVersions()
		self.initErrorPage()

		self._shutDownHandlers = []

		# Initialize TaskManager:
		if self._server.isPersistent():
			from TaskKit.Scheduler import Scheduler
			self._taskManager = Scheduler(1)
			self._taskManager.start()
		else:
			self._taskManager = None

		# Define this before initializing URLParser, so that contexts have a
		# chance to override this. Also be sure to define it before loading the
		# sessions, in case the loading of the sessions causes an exception.
		self._exceptionHandlerClass = ExceptionHandler

		self.initSessions()
		self.makeDirs()

		URLParser.initApp(self)
		self._rootURLParser = URLParser.ContextParser(self)

		self._running = 1

		if useSessionSweeper:
			self.startSessionSweeper()
Example #5
0
    def __init__(self, server, useSessionSweeper=True):
        """Called only by `AppServer`, sets up the Application."""

        self._server = server
        self._serverSidePath = server.serverSidePath()

        self._imp = server._imp  # the import manager

        ConfigurableForServerSidePath.__init__(self)

        print 'Initializing Application...'
        print 'Current directory:', os.getcwd()

        if self.setting('PrintConfigAtStartUp'):
            self.printConfig()

        self.initVersions()
        self.initErrorPage()

        self._shutDownHandlers = []

        # Initialize task manager:
        if self._server.isPersistent():
            from TaskKit.Scheduler import Scheduler
            self._taskManager = Scheduler(
                daemon=True, exceptionHandler=self.handleException)
            self._taskManager.start()
        else:
            self._taskManager = None

        # Define this before initializing URLParser, so that contexts have a
        # chance to override this. Also be sure to define it before loading the
        # sessions, in case the loading of the sessions causes an exception.
        self._exceptionHandlerClass = ExceptionHandler

        self.makeDirs()
        self.initSessions()

        URLParser.initApp(self)
        self._rootURLParser = URLParser.ContextParser(self)

        if useSessionSweeper:
            self.startSessionSweeper()
 def __init__(self, path=None, settings=None, development=None):
     ConfigurableForServerSidePath.__init__(self)
     if path is None:
         path = os.getcwd()
     self._serverSidePath = os.path.abspath(path)
     self._webwarePath = os.path.abspath(os.path.dirname(__file__))
     if development is None:
         development = bool(os.environ.get('WEBWARE_DEVELOPMENT'))
     self._development = development
     appConfig = self.config()
     if settings:
         appConfig.update(settings)
     self._cacheDir = self.serverSidePath(
         self.setting('CacheDir') or 'Cache')
     from MiscUtils.PropertiesObject import PropertiesObject
     props = PropertiesObject(
         os.path.join(self._webwarePath, 'Properties.py'))
     self._webwareVersion = props['version']
     self._webwareVersionString = props['versionString']
     self._imp = MockImportManager()
     for path in (self._cacheDir, ):
         if path and not os.path.exists(path):
             os.makedirs(path)
Example #7
0
    def __init__(self, path=None, settings=None, development=None):
        """Sets up the Application.

        You can specify the path of the application working directory,
        a dictionary of settings to override in the configuration,
        and whether the application should run in development mode.
        """
        ConfigurableForServerSidePath.__init__(self)
        if path is None:
            path = os.getcwd()
        self._serverSidePath = os.path.abspath(path)
        self._webwarePath = os.path.abspath(os.path.dirname(__file__))

        if not os.path.isfile(self.configFilename()):
            print("ERROR: The application cannot be started:")
            print(f"Configuration file {self.configFilename()} not found.")
            raise RuntimeError('Configuration file not found')

        if development is None:
            development = bool(os.environ.get('WEBWARE_DEVELOPMENT'))
        self._development = development

        self.initVersions()

        self._shutDownHandlers = []
        self._plugIns = {}
        self._requestID = 0

        self._imp = ImportManager()

        appConfig = self.config()  # get and cache the configuration
        if settings:
            appConfig.update(settings)

        self._verbose = self.setting('Verbose')
        if self._verbose:
            self._silentURIs = self.setting('SilentURIs')
            if self._silentURIs:
                import re
                self._silentURIs = re.compile(self._silentURIs)
        else:
            self._silentURIs = None
        self._outputEncoding = self.setting('OutputEncoding')
        self._responseBufferSize = self.setting('ResponseBufferSize')
        self._wsgiWrite = self.setting('WSGIWrite')
        if self.setting('CheckInterval') is not None:
            sys.setswitchinterval(self.setting('CheckInterval'))

        logFilename = self.setting('AppLogFilename')
        if logFilename:
            sys.stderr = sys.stdout = open(logFilename, 'a', buffering=1)

        self.initErrorPage()
        self.printStartUpMessage()

        # Initialize task manager:
        if self.setting('RunTasks'):
            self._taskManager = Scheduler(
                daemon=True, exceptionHandler=self.handleException)
            self._taskManager.start()
        else:
            self._taskManager = None

        # Define this before initializing URLParser, so that contexts have a
        # chance to override this. Also be sure to define it before loading the
        # sessions, in case the loading of the sessions causes an exception.
        self._exceptionHandlerClass = ExceptionHandler

        self.makeDirs()
        self.initSessions()

        URLParser.initApp(self)
        self._rootURLParser = URLParser.ContextParser(self)

        self._startTime = time()

        if self.setting('UseSessionSweeper'):
            self.startSessionSweeper()

        self._plugInLoader = None
        self.loadPlugIns()

        self._needsShutDown = [True]
        atexit.register(self.shutDown)
        self._sigTerm = signal.signal(signal.SIGTERM, self.sigTerm)
        try:
            self._sigHup = signal.signal(signal.SIGHUP, self.sigTerm)
        except AttributeError:
            pass  # SIGHUP does not exist on Windows