def exportXmlData(self): """ export data as XML to the web browser """ from zope.xmlpickle import toxml import pickle obj = self.context pickleAdapter = IPickle(obj) if pickleAdapter: self.request.response.setHeader('Content-Type', 'application/ict-xml') filename = datetime.now().strftime('ictxml_%Y%m%d%H%M%S.xml') self.request.response.setHeader( 'Content-Disposition', 'attachment; filename=\"%s\"' % filename) setNoCacheHeaders(self.request.response) pickleDump = pickle.dumps(pickleAdapter.exportAsDict()) #return xmlEscapeWithCData( ##u'<?xml version="1.0" encoding="ISO-8859-1"?>' ##u'<datadump>%s</datadump>', #toxml(pickleDump)) #return pprint.pformat(pickleAdapter.exportAsDict(), \ #width=60, depth=6) return toxml(pickleDump) else: return _(u"no pickle adapter")
def exportAsDict(self, mode='backup'): """ this will export object properties as python-pickle """ retVal = {} retVal['objClass'] = self.context.__class__.__name__ retVal['objName'] = self.context.__name__ retVal['listAttr'] = {} retVal['listAttr']['ikName'] = self.context.ikName retVal['listAttr']['dbgLevel'] = self.context.dbgLevel retVal['listAttr']['objectID'] = self.context.objectID retVal['listAttr']['ikComment'] = self.context.ikComment retVal['listAttr']['ikAuthor'] = self.context.ikAuthor retVal['history'] = [] #print "exportAsDict - self.context.history: %s" % self.context.history if hasattr(self.context, 'history') and \ self.context.history is not None: ringBuffer = removeSecurityProxy(self.context.history) historyList = ringBuffer.get() for entry in historyList: retVal['history'].append(entry.exportAsDict(mode)) retVal['notes'] = [] if hasattr(self.context, 'ikNotes') and \ self.context.ikNotes is not None: for note in self.context.ikNotes: retVal['notes'].append(note) retVal['children'] = [] for name, obj in self.context.items(): recPickle = IPickle(obj) if recPickle: retVal['children'].append(recPickle.exportAsDict(mode)) return retVal
def dumpData(self): """ pretty print for web-interface """ import pprint obj = removeAllProxies(self.context) pickleAdapter = IPickle(obj) if pickleAdapter: return pprint.pformat(pickleAdapter.exportAsDict(), \ width = 60, depth = 6) else: return _(u"no pickle adapter")
def notifyModifiedEvent(instance, event): supervisor = queryUtility(IAdmUtilSupervisor, context=instance) if supervisor and supervisor.isSlave(): if hasattr(event.object, "getObjectId"): objectOid = event.object.getObjectId() else: objectOid = None mq_utility = queryUtility(IAdmUtilObjMQ) recPickle = IPickle(event.object) if mq_utility and supervisor and recPickle: my_data = {'cmd': 'obj_modified', 'obj': recPickle.exportAsDict()} my_data['header'] = {'from_oid': supervisor.objectID, 'from_ip': supervisor.ipv4My, 'from_path': getPath(supervisor), 'to_oid': supervisor.oidMaster, 'to_ip': supervisor.ipv4Master, 'to_path': u"/++etc++site/default"+\ "/AdmUtilSupervisor" } mq_utility.sendPerMq(my_data)
def notifyAddedEvent(instance, event): """ Node was added """ #logger.info(u"supernode.objmq.notifyAddedEvent: event: %s" % event) supervisor = queryUtility(IAdmUtilSupervisor) if supervisor and supervisor.isSlave(): if hasattr(event.object, "getObjectId"): objectOid = event.object.getObjectId() else: objectOid = None if hasattr(event.oldParent, "getObjectId"): oldParentOid = event.oldParent.getObjectId() else: oldParentOid = None if hasattr(event.newParent, "getObjectId"): newParentOid = event.newParent.getObjectId() else: newParentOid = None mq_utility = queryUtility(IAdmUtilObjMQ) recPickle = IPickle(event.object) if mq_utility and supervisor and recPickle: my_data = { 'cmd': 'obj_added', 'oldparent': oldParentOid, 'newparent': newParentOid, 'obj': recPickle.exportAsDict() } my_data['header'] = {'from_oid': supervisor.objectID, 'from_ip': supervisor.ipv4My, 'from_path': getPath(supervisor), 'to_oid': supervisor.oidMaster, 'to_ip': supervisor.ipv4Master, 'to_path': u"/++etc++site/default"+\ "/AdmUtilSupervisor" } mq_utility.sendPerMq(my_data)