Ticket #8538: generate_doi.py

File generate_doi.py, 2.6 KB (added by Jay Rainey, 6 years ago)

Updated DOI wsdl

Line 
1#!/usr/bin/env python
2""" ICAT This utility will register a DOI for an investigation, dataset or datafile"""
3
4from suds import WebFault
5from suds.client import Client
6from suds.transport.https import HttpAuthenticated
7from getpass import getpass
8import logging
9
10logging.getLogger('suds.client').setLevel(logging.CRITICAL)
11
12# ICAT_WSDL = 'https://icatisis.esc.rl.ac.uk:8181/ICATService/ICAT?wsdl'
13ICAT_WSDL = 'https://icatdev.isis.cclrc.ac.uk/ICATService/ICAT?wsdl'
14# DOI_WSDL = 'https://sig-03.esc.rl.ac.uk:8181/doi/DOIService?wsdl'
15DOI_WSDL = 'https://topcatdev.isis.cclrc.ac.uk/doi/DOIWebService?wsdl'
16FACILITY = 'ISIS'
17ICAT_AUTH_TYPE = 'uows'
18
19
20def 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
45print '\nThis utility will register a DOI for an investigation\n'
46VERBOSE = 3
47
48ICAT_CLIENT = Client(ICAT_WSDL)
49FACTORY = ICAT_CLIENT.factory
50ICAT_SERVICE = ICAT_CLIENT.service
51
52DOI_CLIENT = Client(DOI_WSDL)
53DOI_SERVICE = DOI_CLIENT.service
54
55SESSION_ID = logon_icat()
56
57while 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
61INVESTIGATION_ID = raw_input('Object id:')
62
63try:
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))
73except WebFault, e:
74    print "inside try fail, oh darn!\n"   
75    print str(e)
76    ICAT_SERVICE.logout(SESSION_ID)
77    exit(1)
78
79ICAT_SERVICE.logout(SESSION_ID)
80print '\nDONE\n'
81exit(0)