Ejemplo n.º 1
0
    def _get_syspath(self):
        """
        adapt sys path to the remote side, replacing main script dir
        with proper remote path. If we could not figure out just
        return sys.path

        :return: list of remote valid sys paths
        """

        sys_path = list(sys.path)
        main = sys.modules["__main__"]

        if main:
            main_path = os.path.dirname(os.path.abspath(main.__file__))
            if pathutils.is_subdir(main_path, self._workspace_paths.local):
                try:
                    rel_path = os.path.relpath(main_path,
                                               self._workspace_paths.local)
                    remote_path = os.path.join(self._workspace_paths.remote,
                                               rel_path)
                    sys_path.remove(main_path)
                    sys_path.insert(0, remote_path)
                except Exception as e:
                    self.logger.debug(
                        "could not set the remote path as desired will use sys.path",
                        exc_info=e,
                    )

        return sys_path
Ejemplo n.º 2
0
    def _to_relative_push_dest(self, local_path):
        """
        :param local_path: Full local path in local OS format.
        :return: Remote file and directory paths in POSIX format.
        """
        relative_root = self.cfg.push_relative_dir
        if not pathutils.is_subdir(local_path, relative_root):
            raise RuntimeError('Cannot push path {path} - is not within the '
                               'specified local root {root}'.format(
                                   path=local_path, root=relative_root))

        local_rel_path = os.path.relpath(local_path, relative_root)
        return '/'.join(
            (self._remote_push_dir, pathutils.to_posix_path(local_rel_path)))
Ejemplo n.º 3
0
    def _remote_sys_path(self):

        sys_path = [self._testplan_import_path.remote]

        for path in sys.path:
            path = fix_home_prefix(path)

            if is_subdir(path, self._workspace_paths.local):
                path = rebase_path(
                    path,
                    self._workspace_paths.local,
                    self._workspace_paths.remote,
                )

            sys_path.append(path)

        return sys_path
Ejemplo n.º 4
0
    def _remote_working_dir(self):
        """Choose a working directory to use on the remote host."""
        if not pathutils.is_subdir(self._working_dirs.local,
                                   self._workspace_paths.local):
            raise RuntimeError(
                'Current working dir is not within the workspace.\n'
                'Workspace = {ws}\n'
                'Working dir = {cwd}'.format(ws=self._workspace_paths.local,
                                             cwd=self._working_dirs.local))

        # Current working directory is within the workspace - use the same
        # path relative to the remote workspace.
        return pathutils.to_posix_path(
            os.path.join(
                self._workspace_paths.remote,
                os.path.relpath(self._working_dirs.local,
                                self._workspace_paths.local)))
Ejemplo n.º 5
0
    def _remote_working_dir(self):
        """Choose a working directory to use on the remote host."""
        if not is_subdir(self._working_dirs.local,
                         self._workspace_paths.local):
            raise RuntimeError(
                "Current working dir is not within the workspace.\n"
                "Workspace = {ws}\n"
                "Working dir = {cwd}".format(
                    ws=self._workspace_paths.local,
                    cwd=self._working_dirs.local,
                ))

        # Current working directory is within the workspace - use the same
        # path relative to the remote workspace.
        return rebase_path(
            self._working_dirs.local,
            self._workspace_paths.local,
            self._workspace_paths.remote,
        )