Ejemplo n.º 1
0
    def get_args(self):
        """Return the arguments to be passed after self.cmd

        Doesn't expect shell expansion to happen.

        Also adds self.args at the end in case specified by the config.
        """

        presentation_type = self._get_presentation_type()

        if presentation_type == '':
            return super().get_args()

        launcher = self.merged_presentation_launchers[presentation_type]

        presentation_path = self.user_options.get('presentation_path', '')

        args = []

        # jhsingle-native-proxy --destport $destport --authtype oauth voila `pwd` {--}port={port} {--}no-browser {--}Voila.base_url={base_url}/ {--}Voila.server_url=/ --port $port

        notebook_dir = '.'
        if self.notebook_dir:
            notebook_dir = self.format_string(self.notebook_dir)

        git_repo = self.user_options.get('git_repo', '')
        repofolder = ''
        if git_repo != '':
            repofolder = self._calc_repo_folder(git_repo)
            args.append('--repo={}'.format(_quote_safe(git_repo)))
            notebook_dir = os.path.join(notebook_dir, repofolder)
            args.append('--repofolder={}'.format(_quote_safe(notebook_dir)))

        if presentation_path != '' and not '..' in presentation_path:
            # Should have been validated when dashboard created, but .. is particularly dangerous
            presentation_path = re.sub(
                '^/+', '', presentation_path
            )  # Remove leading slash(es) to ensure it is relative to home folder
            notebook_dir = os.path.join(notebook_dir, presentation_path)

        if 'args' in launcher:
            args.extend(launcher['args'])

        args.append('--presentation-path={}'.format(_quote_safe(notebook_dir)))

        conda_env = self.user_options.get('conda_env', '')
        if conda_env != '':
            args.append('--conda-env=%s' % _quote_safe(conda_env))

        if self.ip:
            args.append('--ip=%s' % _quote_safe(self.ip))

        if self.port:
            args.append('--port=%i' % self.port)

        if self.debug:
            if 'debug_args' in launcher:
                args.extend(launcher['debug_args'])
            else:
                args.append('{--}debug')
            args.append('--debug')  # For jhsingle-native-proxy itself

        proxy_request_timeout = getattr(self, 'proxy_request_timeout', 0)
        if proxy_request_timeout:
            args.append('--request-timeout={}'.format(proxy_request_timeout))

        proxy_force_alive = getattr(self, 'proxy_force_alive', True)
        if proxy_force_alive == False:
            args.append('--no-force-alive')

        proxy_last_activity_interval = getattr(self,
                                               'proxy_last_activity_interval',
                                               300)
        if proxy_last_activity_interval != 300:
            args.append('--last-activity-interval={}'.format(
                proxy_last_activity_interval))

        args.extend(self.args)

        if 'extra_args_fn' in launcher and callable(
                launcher['extra_args_fn']
        ):  # Last chance for launcher config to change everything and anything
            args = launcher['extra_args_fn'](args, self)

        return args
Ejemplo n.º 2
0
    def get_args(self):
        """Return the arguments to be passed after self.cmd

        Doesn't expect shell expansion to happen.

        Also adds self.args at the end in case specified by the config.
        """

        presentation_type = self._get_presentation_type()

        if presentation_type == '':
            return super().get_args()

        launcher = self.merged_presentation_launchers[presentation_type]

        presentation_path = self.user_options.get('presentation_path', '')

        args = []

        # jhsingle-native-proxy --destport $destport --authtype oauth voila `pwd` {--}port={port} {--}no-browser {--}Voila.base_url={base_url}/ {--}Voila.server_url=/ --port $port

        notebook_dir = '.'
        if self.notebook_dir:
            notebook_dir = self.format_string(self.notebook_dir)

        if presentation_path != '' and not '..' in presentation_path:
            # Should have been validated when dashboard created, but .. is particularly dangerous
            if presentation_path.startswith("/"):
                presentation_path = presentation_path[1:]
            notebook_dir = os.path.join(notebook_dir, presentation_path)

        if 'args' in launcher:
            args.extend(launcher['args'])

        args.append('--presentation-path={}'.format(_quote_safe(notebook_dir)))

        if self.ip:
            args.append('--ip=%s' % _quote_safe(self.ip))

        if self.port:
            args.append('--port=%i' % self.port)

        if self.debug:
            if 'debug_args' in launcher:
                args.extend(launcher['debug_args'])
            else:
                args.append('{--}debug')
            args.append('--debug')  # For jhsingle-native-proxy itself

        proxy_request_timeout = getattr(self, 'proxy_request_timeout', 0)
        if proxy_request_timeout:
            args.append('--request-timeout={}'.format(proxy_request_timeout))

        args.extend(self.args)

        if 'extra_args_fn' in launcher and callable(
                launcher['extra_args_fn']
        ):  # Last chance for launcher config to change everything and anything
            args = launcher['extra_args_fn'](args, self)

        return args