def run(): SUPPORTED_SERVERS = { "paste": _runPaste, "cheroot": _runCheroot, "cherrypy": _runCherryPy, "ext-wsgiutils": _runExtWsgiutils, "flup-fcgi": _runFlup, "flup-fcgi_fork": _runFlup, "wsgiref": _runWsgiref, } config = _initConfig() util.initLogging(config["verbose"], config.get("enable_loggers", [])) app = WsgiDAVApp(config) server = config["server"] handler = SUPPORTED_SERVERS.get(server) if not handler: raise RuntimeError( "Unsupported server type {!r} (expected {!r})".format( server, "', '".join(SUPPORTED_SERVERS.keys()))) if not useLxml: # and config["verbose"] >= 1: _logger.warn( "WARNING: Could not import lxml: using xml instead (slower). " "Consider installing lxml https://pypi.python.org/pypi/lxml.") handler(app, config, server)
def testCliLogging(self): """CLI initializes logging """ enable_loggers = [ "test", ] initLogging(3, enable_loggers) _baseLogger = logging.getLogger(BASE_LOGGER_NAME) _enabledLogger = getModuleLogger("test") _disabledLogger = getModuleLogger("test2") _baseLogger.debug("_baseLogger.debug") _baseLogger.info("_baseLogger.info") _baseLogger.warning("_baseLogger.warning") _baseLogger.error("_baseLogger.error") _enabledLogger.debug("_enabledLogger.debug") _enabledLogger.info("_enabledLogger.info") _enabledLogger.warning("_enabledLogger.warning") _enabledLogger.error("_enabledLogger.error") _disabledLogger.debug("_disabledLogger.debug") _disabledLogger.info("_disabledLogger.info") _disabledLogger.warning("_disabledLogger.warning") _disabledLogger.error("_disabledLogger.error") rootOutput, baseOutput = self.getLogOutput() # Printed for debugging, when test fails: print("ROOT OUTPUT:\n'{}'\nBASE OUTPUT:\n'{}'".format( rootOutput, baseOutput)) # initLogging() removes all other handlers assert rootOutput == "" assert baseOutput == ""
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"] #_loadSeafileSettings(config) # Command line options 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") log_path = cmdLineOpts.get("log_path", "") if log_path: log_path = os.path.abspath(log_path) config["log_path"] = log_path util.initLogging(config["verbose"], config.get("log_path", ""), config.get("enable_loggers", [])) util.log("Default encoding: %s (file system: %s)" % (sys.getdefaultencoding(), sys.getfilesystemencoding())) _loadSeafileSettings(config) pid_file = cmdLineOpts.get("pid_file", "") if pid_file: pid_file = os.path.abspath(pid_file) config["pid_file"] = pid_file if not config["provider_mapping"]: print >>sys.stderr, "ERROR: No DAV provider defined. Try --help option." sys.exit(-1) return config, args
def __init__(self, config): self.config = config util.initLogging(config["verbose"], config.get("enable_loggers", [])) util.log("Default encoding: %s (file system: %s)" % (sys.getdefaultencoding(), sys.getfilesystemencoding())) # Evaluate configuration and set defaults _checkConfig(config) provider_mapping = self.config["provider_mapping"] # response_trailer = config.get("response_trailer", "") self._verbose = config.get("verbose", 2) lockStorage = config.get("locksmanager") if lockStorage is True: lockStorage = LockStorageDict() if not lockStorage: locksManager = None else: locksManager = LockManager(lockStorage) propsManager = config.get("propsmanager") if not propsManager: # Normalize False, 0 to None propsManager = None elif propsManager is True: propsManager = PropertyManager() mount_path = config.get("mount_path") # Instantiate DAV resource provider objects for every share self.providerMap = {} for (share, provider) in provider_mapping.items(): # Make sure share starts with, or is, '/' share = "/" + share.strip("/") # We allow a simple string as 'provider'. In this case we interpret # it as a file system root folder that is published. if compat.is_basestring(provider): provider = FilesystemProvider(provider) assert isinstance(provider, DAVProvider) provider.setSharePath(share) if mount_path: provider.setMountPath(mount_path) # TODO: someday we may want to configure different lock/prop # managers per provider provider.setLockManager(locksManager) provider.setPropManager(propsManager) self.providerMap[share] = { "provider": provider, "allow_anonymous": False} # Define WSGI application stack application = RequestResolver() domain_controller = None dir_browser = config.get("dir_browser", {}) middleware_stack = config.get("middleware_stack", []) # Replace WsgiDavDirBrowser to custom class for backward compatibility only # In normal way you should insert it into middleware_stack if dir_browser.get("enable", True) and "app_class" in dir_browser.keys(): config["middleware_stack"] = [m if m != WsgiDavDirBrowser else dir_browser[ 'app_class'] for m in middleware_stack] for mw in middleware_stack: if mw.isSuitable(config): if self._verbose >= 2: print("Middleware %s is suitable" % mw) application = mw(application, config) if issubclass(mw, HTTPAuthenticator): domain_controller = application.getDomainController() # check anonymous access for share, data in self.providerMap.items(): if application.allowAnonymousAccess(share): data['allow_anonymous'] = True else: if self._verbose >= 2: print("Middleware %s is not suitable" % mw) # Print info if self._verbose >= 2: print("Using lock manager: %r" % locksManager) print("Using property manager: %r" % propsManager) print("Using domain controller: %s" % domain_controller) print("Registered DAV providers:") for share, data in self.providerMap.items(): hint = " (anonymous)" if data['allow_anonymous'] else "" print(" Share '%s': %s%s" % (share, provider, hint)) if self._verbose >= 1: for share, data in self.providerMap.items(): if data['allow_anonymous']: # TODO: we should only warn here, if --no-auth is not given print("WARNING: share '%s' will allow anonymous access." % share) self._application = application