Skip to content

Commit

Permalink
Handle files relative to working directory + added upload and downloa…
Browse files Browse the repository at this point in the history
…d cwl tool files.
  • Loading branch information
sverhoeven committed Feb 6, 2017
1 parent fd2810f commit 2b47683
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 10 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@ Requires `nlesc/xenon-cli` Docker image to be available locally.

Example to list contents of `/etc` directory via a ssh to localhost connection with cwl-runner:
```
cwl-runner xenon-ls.cwl --adaptor local --location localhost --path /etc
./xenon-ls.cwl --scheme ssh --location <user>@<host> --path $PWD --certfile ~/.ssh/id_rsa
./xenon-upload.cwl --scheme ssh --source $PWD/README.md --location <user>@<host> --path /tmp/copy-of-README.md --certfile ~/.ssh/id_rsa
./xenon-download.cwl --scheme ssh --location <user>@<host> --path /tmp/copy-of-README.md --target /tmp/another-copy-of-README.md --certfile ~/.ssh/id_rsa
```
(Replace `<user>@<host>` with actual username and hostname)
19 changes: 19 additions & 0 deletions src/main/java/nl/esciencecenter/xenon/cli/CopyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,32 @@
import nl.esciencecenter.xenon.XenonException;
import nl.esciencecenter.xenon.files.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class CopyCommand extends XenonCommand {
private static final Logger LOGGER = LoggerFactory.getLogger(CopyCommand.class);

protected void copy(Files files, CopyInput source, CopyInput target) throws XenonException {
FileSystem sourceFS = files.newFileSystem(source.scheme, source.location, source.credential, source.properties);
FileSystem targetFS = files.newFileSystem(target.scheme, target.location, target.credential, target.properties);

Path sourcePath = files.newPath(sourceFS, new RelativePath(source.path));
if ("local".equals(source.scheme) || "file".equals(source.scheme)) {
if (!source.path.startsWith("/")) {
// Path is relative to working directory, make it absolute
RelativePath workingDirectory = new RelativePath(System.getProperty("user.dir"));
sourcePath = files.newPath(sourceFS, workingDirectory.resolve(source.path));
}
}
Path targetPath = files.newPath(targetFS, new RelativePath(target.path));
if ("local".equals(target.scheme) || "file".equals(target.scheme)) {
if (!target.path.startsWith("/")) {
// Path is relative to working directory, make it absolute
RelativePath workingDirectory = new RelativePath(System.getProperty("user.dir"));
sourcePath = files.newPath(sourceFS, workingDirectory.resolve(target.path));
}
}

files.copy(sourcePath, targetPath, CopyOption.CREATE);

Expand Down
40 changes: 40 additions & 0 deletions xenon-download.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env cwl-runner
cwlVersion: v1.0
class: CommandLineTool
doc: Download file from remote storage
requirements:
- class: DockerRequirement
# xenon-cli Docker container needs to be manually build before
dockerImageId: nlesc/xenon-cli
arguments:
- --json
- download
inputs:
scheme:
type: string
inputBinding:
prefix: --scheme
position: -1
certfile:
type: File?
inputBinding:
prefix: --certfile
position: -1
location:
type: string?
inputBinding:
position: 1
path:
type: string
inputBinding:
position: 2
target:
type: string
inputBinding:
position: 3
outputs:
target:
type: File
outputBinding:
glob: $(inputs.target)
# stdout: cwl.output.json
25 changes: 16 additions & 9 deletions xenon-ls.cwl
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#!/usr/bin/env cwl-runner

# Examples:
# xenon --adaptor ssh --json list --location localhost /etc
# xenon --adaptor local --json list /etc

cwlVersion: v1.0
class: CommandLineTool
doc: List objects on remote storage
Expand All @@ -15,15 +10,19 @@ arguments:
- --json
- list
inputs:
adaptor:
scheme:
type: string
inputBinding:
prefix: --adaptor
prefix: --scheme
position: -1
certfile:
type: File?
inputBinding:
prefix: --certfile
position: -1
location:
type: string?
inputBinding:
prefix: --location
position: 1
path:
type: string
Expand All @@ -34,4 +33,12 @@ outputs:
type:
type: array
items: string
stdout: cwl.output.json
files:
type:
type: array
items: string
directories:
type:
type: array
items: string
stdout: cwl.output.json
37 changes: 37 additions & 0 deletions xenon-upload.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env cwl-runner
cwlVersion: v1.0
class: CommandLineTool
doc: Upload file to remote storage
requirements:
- class: DockerRequirement
# xenon-cli Docker container needs to be manually build before
dockerImageId: nlesc/xenon-cli
arguments:
- --json
- upload
inputs:
scheme:
type: string
inputBinding:
prefix: --scheme
position: -1
certfile:
type: File?
inputBinding:
prefix: --certfile
position: -1
source:
type: File
inputBinding:
position: 1
location:
type: string?
inputBinding:
position: 2
path:
type: string
inputBinding:
position: 3
outputs:
path: File
stdout: cwl.output.json

0 comments on commit 2b47683

Please sign in to comment.