def clone(self, params: JSONDict, workspace: Workspace) -> LocalStateResourceMixin: """Instantiate a resource that was created remotely. We need to verify that the local copy of the data exists -- we are not responsible for making certain it is in th correct place. """ name = params["name"] # check local_path, too for backward compatibility global_local_path = (params["global_local_path"] if "global_local_path" in params else params["local_path"]) # type: str local_params = {} # type: JSONDict if exists(global_local_path): local_path = global_local_path else: if not workspace.batch: local_path = cast( str, click.prompt( "Local files resource '%s' was located at '%s' on the original system. W\here is it located on this system?" % (name, global_local_path), type=LocalPathType(exists=True), ), ) local_params["my_local_path"] = local_path else: raise ConfigurationError( "Local files resource %s is missing from %s." % (name, global_local_path)) if not isinstance(workspace, git_backend.Workspace): non_git_hashes = join(local_path, ".hashes") if not exists(non_git_hashes): os.mkdir(non_git_hashes) return self.from_json(params, local_params, workspace)
def clone_scratch_directory( workspace_dir: str, global_params: Dict[str, Any], local_params: Dict[str, Any], batch: bool = False, ) -> str: """Set the scratch directory parameters for a cloned copy of the workspace, updating local_params if neded. Returns the absolute path for the scratch directory on this system. """ if SCRATCH_DIRECTORY in global_params: return join(workspace_dir, global_params[SCRATCH_DIRECTORY]) elif not batch: local_path = cast( str, click.prompt( "Please specify a location for this workspace's scratch directory (must be outside of workspace)", type=LocalPathType(exists=False, must_be_outside_of_workspace=workspace_dir), ), ) local_params[LOCAL_SCRATCH_DIRECTORY] = local_path return local_path else: # TODO: come up with a standard way of handling this when called from the API - either by # letting the user provide values in advance or by having some standard defaults. raise ConfigurationError( "Scratch directory was not within workspaces and we are running in batch mode. No way to ask user for location." )
def clone(self, params: JSONDict, workspace: Workspace) -> LocalStateResourceMixin: """Instantiate a resource that was created remotely. In this case, we will copy from the remote origin. """ remote_origin = params["remote_origin"] config = params["config"] name = params["name"] master = params.get("master", None) sync_mode = params.get("sync_mode", None) size_only = params.get("size_only", None) # check local_path, too for backward compatibility global_local_path = (params["global_local_path"] if "global_local_path" in params else params["local_path"]) # type: str if os.path.exists(global_local_path): local_path = global_local_path my_local_path = None # type: Optional[str] else: if not workspace.batch: # TODO: consider whether we can just create the directory the user specifies rather than # requiring it to pre-exist (since we will download anyway). local_path = cast( str, click.prompt( "Rclone resource '%s' was located at '%s' on the original system. Where is it located on this system?" % (name, global_local_path), type=LocalPathType(exists=True), ), ) my_local_path = local_path else: raise ConfigurationError( "Local files resource %s is missing from %s." % (name, global_local_path)) rclone = self._add_prechecks(local_path, remote_origin, config) self._copy_from_remote(name, local_path, remote_origin, rclone, master, sync_mode, size_only, workspace.verbose) return RcloneResource( name, params["role"], workspace, remote_origin, global_local_path=global_local_path, my_local_path=my_local_path, config=config, compute_hash=params["compute_hash"], export=params.get("export", False), imported=params.get("imported", False), master=master, sync_mode=sync_mode, size_only=size_only, )
default=None, help="Hostname to identify this machine in snapshot directory paths, " + "defaults to the result of the 'hostname' command.", ) @click.option( "--create-resources", default=[], type=RESOURCE_PARAM, help= "Initialize the workspace with subdirectories for the specified resource roles. Choices are 'all' or any comma-separated combination of %s." % ", ".join(RESOURCE_ROLE_CHOICES), ) @click.option( "--scratch-directory", default=None, type=LocalPathType(allow_multiple_levels_of_missing_dirs=True), help="Local scratch directory (defaults to WORKSPACE_DIR/scratch)", ) @click.option( "--git-fat-remote", type=str, help="Initialize the workspace with the git-fat large file extension " + "and use the specified URL for the remote datastore", ) @click.option("--git-fat-user", type=str, default=None, help="Username for git fat remote (if not root)") @click.option("--git-fat-port", type=int, default=None,