view MetaDataClient.py @ 0:9f9d9be26e53

first checkin in Mercurial (see history in SVN)
author casties
date Mon, 25 Jul 2011 16:50:48 +0200
parents
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