| 1 | #!/usr/bin/env python |
|---|
| 2 | """ ICAT This utility will register a DOI for an investigation, dataset or datafile""" |
|---|
| 3 | |
|---|
| 4 | from suds import WebFault |
|---|
| 5 | from suds.client import Client |
|---|
| 6 | from suds.transport.https import HttpAuthenticated |
|---|
| 7 | from getpass import getpass |
|---|
| 8 | import logging |
|---|
| 9 | |
|---|
| 10 | logging.getLogger('suds.client').setLevel(logging.CRITICAL) |
|---|
| 11 | |
|---|
| 12 | # ICAT_WSDL = 'https://icatisis.esc.rl.ac.uk:8181/ICATService/ICAT?wsdl' |
|---|
| 13 | ICAT_WSDL = 'https://icatdev.isis.cclrc.ac.uk/ICATService/ICAT?wsdl' |
|---|
| 14 | # DOI_WSDL = 'https://sig-03.esc.rl.ac.uk:8181/doi/DOIService?wsdl' |
|---|
| 15 | DOI_WSDL = 'https://topcatdev.isis.cclrc.ac.uk/doi/DOIWebService?wsdl' |
|---|
| 16 | FACILITY = 'ISIS' |
|---|
| 17 | ICAT_AUTH_TYPE = 'uows' |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | def logon_icat(): |
|---|
| 21 | """ |
|---|
| 22 | log on to ICAT |
|---|
| 23 | """ |
|---|
| 24 | try: |
|---|
| 25 | credentials = FACTORY.create("credentials") |
|---|
| 26 | entry = FACTORY.create("credentials.entry") |
|---|
| 27 | entry.key = 'username' |
|---|
| 28 | entry.value = raw_input('ICAT Username:') |
|---|
| 29 | credentials.entry.append(entry) |
|---|
| 30 | entry = FACTORY.create("credentials.entry") |
|---|
| 31 | entry.key = 'password' |
|---|
| 32 | entry.value = getpass('ICAT password: ') |
|---|
| 33 | credentials.entry.append(entry) |
|---|
| 34 | session_id = ICAT_SERVICE.login(ICAT_AUTH_TYPE, credentials) |
|---|
| 35 | except WebFault, e: |
|---|
| 36 | print "ERROR - Cannot log on to " + FACILITY + " - " + str(e) |
|---|
| 37 | # logout() |
|---|
| 38 | exit(2) |
|---|
| 39 | if VERBOSE >= 2: |
|---|
| 40 | print "Logged on to " + FACILITY |
|---|
| 41 | return session_id |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | print '\nThis utility will register a DOI for an investigation\n' |
|---|
| 46 | VERBOSE = 3 |
|---|
| 47 | |
|---|
| 48 | ICAT_CLIENT = Client(ICAT_WSDL) |
|---|
| 49 | FACTORY = ICAT_CLIENT.factory |
|---|
| 50 | ICAT_SERVICE = ICAT_CLIENT.service |
|---|
| 51 | |
|---|
| 52 | DOI_CLIENT = Client(DOI_WSDL) |
|---|
| 53 | DOI_SERVICE = DOI_CLIENT.service |
|---|
| 54 | |
|---|
| 55 | SESSION_ID = logon_icat() |
|---|
| 56 | |
|---|
| 57 | while True: |
|---|
| 58 | DATA_TYPE = raw_input('Object type: i, d or f:') |
|---|
| 59 | if ((DATA_TYPE == "i") or (DATA_TYPE == "d") or (DATA_TYPE == "f")): |
|---|
| 60 | break |
|---|
| 61 | INVESTIGATION_ID = raw_input('Object id:') |
|---|
| 62 | |
|---|
| 63 | try: |
|---|
| 64 | if (DATA_TYPE == "i"): |
|---|
| 65 | DOI_SERVICE.registerDatafileDOI(SESSION_ID, INVESTIGATION_ID) |
|---|
| 66 | print ("\nNew DOI:" + DOI_SERVICE.registerInvestigationDOI(SESSION_ID, INVESTIGATION_ID)) |
|---|
| 67 | if (DATA_TYPE == "d"): |
|---|
| 68 | DOI_SERVICE.registerDatafileDOI(SESSION_ID, INVESTIGATION_ID) |
|---|
| 69 | print ("\nNew DOI:" + DOI_SERVICE.registerDatasetDOI(SESSION_ID, INVESTIGATION_ID)) |
|---|
| 70 | if (DATA_TYPE == "f"): |
|---|
| 71 | DOI_SERVICE.registerDatafileDOI(SESSION_ID, INVESTIGATION_ID) |
|---|
| 72 | print ("\nNew DOI:" + DOI_SERVICE.registerDatafileDOI(SESSION_ID, INVESTIGATION_ID)) |
|---|
| 73 | except WebFault, e: |
|---|
| 74 | print "inside try fail, oh darn!\n" |
|---|
| 75 | print str(e) |
|---|
| 76 | ICAT_SERVICE.logout(SESSION_ID) |
|---|
| 77 | exit(1) |
|---|
| 78 | |
|---|
| 79 | ICAT_SERVICE.logout(SESSION_ID) |
|---|
| 80 | print '\nDONE\n' |
|---|
| 81 | exit(0) |
|---|