forked from cmo/triple-tools
59 lines
1.5 KiB
Python
59 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import os
|
|
import sys
|
|
|
|
from dump_things_pyclient.communicate import (
|
|
HTTPError,
|
|
incoming_delete_record,
|
|
incoming_read_records,
|
|
)
|
|
|
|
|
|
def _main():
|
|
argument_parser = argparse.ArgumentParser()
|
|
argument_parser.add_argument('base_url')
|
|
argument_parser.add_argument('collection')
|
|
argument_parser.add_argument('label')
|
|
argument_parser.add_argument('--list-only', '-l', action='store_true', help="list records in the inbox, don't remove them")
|
|
|
|
arguments = argument_parser.parse_args()
|
|
|
|
curator_token = os.environ.get('CURATOR_TOKEN')
|
|
if curator_token is None:
|
|
print('ERROR: environment variable CURATOR_TOKEN not set', file=sys.stderr, flush=True)
|
|
return 1
|
|
|
|
for record, _, _, _, _ in incoming_read_records(
|
|
service_url=arguments.base_url,
|
|
collection=arguments.collection,
|
|
label=arguments.label,
|
|
token=curator_token,
|
|
):
|
|
if arguments.list_only:
|
|
print(f'{arguments.label}:\t{record}')
|
|
continue
|
|
|
|
# Delete record from incoming area
|
|
incoming_delete_record(
|
|
service_url=arguments.base_url,
|
|
collection=arguments.collection,
|
|
label=arguments.label,
|
|
pid=record['pid'],
|
|
token=curator_token,
|
|
|
|
)
|
|
return 0
|
|
|
|
|
|
def main():
|
|
try:
|
|
return _main()
|
|
except HTTPError as e:
|
|
print(f'ERROR: {e}: {e.response.text}', file=sys.stderr, flush=True)
|
|
return 1
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|