Mercurial > hg > MetaDataProvider
view MetaDataClient.py @ 12:7f0e2b656e5c
more work for non-bib metadata
author | casties |
---|---|
date | Fri, 29 Jul 2011 18:28:06 +0200 |
parents | 9f9d9be26e53 |
children |
line wrap: on
line source
import xmlrpclib import sys import base64 import bz2 import re import logging class MetaDataClient: def __init__(self,serverUrl): self.serverUrl=serverUrl try: self.server=xmlrpclib.ServerProxy(serverUrl) except: logging.error("MetaDataClient: writeMetaDataFile: (%s %s %s)"%sys.exc_info()) def writeMetaDataFile(self,path,newMetaXML,compressed=None): #path hast to be an url to metadatafile or the path on the storage starting with /permanent or /experimental # the url hast to contain the path to metadata file, the path has to start with /permanent or /experimental path = self.correctPath(path) if compressed: newMetaXML=self.compress(newMetaXML); ret=self.server.writeMetaDataFile(path,newMetaXML); logging.debug("MetaDataClient: writeMetaDataFile:"+repr(ret)) return ret def compress(self,txt): return base64.encodestring(bz2.compress(string)) def correctPath(self,path): #take only the path of the url which starts with /permanent or /experimental rs= re.search("/permanent/(.*)", path); if rs is not None: txt="permanent/"+rs.group(1) else: rs= re.search("/experimental/(.*)", path); if rs is not None: txt="experimental"+rs.group(1) else: return None return txt