Skip to content
This repository was archived by the owner on Mar 12, 2021. It is now read-only.

B2HANDLE Python client (epicclient2.py)

cookie33 edited this page Jul 12, 2017 · 10 revisions

The B2HANDLE library in itself does nothing. A client is needed to communicate with it. Therefore a epicclient2.py is supplied in the B2SAFE product/service.

It has a help function. This can be invoked as follows:

./epicclient2.py --help
usage: epicclient2.py [-h]
                      {os,irods} credpath
                      {search,read,create,modify,bulk,relation,delete} ...

EUDAT EPIC client API. Supports reading, querying, creating, modifying and
deleting handle records.

...

It always needs a file with credentials. So it will always be invoked as follows:

./epicclient2.py os <path>/<credentials_file> --help
usage: epicclient2.py [-h]
                      {os,irods} credpath
                      {search,read,create,modify,bulk,relation,delete} ...

EUDAT EPIC client API. Supports reading, querying, creating, modifying and
deleting handle records.

...

An example of the credentials file looks as follows:

{
    "handle_server_url": "https://fully_qualified_host_name:port",
    "private_key": "/<path>/21.T12996_USER01_310_privkey.pem",
    "certificate_only": "/<path>/21.T12996_USER01_310_certificate_only.pem",
    "prefix": "21.T12996",
    "handleowner": "200:0.NA/21.T12996",
    "reverselookup_username": "21.T12996",
    "reverselookup_password": "my_very_secret_password",
    "HTTPS_verify": "True"
}

The script supports several functions. They are described with the help function. The only function which is not extensive subscribed in the help is the bulk function.

It has the following functions:

  • create
  • modify
  • delete
  • read
  • search
  • relation
  • bulk

Each function is shortly described:

create

Create handles. The create function is invoked as follows:

./epicclient2.py os <path>/<credentials_file> create [--checksum CHECKSUM] [--extratype EXTRATYPE] [--loc10320 LOC10320] location

A handle is created with the URL value of location. The handle is generated using a uuid for the suffix. There are several optional values:

  • --checksum This is a value which will be assigned to a key CHECKSUM
  • --extratype This is a ; separated list of extra values to add. Example: NOOT=pinda;FIETS=transport
  • --loc10320 This is a value which will be assigned to a key 10320/LOC

modify

Modify handles. The modify function is invoked as follows:

./epicclient2.py os <path>/<credentials_file> modify handle key value

The handle is modified. The field with key is changed with a new value.

delete

Delete handles. The delete function is invoked as follows:

./epicclient2.py os <path>/<credentials_file> delete [--key KEY] handle

Either the whole handle is deleted or the field with value KEY is deleted.

read

Read handles. The read function is invoked as follows:

./epicclient2.py os <path>/<credentials_file> read [-h] [--key KEY] handle

Either the whole handle is returned or only the value of the field with value KEY.

search

Search handles. The search function is invoked as follows:

./epicclient2.py os <path>/<credentials_file> search {URL,CHECKSUM} value

The handle database is searched for either URL or CHECKSUM with the given value. It gives back the handles which match.

relation

Add a relation in 10320/LOC in a handle. The relation function is invoked as follows:

./epicclient2.py os <path>/<credentials_file> relation ppid cpid

Extend the 10320/LOC field with an extra value. It is special because the 10320/LOC field is an xml formatted string.

bulk

Perform bulk operations on handles. The bulk function is invoked as follows:

./epicclient2.py os <path>/<credentials_file> bulk --input <input_file> --result <output_result_file>

The bulk actions are read from an input file and executed. The result of each action is put in a result file. The separator in the input file is a single space. The following bulk actions are defined:

  • SEARCH
  • CREATE
  • READ
  • MODIFY
  • REPLACE
  • DELETE

The only new function is the REPLACE function. It causes a string to be replaced with a new string in a field in the handle. This allows you to update for instance an URL containing tes.com with test.com in http://tes.com

SEARCH

implementation of SEARCH action:

SEARCH URL http://www.test.com

line breakdown:

  • item 1: SEARCH
  • item 2: key for key/value pair to search in.
  • item 3: value for key/value pair to search for.

The key has to be a valid key. It excepts more than the standard URL and CHECKSUM from the standard epicclient2.py search function. But for it to function with other keys you will need to add allowed_search_keys with a list in the json credentials file

CREATE

implementation of CREATE action:

CREATE 841/uuid http://www.test841.com
CREATE 841/uuid http://www.test841.com 1223456789
CREATE 841/uuid http://www.test841.com 1223456789 http://hdl.handle.net/841/test
CREATE 841/uuid http://www.test841.com 1223456789 http://hdl.handle.net/841/test BOEKIE=zoekie;AAP=noot
CREATE 841/uuid http://www.test841.com none http://hdl.handle.net/841/test BOEKIE=zoekie;AAP=noot
CREATE 841/uuid http://www.test841.com none none BOEKIE=zoekie;AAP=noot
CREATE 841/uuid http://www.test841.com 123456789 none BOEKIE=zoekie;AAP=noot
CREATE 841/test841_1 http://www.test841.com 123456789 none BOEKIE=zoekie;AAP=noot

line breakdown:

  • item 1: CREATE
  • item 2: prefix/uuid or prefix/suffix. Use a new uuid or use the defined suffix. when uuid overwrite=False, otherwise True. The process is faster with the suffix filled in. Otherwise it does a check first if the handle already exists. This makes it slower.
  • item 3 URL to be filled in
  • item 4 none or CHECKSUM
  • item 5 none or 10320/LOC
  • item 6 none or key/value pairs in a ";' separated list.

Items 4 through 6 are optionals.

READ

implementation of READ action:

READ 841/test841_01
READ 841/test841_01 BOEKIE

line breakdown:

  • item 1: READ
  • item 2: handle.
  • item 3: key for key/value pair to read.

Item 3 is optional. If the optional is filled in the key/value pair will be shown. Otherwise the whole handle will be shown.

MODIFY

implementation of MODIFY action:

MODIFY 841/test841_01 BOEKIE zoeken

line breakdown:

  • item 1: MODIFY
  • item 2: handle.
  • item 3: key for key/value pair to modify.
  • item 4: value for key/value pair to modify to.

REPLACE

implementation of REPLACE action:

REPLACE 841/test841_02 CHECKSUM 345 543

line breakdown:

  • item 1: REPLACE
  • item 2: handle.
  • item 3: key for key/value pair to replace.
  • item 4: value for key/value pair to replace.
  • item 5: value for key/value pair to replace with.

The replace action will replace stringA with stringB in a key/value pair in one specific handle.

DELETE

implementation of DELETE action:

DELETE 841/a1a72f78-4b4e-11e7-8298-5254000df0ed CHECKSUM
DELETE 841/a1a72f78-4b4e-11e7-8298-5254000df0ed

line breakdown:

  • item 1: DELETE
  • item 2: handle.
  • item 3 Key for key/value pair to remove

Item 3 is optional. If the optional is filled in the key/value pair will be removed. Otherwise the whole handle will be removed.

example test input file for bulk operation

An example input is as follows:

SEARCH URL http://www.test841.com
CREATE 841/TEST_841_01 http://www.test841.com
SEARCH URL http://www.test841.com
CREATE 841/TEST_841_02 http://www.test841.com 123456789
CREATE 841/TEST_841_03 http://www.test841.com 123456789 http://www.test.com
CREATE 841/TEST_841_04 http://www.test841.com 123456789 http://www.test.com AAP=noot;JUT=jul
CREATE 841/TEST_841_05 http://www.test841.com 123456789 none AAP=noot;JUT=jul
CREATE 841/TEST_841_06 http://www.test841.com none http://www.test.com AAP=noot;JUT=jul
CREATE 841/TEST_841_07 http://www.test841.com none none AAP=noot;JUT=jul
SEARCH URL http://www.test841*
READ 841/TEST_841_01 URL
READ 841/TEST_841_02 URL
READ 841/TEST_841_02 CHECKSUM
READ 841/TEST_841_03 URL
READ 841/TEST_841_03 CHECKSUM
READ 841/TEST_841_03 10320/LOC
READ 841/TEST_841_04 URL
READ 841/TEST_841_04 CHECKSUM
READ 841/TEST_841_04 10320/LOC
READ 841/TEST_841_04 AAP
READ 841/TEST_841_04 JUT
READ 841/TEST_841_05 URL
READ 841/TEST_841_05 CHECKSUM
READ 841/TEST_841_05 10320/LOC
READ 841/TEST_841_05 AAP
READ 841/TEST_841_05 JUT
READ 841/TEST_841_06 URL
READ 841/TEST_841_06 CHECKSUM
READ 841/TEST_841_06 10320/LOC
READ 841/TEST_841_06 AAP
READ 841/TEST_841_06 JUT
READ 841/TEST_841_07 URL
READ 841/TEST_841_07 CHECKSUM
READ 841/TEST_841_07 10320/LOC
READ 841/TEST_841_07 AAP
READ 841/TEST_841_07 JUT
MODIFY 841/TEST_841_07 JUT joep
READ 841/TEST_841_07 JUT
READ 841/TEST_841_02 CHECKSUM
REPLACE 841/TEST_841_02 CHECKSUM 345 543
READ 841/TEST_841_02 CHECKSUM
REPLACE 841/TEST_841_02 CHECKSUM 345 543
REPLACE 841/TEST_841_02 CHECKSUMM 345 543
REPLACE 841/TEST_841_021 CHECKSUM 345 543
DELETE 841/TEST_841_01
DELETE 841/TEST_841_02
DELETE 841/TEST_841_03
DELETE 841/TEST_841_04
DELETE 841/TEST_841_05
DELETE 841/TEST_841_06
DELETE 841/TEST_841_07 AAP
DELETE 841/TEST_841_07

Clone this wiki locally