def _build_push_dests(self, push_sources): """ When the destination paths have not been explicitly specified, build them automatically. By default we try to push to the same absolute path on the remote host, converted to POSIX format. However if a relative directory root has been configured we will build a remote destination based on that. """ if self.cfg.push_relative_dir: self.logger.debug('local push dir = %s', self.cfg.push_relative_dir) # Set up the remote push dir. self._remote_push_dir = '/'.join( (self._remote_testplan_path, 'push_files')) self._mkdir_remote(self._remote_push_dir) self.setup_metadata.push_dir = self._remote_push_dir self.logger.debug('Created remote push dir %s', self._remote_push_dir) push_dsts = [ self._to_relative_push_dest(path) for path in push_sources ] else: push_dsts = [ pathutils.to_posix_path(path) for path in push_sources ] return push_dsts
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)))
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)))