-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from caltechlibrary/rsdoiel-master
Add in reporting improvements and CaltechDATA citation updating features
- Loading branch information
Showing
15 changed files
with
623 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ CaltechDATA_Logo_cropped.png | |
build/ | ||
dist/ | ||
ames.egg-info/ | ||
# Test files | ||
*.csv | ||
updates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
from .codemeta_to_datacite import codemeta_to_datacite | ||
from .epfmt import eprint_as_xml, eprint_as_json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# | ||
# epfmt is a Python 3.7 wrapper for the functionality of | ||
# the epfmt command line tool which is part of the eprinttools Go | ||
# package | ||
# | ||
# For the Go package see https://github.com/caltechlibrary/eprinttools. | ||
# | ||
import os | ||
import io | ||
import json | ||
import sys | ||
from subprocess import run, Popen, PIPE | ||
|
||
|
||
# | ||
# eprint_as_xml takes a Python dict of EPrint content like | ||
# that fetched with eputil returns the object as EPrint XML. | ||
# | ||
def eprint_as_xml(eprint_obj): | ||
src = json.dumps(eprint_obj) | ||
#if not isinstance(src, bytes): | ||
# src = src.encode('utf-8') | ||
cmd = ['epfmt', '-xml'] | ||
try: | ||
p = run(cmd, input = src.encode('utf-8'), capture_output = True) | ||
except Exception as e: | ||
sys.stderr.write(f"{e}\n") | ||
exit_code = p.returncode | ||
if exit_code != 0: | ||
print(f"ERROR: {' '.join(cmd)}, exit code {exit_code}") | ||
return None | ||
value = p.stdout | ||
if not isinstance(value, bytes): | ||
value = value.encode('utf8') | ||
return value.decode() | ||
|
||
# | ||
# eprint_as_json takes a Python Dict of EPrint content | ||
# like that fetch with eputil returns the object in JSON format. | ||
# | ||
def eprint_as_json(eprint_obj): | ||
src = json.dumps(eprint_obj) | ||
if not isinstance(src, bytes): | ||
src = src.encode('utf-8') | ||
cmd = ['epfmt', '-json'] | ||
try: | ||
p = run(cmd, input = src, capture_output = True) | ||
except Exception as e: | ||
sys.stderr.write(f"{e}\n") | ||
exit_code = p.returncode | ||
if exit_code != 0: | ||
print(f"ERROR: {' '.join(cmd)}, exit code {exit_code}") | ||
return None | ||
value = p.stdout | ||
if not isinstance(value, bytes): | ||
value = value.encode('utf8') | ||
return value.decode() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# | ||
# eputil.py is a Python 3.7 wrapper for the Go eprinttools | ||
# eputil command line program. | ||
# | ||
# For Go package see https://github.com/caltechlibrary/eprinttools. | ||
# | ||
import os | ||
import json | ||
import sys | ||
from subprocess import run, Popen, PIPE | ||
from datetime import datetime, timedelta | ||
|
||
|
||
# | ||
# get_eprint_keys returns a list of keys available from the | ||
# EPrints rest API indicated in the provided eprint_url. | ||
# | ||
# The eprint_url often is in the form containing a username/password | ||
# for access the API. E.g. | ||
# | ||
# 'https://jane.doe:[email protected]' | ||
# | ||
def get_eprint_keys(eprint_url): | ||
cmd = ['eputil'] | ||
cmd.append('-json') | ||
cmd.append(eprint_url + '/rest/eprint/') | ||
try: | ||
p = run(cmd, capture_output = True) | ||
except Exception as e: | ||
sys.stderr.write(f"{e}\n") | ||
|
||
exit_code = p.returncode | ||
if exit_code != 0: | ||
print(f"ERROR: {' '.join(cmd)}, exit code {exit_code}") | ||
return None | ||
value = p.stdout | ||
if not isinstance(value, bytes): | ||
value = value.encode('utf8') | ||
src = value.decode() | ||
if type(src) == str: | ||
if src == "": | ||
return [] | ||
keys = [] | ||
l = json.loads(src) | ||
for k in l: | ||
keys.append(f"{k}") | ||
return keys | ||
else: | ||
print(f"ERROR: wrong type {type(src)} for {src}") | ||
return None | ||
|
||
# | ||
# get_eprint returns a single EPrint element for given EPrint ID. | ||
# via the EPrints rest API indicated in the provided eprint_url. | ||
# | ||
# The eprint_url often is in the form containing a username/password | ||
# for access the API. E.g. | ||
# | ||
# 'https://jane.doe:[email protected]' | ||
# | ||
def get_eprint(eprint_url, eprint_id): | ||
eprint = {} | ||
cmd = ['eputil'] | ||
cmd.append('-json') | ||
cmd.append(eprint_url + '/rest/eprint/' + eprint_id + '.xml') | ||
try: | ||
p = run(cmd, capture_output = True) | ||
except Exception as e: | ||
sys.stderr.write(f"{e}\n") | ||
|
||
exit_code = p.returncode | ||
if exit_code != 0: | ||
print(f"ERROR: {' '.join(cmd)}, exit code {exit_code}") | ||
return None | ||
value = p.stdout | ||
if not isinstance(value, bytes): | ||
value = value.encode('utf8') | ||
src = value.decode() | ||
if type(src) == str: | ||
if src == "": | ||
return {} | ||
obj = json.loads(src) | ||
if 'eprint' in obj and len(obj['eprint']) > 0: | ||
return obj['eprint'][0] | ||
return None | ||
else: | ||
print(f"ERROR: wrong type {type(src)} for {src}") | ||
return None | ||
|
||
# | ||
# get_eprints returns an EPrint element in List form | ||
# for given EPrint ID via the EPrints rest API indicated in the | ||
# provided eprint_url (the outer XML is <eprints>... rather | ||
# than the inner XML of <eprints><eprint>...) | ||
# | ||
# The eprint_url often is in the form containing a username/password | ||
# for access the API. E.g. | ||
# | ||
# 'https://jane.doe:[email protected]' | ||
# | ||
def get_eprints(eprint_url, eprint_id): | ||
eprints = [] | ||
eprint = {} | ||
cmd = ['eputil'] | ||
cmd.append('-json') | ||
cmd.append(eprint_url + '/rest/eprint/' + eprint_id + '.xml') | ||
try: | ||
p = run(cmd, capture_output = True) | ||
except Exception as e: | ||
sys.stderr.write(f"{e}\n") | ||
exit_code = p.returncode | ||
if exit_code != 0: | ||
print(f"ERROR: {' '.join(cmd)}, exit code {exit_code}") | ||
return None | ||
value = p.stdout | ||
if not isinstance(value, bytes): | ||
value = value.encode('utf8') | ||
src = value.decode() | ||
if type(src) == str: | ||
if src == "": | ||
return [] | ||
obj = json.loads(src) | ||
if 'eprint' in obj and len(obj['eprint']) > 0: | ||
return obj | ||
return None | ||
else: | ||
print(f"ERROR: wrong type {type(src)} for {src}") | ||
return None | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
from .caltechdata import match_cd_refs | ||
from .caltechdata import match_codemeta | ||
from .caltechdata import fix_multiple_links | ||
from .update_datacite import update_datacite_media | ||
from .caltechdata import add_citation | ||
from .datacite import update_datacite_metadata | ||
from .datacite import update_datacite_media |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.