Skip to content

Commit

Permalink
Merge pull request #16 from ResearchObject/add-cli
Browse files Browse the repository at this point in the history
add simple CLI and user guide
  • Loading branch information
elichad authored Jun 12, 2024
2 parents 0bc0bba + ff292d0 commit 28c96c9
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# ro-crate-uploader
RO-Crate uploader for Zenodo

[User Guide](docs/user_guide.md)
[Developer Guide](docs/developer_guide.md)
26 changes: 25 additions & 1 deletion docs/user_guide.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# User Guide - Under Construction

## Install requirements
## Install the project

```
git clone https://github.com/ResearchObject/ro-crate-uploader.git
cd ro-crate-uploader
pip install -r requirements.txt
pip install .
```

## Set up a Zenodo personal access token
Expand Down Expand Up @@ -43,3 +46,24 @@ api_token = your-token-here
```

`ro-crate-uploader` will read this token whenever it connects to Zenodo in order to perform actions under your account. It's recommended to use the Zenodo sandbox until you're confident using `ro-crate-uploader`.

## Run the code

Run the `rocrate_upload` command in your terminal. Use the `-s` flag to upload to Zenodo sandbox, or omit it to upload to real Zenodo.
```
rocrate_upload -s demo/demo_crate
```
Replace `demo/demo_crate` with the path to the RO-Crate directory you want to upload.

Once complete, you should see the draft record in your Zenodo dashboard.

Further info:
```
rocrate_upload --help
```

## Tips

1. Set `givenName` and `familyName` on authors of the RO-Crate.
2. Use the SPDX URI for the top-level license, e.g. `https://spdx.org/licenses/CC-BY-NC-SA-4.0.html`
3. Check your upload carefully before publishing.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Homepage = "https://www.researchobject.org/ro-crate/"
Repository = "https://github.com/ResearchObject/ro-crate-uploader"
Issues = "https://github.com/ResearchObject/ro-crate-uploader/issues"

[project.scripts]
rocrate_upload = "rocrate_upload.main:cli_entry"

[tool.setuptools.dynamic]
version = {attr = "rocrate_upload.__version__"}

Expand Down
43 changes: 43 additions & 0 deletions src/rocrate_upload/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import argparse
from rocrate.rocrate import ROCrate

from rocrate_upload.upload import (
build_zenodo_metadata_from_crate,
ensure_crate_zipped,
upload_crate_to_zenodo,
)


def cli_entry():
parser = argparse.ArgumentParser(
description="Takes a RO-Crate directory as input and uploads it to Zenodo"
)

parser.add_argument(
"ro_crate_directory",
help="RO-Crate directory to upload.",
type=str,
action="store",
)
parser.add_argument(
"-s",
"--sandbox",
help="Upload to Zenodo sandbox rather than Zenodo production",
action="store_true",
)
parser.add_argument(
"-p",
"--publish",
help="Publish the record after uploading.",
action="store_true",
)
args = parser.parse_args()

crate = ROCrate(args.ro_crate_directory)

metadata = build_zenodo_metadata_from_crate(crate)
crate_zip_path = ensure_crate_zipped(crate)
record = upload_crate_to_zenodo(
crate_zip_path, metadata, sandbox=args.sandbox, publish=args.publish
)
print(f'Created record {record["id"]} ({record["links"]["html"]})')
11 changes: 8 additions & 3 deletions src/rocrate_upload/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ def ensure_crate_zipped(crate: ROCrate) -> str:
return zipped


def upload_crate_to_zenodo(crate_zip_path: str, metadata: Metadata) -> Any:
def upload_crate_to_zenodo(
crate_zip_path: str,
metadata: Metadata,
sandbox: bool = True,
publish: bool = False,
) -> Any:
"""Upload a zipped crate and its metadata to Zenodo.
It's recommended to keep sandbox=True until ready for production use."""
Expand All @@ -114,8 +119,8 @@ def upload_crate_to_zenodo(crate_zip_path: str, metadata: Metadata) -> Any:
paths=[
crate_zip_path,
],
sandbox=True, # remove this when you're ready to upload to real Zenodo
publish=False,
sandbox=sandbox,
publish=publish,
)

return res.json()

0 comments on commit 28c96c9

Please sign in to comment.