Back to index

nordugrid-arc-nox  1.1.0~rc6
librarian_client.py
Go to the documentation of this file.
00001 import arc, sys, time, os
00002 from arcom.xmltree import XMLTree
00003 from storage.client import LibrarianClient
00004 args = sys.argv[1:]
00005 if len(args) > 0 and args[0] == '-x':
00006     args.pop(0)
00007     print_xml = True
00008 else:
00009     print_xml = False
00010 try:
00011     librarian_url = os.environ['ARC_LIBRARIAN_URL']
00012     # print '- The URL of the Librarian:', librarian_url
00013 except:
00014     librarian_url = 'http://localhost:60000/Librarian'
00015     print '- ARC_LIBRARIAN_URL environment variable not found, using', librarian_url
00016 ssl_config = {}
00017 if librarian_url.startswith('https'):
00018     try:
00019         ssl_config['key_file'] = os.environ['ARC_KEY_FILE']
00020         ssl_config['cert_file'] = os.environ['ARC_CERT_FILE']
00021         # print '- The key file:', ssl_config['key_file']
00022         # print '- The cert file:', ssl_config['cert_file']
00023     except:
00024         ssl_config = {}
00025         print '- ARC_KEY_FILE or ARC_CERT_FILE environment variable not found, SSL disabled'
00026 librarian = LibrarianClient(librarian_url, print_xml, ssl_config = ssl_config)    
00027 if len(args) == 0 or args[0] not in ['new', 'get', 'traverseLN', 'modifyMetadata', 'remove']:
00028     print 'Supported methods: new get traverseLN modifyMetadata'
00029 else:
00030     command = args.pop(0)
00031     if command == 'new':
00032         if len(args) < 1:
00033             print 'Usage: new {collection,file} [<GUID>]'
00034         else:
00035             type = args.pop(0)
00036             metadata = {}
00037             metadata[('entry','type')] = type
00038             metadata[('timestamps','created')] = str(time.time())
00039             if len(args) > 0:
00040                 metadata[('entry', 'GUID')] = args[0]
00041             request = {'0' : metadata}
00042             print 'new', request
00043             print librarian.new(request)
00044     elif command == 'get':
00045         if len(args) < 1:
00046             print 'Usage: get <GUID> [<GUID> ...] neededMetadata [<section> [<property>] ...] '
00047         else:
00048             IDs = []
00049             while len(args) > 0 and args[0] != 'neededMetadata':
00050                 IDs.append(args.pop(0))
00051             neededMetadata = []
00052             if len(args) > 0:
00053                 args.pop(0)
00054             while len(args) > 0:
00055                 section = args.pop(0)
00056                 if len(args) > 0:
00057                     property = args.pop(0)
00058                 else:
00059                     property = ''
00060                 neededMetadata.append((section, property))
00061             print 'get', IDs, neededMetadata
00062             print librarian.get(IDs, neededMetadata)
00063     elif command == 'traverseLN':
00064         if len(args) < 1:
00065             print 'Usage: traverseLN <LN> [<LN> ...]'
00066         else:
00067             request = {}
00068             for i in range(len(args)):
00069                 request[str(i)] = args[i]
00070             print 'traverseLN', request
00071             print librarian.traverseLN(request)
00072     elif command == 'modifyMetadata':
00073         if len(args) < 5:
00074             print 'Usage: modifyMetadata <GUID> <changeType> <section> <property> <value>'
00075         else:
00076             request = {'0' : args}
00077             print 'modifyMetadata', request
00078             print librarian.modifyMetadata(request)
00079     elif command == 'remove':
00080         if len(args) < 1:
00081             print 'Usage: remove <GUID> [<GUID>, ...]'
00082         else:
00083             request = dict([(str(i), args[i]) for i in range(len(args))])
00084             print 'remove', request
00085             print librarian.remove(request)