comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:9f9d9be26e53
1 import xmlrpclib
2 import sys
3 import base64
4 import bz2
5 import re
6 import logging
7 class MetaDataClient:
8
9 def __init__(self,serverUrl):
10 self.serverUrl=serverUrl
11 try:
12 self.server=xmlrpclib.ServerProxy(serverUrl)
13 except:
14 logging.error("MetaDataClient: writeMetaDataFile: (%s %s %s)"%sys.exc_info())
15
16 def writeMetaDataFile(self,path,newMetaXML,compressed=None):
17 #path hast to be an url to metadatafile or the path on the storage starting with /permanent or /experimental
18 # the url hast to contain the path to metadata file, the path has to start with /permanent or /experimental
19
20 path = self.correctPath(path)
21 if compressed:
22 newMetaXML=self.compress(newMetaXML);
23
24 ret=self.server.writeMetaDataFile(path,newMetaXML);
25 logging.debug("MetaDataClient: writeMetaDataFile:"+repr(ret))
26
27 return ret
28 def compress(self,txt):
29 return base64.encodestring(bz2.compress(string))
30
31 def correctPath(self,path):
32 #take only the path of the url which starts with /permanent or /experimental
33
34 rs= re.search("/permanent/(.*)", path);
35 if rs is not None:
36 txt="permanent/"+rs.group(1)
37 else:
38 rs= re.search("/experimental/(.*)", path);
39 if rs is not None:
40 txt="experimental"+rs.group(1)
41 else:
42 return None
43
44 return txt
45
46
47
48