Changeset 794 for ZMS/trunk/ZMSMetaobjManager.py
- Timestamp:
- 16.11.2009 15:50:56 (3 years ago)
- File:
-
- 1 edited
-
ZMS/trunk/ZMSMetaobjManager.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ZMS/trunk/ZMSMetaobjManager.py
r723 r794 25 25 # Imports. 26 26 from __future__ import nested_scopes 27 from zope.interface import implements 27 28 from Products.ExternalMethod import ExternalMethod 28 29 from Products.PageTemplates import ZopePageTemplate … … 32 33 import ZPublisher.HTTPRequest 33 34 import copy 35 import os 34 36 import sys 35 37 import time … … 38 40 import _fileutil 39 41 import _globals 42 import IZMSSvnInterface 40 43 41 44 … … 74 77 attr['custom'] = '<connection>%s</connection>\n<params>%s</params>\n%s'%(connection,params,ob.src) 75 78 except: 76 value = _globals.writeError(self,'[ getMetaobjAttr]')79 value = _globals.writeError(self,'[syncType]') 77 80 78 81 … … 98 101 ################################################################################ 99 102 class ZMSMetaobjManager: 103 implements(IZMSSvnInterface.IZMSSvnInterface) 100 104 101 105 # Globals. … … 219 223 return ids 220 224 225 def exportMetaobjXml(self, ids, REQUEST=None, RESPONSE=None): 226 value = [] 227 for id in ids: 228 metaObj = self.getMetaobj( id) 229 if metaObj['type'] == 'ZMSPackage': 230 for pkgMetaObjId in self.getMetaobjIds(): 231 pkgMetaObj = self.getMetaobj( pkgMetaObjId) 232 if pkgMetaObj[ 'package'] == metaObj[ 'id']: 233 ids.append( pkgMetaObjId) 234 keys = self.model.keys() 235 keys.sort() 236 for id in keys: 237 if id in ids or len(ids) == 0: 238 ob = copy.deepcopy(self.__get_metaobj__(id)) 239 attrs = [] 240 for attr in ob['attrs']: 241 attr_id = attr['id'] 242 syncType( self, id, attr) 243 for key in ['keys','custom','default']: 244 if attr.has_key(key) and not attr[key]: 245 del attr[key] 246 attrs.append( attr) 247 ob['__obj_attrs__'] = attrs 248 for key in ['attrs','zms_system','acquired']: 249 if ob.has_key(key): 250 del ob[key] 251 # Value. 252 value.append({'key':id,'value':ob}) 253 # XML. 254 if len(value)==1: 255 value = value[0] 256 filename = '%s.metaobj.xml'%ids[0] 257 else: 258 filename = 'export.metaobj.xml' 259 content_type = 'text/xml; charset=utf-8' 260 export = self.getXmlHeader() + self.toXmlString(value,1) 261 262 if RESPONSE: 263 RESPONSE.setHeader('Content-Type',content_type) 264 RESPONSE.setHeader('Content-Disposition','inline;filename=%s'%filename) 265 return export 266 267 268 ############################################################################ 269 # 270 # IZMSSvnInterface 271 # 272 ############################################################################ 273 274 # -------------------------------------------------------------------------- 275 # ZMSMetaobjManager.svnCopy 276 # -------------------------------------------------------------------------- 277 def svnCopy(self, node, path, ids=[], excl_ids=[]): 278 l = [] 279 for id in self.getMetaobjIds(): 280 metaObj = self.getMetaobj(id) 281 if not metaObj.get('acquired'): 282 if metaObj.get('package') == '' or metaObj.get('type') == 'ZMSPackage': 283 action = None 284 path_id = id+'.metaobj.xml' 285 filepath = path+'/'+self.id+'/'+path_id 286 filemrevision = None 287 mrevision = metaObj.get('revision','0.0.0') 288 if os.path.exists( filepath): 289 filexml = self.parseXmlString( open(filepath), mediadbStorable=False) 290 if type(filexml) is list: 291 filexml = filter(lambda x: x['value']['type']=='ZMSPackage',filexml)[0] 292 filemrevision = filexml['value'].get('revision','0.0.0') 293 if mrevision > filemrevision: 294 action = 'refresh' 295 elif mrevision < filemrevision: 296 action = 'conflict' 297 else: 298 action = 'add' 299 if action: 300 l.append({'action':action,'filepath':filepath,'mrevision':mrevision,'filemrevision':filemrevision,'meta_type':self.meta_type}) 301 if filepath in ids: 302 xml = self.exportMetaobjXml([id]) 303 _fileutil.exportObj(xml,filepath) 304 return l 305 306 307 # -------------------------------------------------------------------------- 308 # ZMSMetaobjManager.svnUpdate 309 # -------------------------------------------------------------------------- 310 def svnUpdate(self, node, path, ids=[], excl_ids=[]): 311 l = [] 312 suffix = '.metaobj.xml' 313 # Changed resources. 314 for filename in os.listdir(path): 315 action = None 316 filepath = path+'/'+filename 317 file = open(filepath) 318 # Execute action. 319 if filepath in ids: 320 ob.metaobj_manager.importMetaobjXml( file) 321 elif filepath.endswith(suffix): 322 filexml = self.parseXmlString( file, mediadbStorable=False) 323 if type(filexml) is list: 324 filexml = filter(lambda x: x['value']['type']=='ZMSPackage',filexml)[0] 325 mrevision = None 326 filemrevision = filexml['value'].get('revision','0.0.0') 327 metaObjId = filename[:-len(suffix)] 328 if metaObjId in self.getMetaobjIds(): 329 metaObj = self.getMetaobj(metaObjId) 330 mrevision = metaObj.get('revision','0.0.0') 331 if mrevision < filemrevision: 332 action = 'refresh' 333 elif mrevision > filemrevision: 334 action = 'conflict' 335 else: 336 action = 'add' 337 if action: 338 l.append({'action':action,'filepath':filepath,'mrevision':mrevision,'filemrevision':filemrevision,'meta_type':self.meta_type}) 339 # Deleted resources. 340 for id in self.getMetaobjIds(): 341 metaObj = self.getMetaobj(id) 342 if not metaObj.get('acquired'): 343 if metaObj.get('package') == '' or metaObj.get('type') == 'ZMSPackage': 344 filename = id+suffix 345 filepath = path+'/'+filename 346 # Execute action. 347 if filepath in ids: 348 self.delMetaobj(id) 349 elif not os.path.exists( filepath): 350 action = 'delete' 351 mrevision = metaObj['revision'] 352 filemrevision = None 353 l.append({'action':action,'filepath':filepath,'mrevision':mrevision,'filemrevision':filemrevision,'meta_type':self.meta_type}) 354 355 return l 356 357 358 ############################################################################ 359 # 360 # OBJECTS 361 # 362 ############################################################################ 221 363 222 364 # -------------------------------------------------------------------------- … … 969 1111 metaOb = self.getMetaobj(id) 970 1112 if metaOb.get('acquired',0) == 1: 971 masterRoot = getattr(self,self.getConfProperty('Portal.Master')) 972 masterDocElmnt = masterRoot.content 973 REQUEST.set('ids',[id]) 974 xml = masterDocElmnt.metaobj_manager.manage_changeProperties(lang, self.getZMILangStr('BTN_EXPORT'), key, REQUEST, RESPONSE) 1113 xml = self.getPortalMaster().metaobj_manager.exportMetaobjXml([id]) 975 1114 self.importMetaobjXml(xml=xml) 976 1115 message = self.getZMILangStr('MSG_IMPORTED')%('<i>%s</i>'%id) … … 980 1119 elif btn == self.getZMILangStr('BTN_EXPORT'): 981 1120 sync_id = False 982 value = []983 1121 ids = REQUEST.get('ids',[]) 984 for id in ids: 985 metaObj = self.getMetaobj( id) 986 if metaObj['type'] == 'ZMSPackage': 987 for pkgMetaObjId in self.getMetaobjIds(): 988 pkgMetaObj = self.getMetaobj( pkgMetaObjId) 989 if pkgMetaObj[ 'package'] == metaObj[ 'id']: 990 ids.append( pkgMetaObjId) 991 keys = self.model.keys() 992 keys.sort() 993 for id in keys: 994 if id in ids or len(ids) == 0: 995 ob = copy.deepcopy(self.__get_metaobj__(id)) 996 attrs = [] 997 for attr in ob['attrs']: 998 attr_id = attr['id'] 999 syncType( self, id, attr) 1000 for key in ['keys','custom','default']: 1001 if attr.has_key(key) and not attr[key]: 1002 del attr[key] 1003 attrs.append( attr) 1004 ob['__obj_attrs__'] = attrs 1005 for key in ['attrs','zms_system','acquired']: 1006 if ob.has_key(key): 1007 del ob[key] 1008 # Value. 1009 value.append({'key':id,'value':ob}) 1010 # XML. 1011 if len(value)==1: 1012 value = value[0] 1013 filename = '%s.metaobj.xml'%ids[0] 1014 else: 1015 filename = 'export.metaobj.xml' 1016 content_type = 'text/xml; charset=utf-8' 1017 export = self.getXmlHeader() + self.toXmlString(value,1) 1018 1019 RESPONSE.setHeader('Content-Type',content_type) 1020 RESPONSE.setHeader('Content-Disposition','inline;filename=%s'%filename) 1021 return export 1122 return self.exportMetaobjXml(ids,REQUEST,RESPONSE) 1022 1123 1023 1124 # Insert.
Note: See TracChangeset
for help on using the changeset viewer.
