Skip to content

Commit

Permalink
Merge branch 'release/v0.1.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhigman committed Mar 27, 2024
2 parents ca25efa + b13f000 commit 81e5cbc
Show file tree
Hide file tree
Showing 16 changed files with 624 additions and 119 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/bulk_disseminate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
NEW_IDS: ${{ steps.get-ids.outputs.NEW_IDS }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.10'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/disseminate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
work-id: ${{ fromJSON(inputs.work-ids) }}
steps:
- name: Make all platform credentials available to later steps (with names lowercased)
uses: oNaiPs/secrets-to-env-action@v1
uses: oNaiPs/secrets-to-env-action@v1.5
with:
secrets: ${{ toJSON(secrets) }}
convert: lower
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/docker_build_and_push_to_dockerhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
Expand All @@ -23,17 +23,17 @@ jobs:
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v3
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/manual_disseminate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# named IA_S3_ACCESS (access key) and IA_S3_SECRET (secret key).
# It is advised not to upload until the work is published and all metadata finalised.
name: manual-disseminate
run-name: 'manual-disseminate to ${{ github.event.inputs.platform }}: ${{ github.event.inputs.workIds }}'

on:
workflow_dispatch:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [[0.1.10]](https://github.com/thoth-pub/thoth-dissemination/releases/tag/v0.1.10) - 2024-03-27
### Changed
- Enhanced basic SWORD v2 (DSpace v7) functionality to fit CUL requirements
- Upgraded GitHub Actions dependencies from Node 16 to 20 (`docker/setup-qemu-action@v3`, `docker/setup-buildx-action@v3`, `docker/login-action@v3`, `docker/build-push-action@v5`, `actions/checkout@v4`, `actions/setup-python@v5`, `oNaiPs/secrets-to-env-action@v1.5`)

## [[0.1.9]](https://github.com/thoth-pub/thoth-dissemination/releases/tag/v0.1.9) - 2023-12-05
### Added
- GitHub Actions for recurring automatic uploads of newly published works to Figshare
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ docker run --rm ${imagename} ./disseminator.py --work ${work_id} --platform ${pl
### Options
`--work` = Thoth ID of work to be disseminated

`--platform` = Destination distribution/archiving platform (one of `InternetArchive`, `OAPEN`, `ScienceOpen`, `SWORD`, `Crossref`, `Figshare`)
`--platform` = Destination distribution/archiving platform (one of `InternetArchive`, `OAPEN`, `ScienceOpen`, `CUL`, `Crossref`, `Figshare`)

See also `--help`.
32 changes: 32 additions & 0 deletions culuploader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3
"""
Retrieve and disseminate files and metadata to
Cambridge University Library DSpace
"""

from dspaceuploader import DSpaceUploader, MetadataProfile


class CULUploader(DSpaceUploader):
def __init__(self, work_id, export_url, client_url, version):
"""Set CUL-specific parameters and pass them to DSpaceUploader"""
user_name_string = 'cam_ds7_user'
user_pass_string = 'cam_ds7_pw'
service_document_iri = (
'https://copim-b-dev.lib.cam.ac.uk/server/swordv2/servicedocument'
)
collection_iri = (
'https://copim-b-dev.lib.cam.ac.uk/server/swordv2/collection/1811/'
'7'
)
metadata_profile = MetadataProfile.JISC_ROUTER
super().__init__(
work_id,
export_url,
client_url,
version,
user_name_string,
user_pass_string,
service_document_iri,
collection_iri,
metadata_profile)
20 changes: 14 additions & 6 deletions disseminator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
and upload them in the appropriate format to various platforms.
"""

__version__ = '0.1.9'
__version__ = '0.1.10'

import argparse
import logging
Expand All @@ -16,15 +16,15 @@
from iauploader import IAUploader
from oapenuploader import OAPENUploader
from souploader import SOUploader
from swordv2uploader import SwordV2Uploader
from culuploader import CULUploader
from crossrefuploader import CrossrefUploader
from fsuploader import FigshareUploader

UPLOADERS = {
"InternetArchive": IAUploader,
"OAPEN": OAPENUploader,
"ScienceOpen": SOUploader,
"SWORD": SwordV2Uploader,
"CUL": CULUploader,
"Crossref": CrossrefUploader,
"Figshare": FigshareUploader,
}
Expand All @@ -48,15 +48,22 @@
"action": "store",
"default": "https://export.thoth.pub",
"help": "Thoth's Export API endpoint URL",
}, {
"val": "--client-url",
"dest": "client_url",
"action": "store",
"default": None,
"help": "URL of GraphQL API endpoint to use with Thoth Client",
}
]


def run(work_id, platform, export_url):
def run(work_id, platform, export_url, client_url):
"""Execute a dissemination uploader based on input parameters"""
logging.info('Beginning upload of {} to {}'.format(work_id, platform))
try:
uploader = UPLOADERS[platform](work_id, export_url, __version__)
uploader = UPLOADERS[platform](
work_id, export_url, client_url, __version__)
except KeyError:
logging.error('{} not supported: platform must be one of {}'.format(
platform, UPLOADERS_STR))
Expand Down Expand Up @@ -91,4 +98,5 @@ def get_arguments():
dotenv_path = Path('./config.env')
load_dotenv(dotenv_path=dotenv_path)
ARGUMENTS = get_arguments()
run(ARGUMENTS.work_id, ARGUMENTS.platform, ARGUMENTS.export_url)
run(ARGUMENTS.work_id, ARGUMENTS.platform,
ARGUMENTS.export_url, ARGUMENTS.client_url)
32 changes: 32 additions & 0 deletions dspaceuploader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3
"""
Retrieve and disseminate files and metadata to a DSpace repository
"""

from swordv2uploader import SwordV2Uploader, MetadataProfile


class DSpaceUploader(SwordV2Uploader):
# Currently DSpace dissemination is only implemented via SWORDv2
# This class will be extended once we implement e.g. DSpace REST API
def __init__(
self,
work_id,
export_url,
client_url,
version,
user_name_string,
user_pass_string,
service_document_iri,
collection_iri,
metadata_profile):
super().__init__(
work_id,
export_url,
client_url,
version,
user_name_string,
user_pass_string,
service_document_iri,
collection_iri,
metadata_profile)
11 changes: 5 additions & 6 deletions fsuploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
class FigshareUploader(Uploader):
"""Dissemination logic for Figshare"""

def __init__(self, work_id, export_url, version):
def __init__(self, work_id, export_url, client_url, version):
"""Instantiate class for accessing Figshare API."""
super().__init__(work_id, export_url, version)
super().__init__(work_id, export_url, client_url, version)
try:
api_token = self.get_credential_from_env(
'figshare_token', 'Figshare')
Expand Down Expand Up @@ -125,9 +125,8 @@ def upload_to_platform(self):
def parse_metadata(self):
"""Convert work metadata into Figshare format."""
work_metadata = self.metadata.get('data').get('work')
try:
long_abstract = work_metadata.get('longAbstract')
except KeyError:
long_abstract = work_metadata.get('longAbstract')
if long_abstract is None:
logging.error(
'Cannot upload to Figshare: Work must have a Long Abstract')
sys.exit(1)
Expand Down Expand Up @@ -261,7 +260,7 @@ def get_figshare_authors(metadata):
"""
# fullName is mandatory so we do not expect KeyErrors
authors = [{'name': n['fullName']} for n in metadata.get('contributions')
if n.get('mainContribution') == True]
if n.get('mainContribution') is True]
if len(authors) < 1:
logging.error(
'Cannot upload to Figshare: Work must have at least one Main Contribution')
Expand Down
3 changes: 2 additions & 1 deletion iauploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def parse_metadata(self):
# Repeatable fields such as 'creator', 'isbn', 'subject'
# can be set by submitting a list of values
creators = [n.get('fullName')
for n in work_metadata.get('contributions') if n.get('mainContribution') == True]
for n in work_metadata.get('contributions')
if n.get('mainContribution') is True]
# IA metadata schema suggests hyphens should be omitted,
# although including them does not cause any errors
isbns = [n.get('isbn').replace(
Expand Down
3 changes: 2 additions & 1 deletion obtain_new_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ def get_thoth_ids(self):
break
offset += 1
next_work = next_batch[0]
next_work_pub_date = datetime.strptime(next_work.publicationDate, "%Y-%m-%d").date()
next_work_pub_date = datetime.strptime(
next_work.publicationDate, "%Y-%m-%d").date()
if next_work_pub_date > previous_month_end:
# This work will be handled in next month's run - don't cause duplication
continue
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pysftp==0.2.9
python-dotenv==0.19.2
requests==2.31.0
sword2==0.3.0
thothlibrary==0.20.1
thothlibrary==0.25.0
2 changes: 1 addition & 1 deletion requirements_obtain_new_ids.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
internetarchive==3.0.2
thothlibrary==0.20.0
thothlibrary==0.25.0
Loading

0 comments on commit 81e5cbc

Please sign in to comment.