Esempio n. 1
0
def webdav_app(config_uri):
    plaster.setup_logging(config_uri)
    loader = plaster.get_loader(config_uri, protocols=['wsgi'])
    return loader.get_wsgi_app(name=WEBDAV_APP_NAME)
Esempio n. 2
0
def webdav_app(config_uri):
    config_uri = '{}#webdav'.format(config_uri)
    plaster.setup_logging(config_uri)
    loader = plaster.get_loader(config_uri, protocols=['wsgi'])
    return loader.get_wsgi_app()
Esempio n. 3
0
 def setup_logging(self):
     """call setup_logging for self's config"""
     plaster.setup_logging(self.config)
Esempio n. 4
0
def caldav_app(config_uri: str) -> RadicaleApplication:
    plaster.setup_logging(config_uri)
    loader = plaster.get_loader(config_uri, protocols=["wsgi"])
    return loader.get_wsgi_app(name=CALDAV_APP_NAME)
Esempio n. 5
0
def webdav_app(config_uri: str) -> WsgiDAVApp:
    plaster.setup_logging(config_uri)
    loader = plaster.get_loader(config_uri, protocols=["wsgi"])
    return loader.get_wsgi_app(name=WEBDAV_APP_NAME)
Esempio n. 6
0
    def run(self):  # pragma: no cover
        if not self.args.config_uri:
            self.out('You must give a config file')
            return 2
        app_spec = self.args.config_uri

        vars = self.get_config_vars()
        app_name = self.args.app_name

        base = os.getcwd()
        if not self._scheme_re.search(app_spec):
            config_path = os.path.join(base, app_spec)
            app_spec = 'config:' + app_spec
        else:
            config_path = None
        server_name = self.args.server_name
        if self.args.server:
            server_spec = 'egg:pyramid'
            assert server_name is None
            server_name = self.args.server
        else:
            server_spec = app_spec

        if self.args.reload and not hupper.is_active():
            if self.args.verbose > 1:
                self.out('Running reloading file monitor')
            hupper.start_reloader(
                'pyramid_plaster.plserve.main',
                reload_interval=int(self.args.reload_interval),
                verbose=self.args.verbose,
            )
            return 0

        if config_path:
            plaster.setup_logging(config_path)
            self.pserve_file_config(config_path, global_conf=vars)
            self.watch_files.append(config_path)

        if hupper.is_active():
            reloader = hupper.get_reloader()
            reloader.watch_files(self.watch_files)

        server = self.loadserver(
            config_path, name=server_name, relative_to=base, global_conf=vars)

        app = self.loadapp(
            config_path, name=app_name, relative_to=base, global_conf=vars)

        if self.args.verbose > 0:
            if hasattr(os, 'getpid'):
                msg = 'Starting server in PID %i.' % os.getpid()
            else:
                msg = 'Starting server.'
            self.out(msg)

        try:
            server(app)
        except (SystemExit, KeyboardInterrupt) as e:
            if self.args.verbose > 1:
                raise
            if str(e):
                msg = ' ' + str(e)
            else:
                msg = ''
            self.out('Exiting%s (-v to see traceback)' % msg)
Esempio n. 7
0
    def run(self, shell=None):
        if self.args.list:
            return self.show_shells()
        if not self.args.config_uri:
            self.out('Requires a config file argument')
            return 2
        config_uri = self.args.config_uri
        config_file = config_uri.split('#', 1)[0]
        plaster.setup_logging(config_file)
        self.pshell_file_config(config_file)

        # bootstrap the environ
        env = self.bootstrap[0](config_uri,
                                options=parse_vars(self.args.config_vars))

        # remove the closer from the env
        self.closer = env.pop('closer')

        # setup help text for default environment
        env_help = dict(env)
        env_help['app'] = 'The WSGI application.'
        env_help['root'] = 'Root of the default resource tree.'
        env_help['registry'] = 'Active Pyramid registry.'
        env_help['request'] = 'Active request object.'
        env_help['root_factory'] = (
            'Default root factory used to create `root`.')

        # override use_script with command-line options
        if self.args.setup:
            self.setup = self.args.setup

        if self.setup:
            # store the env before muddling it with the script
            orig_env = env.copy()

            # call the setup callable
            resolver = DottedNameResolver(None)
            setup = resolver.maybe_resolve(self.setup)
            setup(env)

            # remove any objects from default help that were overidden
            for k, v in env.items():
                if k not in orig_env or env[k] != orig_env[k]:
                    if getattr(v, '__doc__', False):
                        env_help[k] = v.__doc__.replace("\n", " ")
                    else:
                        env_help[k] = v

        # load the pshell section of the ini file
        env.update(self.loaded_objects)

        # eliminate duplicates from env, allowing custom vars to override
        for k in self.loaded_objects:
            if k in env_help:
                del env_help[k]

        # generate help text
        help = ''
        if env_help:
            help += 'Environment:'
            for var in sorted(env_help.keys()):
                help += '\n  %-12s %s' % (var, env_help[var])

        if self.object_help:
            help += '\n\nCustom Variables:'
            for var in sorted(self.object_help.keys()):
                help += '\n  %-12s %s' % (var, self.object_help[var])

        if shell is None:
            try:
                shell = self.make_shell()
            except ValueError as e:
                self.out(str(e))
                self.closer()
                return 1

        if self.pystartup and os.path.isfile(self.pystartup):
            with open(self.pystartup, 'rb') as fp:
                exec_(fp.read().decode('utf-8'), env)
            if '__builtins__' in env:
                del env['__builtins__']

        try:
            shell(env, help)
        finally:
            self.closer()