def __init__(self, **data): """ constructor of Superclass """ Persistent.__init__(self) ISuperclass['objectID'].readonly = False self.objectID = generateOid(self) self.ikName = self.objectID for (name, value) in data.items(): if name in ISuperclass.names(): setattr(self, name, value) ISuperclass['objectID'].readonly = True self.ikAuthor = u"" self.dbgLevel = NOTSET self.history = RingBuffer(20) self.inpEQueue = Queue() self.outEQueue = Queue() self.outEReceiver = None self.workflows = {} self.wf_worklist = [] interaction = queryInteraction() if interaction is not None: for participation in interaction.participations: #principalid = participation.principal.id principal_title = participation.principal.title self.ikAuthor += unicode(principal_title) self.myFactory = str(self.__class__).split("'")[1] self.ikRevision = __version__
def makeAttributeTable(self): data = [] fields = self.getReportFields() for f_name, f_obj in fields.items(): f_val = getattr(self.context, f_name) namePara = self._convertNamePara(f_obj) if f_val is not None: if f_name in ['user', 'productionState']: token = self._getVocabValue(f_obj.field.vocabularyName, f_val) valPara = self._convertValPara(token) data.append([namePara, valPara]) elif type(f_val) is str or \ type(f_val) is unicode: valPara = self._convertValPara(f_val) data.append([namePara, valPara]) elif ISuperclass.providedBy(f_val): valPara = self._convertValPara(f_val) data.append([namePara, valPara]) else: if type(f_val) is list: valParas = [] for i in f_val: valParas.append(self._convertValPara(i)) if len(valParas) >= 1: data.append([namePara, valParas]) else: valPara = self._convertValPara(f_val) data.append([namePara, valPara]) return data
def anchor(value, item, formatter): """ anchor method will return a html formated anchor""" if value is None: return u'' if type(item) is dict: item = item['obj'] if ISuperclass.providedBy(value): item = value value = item.ikName try: myAdapter = zapi.queryMultiAdapter((item, formatter.request), name=view) if myAdapter is not None and canAccess(myAdapter,'render'): url = absoluteURL(item, formatter.request) + '/' + view return u'<a href="%s">%s</a>' % (url, value) else: # view = "details.html" myAdapter = zapi.queryMultiAdapter((item, formatter.request), name="details.html") if myAdapter is not None and canAccess(myAdapter,'render'): url = absoluteURL(item, formatter.request) + '/' + "details.html" return u'<a href="%s">%s</a>' % (url, value) else: return u'%s' % (value) except Exception: return u'%s' % (value)
def handleDelete(self, action): """delete was pressed""" if ISuperclass.providedBy(self.context): parent = self.getContent().__parent__ del parent[self.context.objectID] self.deleted = True self.context = parent url = absoluteURL(parent, self.request) self.request.response.redirect(url)
def traverse4Rpt(self, level, comments): """object pdf report level: indent-level (int 0..) comments: should there comments are in the output? """ if ISuperclass.providedBy(self.context): self.traverse4RptPre(level, comments) self.traverse4RptBody(level, comments) self.traverse4RptPost(level, comments)
def objs(self): """List of Content objects""" retList = [] try: for obj in self.context.values(): if ISuperclass.providedBy(obj): retList.append(obj) except: pass return retList
def updateSuperclassDCTitle(ikObject, event): """ Update an object's Dublin Core Title and back """ for i in event.descriptions: if ISuperclass.isEqualOrExtendedBy(i.interface): dcore = IWriteZopeDublinCore(ikObject) dcore.title = ikObject.ikName if IZopeDublinCore.isEqualOrExtendedBy(i.interface): dcore = IZopeDublinCore(ikObject) ikObject.ikName = dcore.title
def handleDelete(self, action): """delete was pressed""" if ISuperclass.providedBy(self.context): parent = self.context.__parent__ del parent[self.context.objectID] self.deleted = True self.context = parent url = absoluteURL(parent, self.request) self.request.response.redirect(url) # workaround for gocept.objectquery import transaction transaction.savepoint()
def handleDelete(self, action): """delete was pressed""" if ISuperclass.providedBy(self.context): parent = self.context.__parent__ parentList = list(parent.items()) oname = [oname for oname, oobj in parentList \ if oobj == self.context][0] del parent[oname] self.deleted = True self.context = parent url = absoluteURL(parent, self.request) self.request.response.redirect(url)
def traverse4Rpt(self, level, comments): """object pdf report level: indent-level (int 0..) comments: should there comments are in the output? """ if ISuperclass.providedBy(self.context): self.traverse4RptPre(level, comments) self.traverse4RptBody(level, comments) self.traverse4RptPost(level, comments) if self.document is not None and \ self.document._reporter is not None: self.document._reporter.alreadyReported[self.context.objectID] = self
def objs(self): """List of Content objects""" objWithPermisson = [] # allObj = getAllUtilitiesRegisteredFor(ISuperclass) # allObj = getAllUtilitiesRegisteredFor(Interface, context=self.context) smFolder = self.context.getParent() allObj = smFolder.values() for obj in allObj: if ISuperclass.providedBy(obj): myAdapter = zapi.queryMultiAdapter((obj, self.request), name='details.html') if myAdapter is not None and canAccess(myAdapter, 'render'): objWithPermisson.append(obj) return objWithPermisson
def getSortKey(self, item, formatter): if ISuperclass.providedBy(self.getter(item, formatter)): key = self.getter(item, formatter).ikName if key is not None: key = key.lower() else: key = u'\xffff' * 80 return key else: key = self.getter(item, formatter) if key is not None: key = key.lower() else: key = u'\xffff' * 80 return key
def handleDelete(self, action): """delete was pressed""" self.deleted = False objList = self.getContent().components nameList = [obj.ikName for obj in objList] if len(objList) > 0: self.deleted = False self.status = u"already used in: '%s'" % "' ,'".join(nameList) else: if ISuperclass.providedBy(self.context): parent = self.getContent().__parent__ del parent[self.context.objectID] self.deleted = True self.context = parent url = absoluteURL(parent, self.request) self.request.response.redirect(url)
def traverse4honeydGeneratorBody(self, cfgFile, level=0, comments=True): """graphviz configuration data of/in object """ if comments: print >> cfgFile, "%s## Body (%s,%d) - SupernodeGenHoneyd" % \ ("\t" * level, self.context.__name__, level) its = self.context.items() for (dummy_name, oobj) in its: if ISuperclass.providedBy(oobj): try: adapterGenHoneyd = IIKGenHoneyd(oobj) if adapterGenHoneyd: adapterGenHoneyd.traverse4honeydGenerator( cfgFile, level + 1, comments) except TypeError: logger.error(u"Problem in adaption of honeyd config")
def traverse4nagiosGeneratorBody(self, fileDict, level=0, comments=True): """graphviz configuration data of/in object """ if comments: print >> fileDict['HostCfg'], \ "%s## Body (%s,%d) - SupernodeGenNagios" % \ ("\t" * level, self.context.ikName, level) its = self.context.items() for (dummy_name, oobj) in its: if ISuperclass.providedBy(oobj): try: adapterGenNagios = IGenNagios(oobj) if adapterGenNagios: adapterGenNagios.traverse4nagiosGenerator( fileDict, level + 1, comments) except TypeError: logger.error(u"Problem in adaption of nagios config")
def traverse4DotGenerator(self, cfgFile, level=0, comments=True, request=None, alreadySeenList=None): """ cfgFile: handle to open file level: indent-level """ if ISuperclass.providedBy(self.context): self.traverse4DotGeneratorPre(cfgFile, level, comments, request, alreadySeenList) self.traverse4DotGeneratorBody(cfgFile, level, comments, request, alreadySeenList) self.traverse4DotGeneratorPost(cfgFile, level, comments, request, alreadySeenList)
def traverse4nagiosGeneratorBody(self, level=0, comments=True): """graphviz configuration data of/in object """ if comments: self.write("%s## Body (%s,%d) - SupernodeGenNagios" % \ ("\t" * level, self.context.ikName, level)) its = self.context.items() for (dummy_name, oobj) in its: if ISuperclass.providedBy(oobj): try: adapterGenNagios = IGenNagios(oobj) if adapterGenNagios: adapterGenNagios.parentAdapter = self adapterGenNagios.traverse4nagiosGenerator( level + 1, comments) except TypeError, errText: logger.error(u"Problem in nagios adaption: '%s'" % \ errText)
def handleDelete(self, action): """delete was pressed""" self.deleted = False if self.getContent().wasUsed: self.deleted = False self.status = u"already used" else: if ISuperclass.providedBy(self.context): sitem = getSiteManager(self) parent = self.getContent().__parent__ sitem.unregisterUtility(component=self.getContent(), provided=IIdChooser, name=self.getContent().ikName) del parent[self.context.objectID] self.deleted = True self.context = parent url = absoluteURL(parent, self.request) self.request.response.redirect(url)
def render(self): """Return the template with the option 'menus'""" objWithPermisson = [] utilManager = getUtility(IUtilManager) smFolder = utilManager.getParent() allObj = smFolder.values() for obj in allObj: if ISuperclass.providedBy(obj): if canAccess(obj, 'ikName'): myAdapter = zapi.queryMultiAdapter((obj, self.request), name='details.html') if myAdapter is not None and canAccess( myAdapter, 'render'): objWithPermisson.append(obj) if len(objWithPermisson) > 0: return self.template() else: return u''
def _convertValPara(self, f_val): if ISuperclass.providedBy(f_val): rptAdapter = IRptPdf(f_val) rptAdapter.request = self.request rptAdapter.document = self.document iText = rptAdapter.getRefTitle() else: # if isOidInCatalog(f_val): # iText = translate(oid2dcTitle(f_val), # domain='org.ict_ok', # context=self.request) # else: iText = translate(unicode(f_val), domain='org.ict_ok', context=self.request) rptPara = RptPara(iText, style=self.document.styles['Normal'], doc=self.document) return rptPara
def getEvaluationsTodo(context): """List of Content objects""" retSet = set([]) my_catalog = zapi.getUtility(ICatalog) if hasattr(context, "requirements"): if context.requirements is not None: for requirement in context.requirements: if ISuperclass.providedBy(requirement): res = my_catalog.searchResults(oid_index=requirement.objectID) else: res = my_catalog.searchResults(oid_index=requirement) if len(res) > 0: startReq = iter(res).next() allObjReqs = getRequirementList(startReq) allObjEvaluations = getEvaluationsDone(context) alreadyCheckedReqs = [ev[0] for ev in allObjEvaluations.items()] #retList.extend(set(allObjReqs).difference(alreadyCheckedReqs)) retSet = retSet.union(set(allObjReqs).difference(alreadyCheckedReqs)) # return retList return list(retSet)
def exportXmlData(self): """get data file for all objects""" #dataStructure = { #'objects': ['a', 'b', 'c'], #'conns': [1, 2, 3], #} dataStructure = { 'objects': [], } its = self.items() for (dummy_name, oobj) in its: if ISuperclass.providedBy(oobj): dataStructure['objects'].append(oobj.ikName) # sitemanger = zapi.getParent(self) # locSitemanager = zapi.getParent(sitemanger) # root_folder = zapi.getParent(locSitemanager) # for folder in root_folder.values(): # for obj in folder.values(): # obj.getAllExportData(dataStructure) python_pickle = pickle.dumps(dataStructure) return toxml(python_pickle)
def generateAllPdf(self, absFilename, authorStr, versionStr): """ will generate a complete pdf report """ files2delete = [] document = RptDocument(absFilename) document.setAuthorName(authorStr) document.setVersionStr(versionStr) its = self.items() for (dummy_name, oobj) in its: if ISuperclass.providedBy(oobj): try: adapterRptPdf = IRptPdf(oobj) if adapterRptPdf: adapterRptPdf.document = document adapterRptPdf.traverse4Rpt(1, False) files2delete.extend(adapterRptPdf.files2delete) del adapterRptPdf except TypeError, errText: logger.error(u"Problem in adaption of pdf report: %s" %\ (errText))
def traverse4RptBody(self, level, comments): """pdf report data of/in object level: indent-level (int 0..) comments: should there comments are in the output? """ if comments: self.writeComment(u"%s## Body (%s,%d) - Product" % \ ("\t" * level, self.context.ikName, level)) its = self.context.subProducts for oobj in its: if ISuperclass.providedBy(oobj): try: adapterRptPdf = IRptPdf(oobj) if adapterRptPdf: adapterRptPdf.document = self.document adapterRptPdf.traverse4Rpt(level + 1, comments) self.files2delete.extend(adapterRptPdf.files2delete) del adapterRptPdf except TypeError, errText: logger.error(u"Problem in adaption: %s (%s)" %\ (errText, oobj.ikName))
def traverse4RptBody(self, level, comments): """xml report data of/in object level: indent-level (int 0..) comments: should there comments are in the output? """ if comments: self.writeComment(u"%s## Body (%s,%d) - SupernodeRptXMLBody" % \ ("\t" * level, self.context.ikName, level)) its = self.context.items() for (dummy_name, oobj) in its: if ISuperclass.providedBy(oobj): try: adapterRptXML = IRptXML(oobj) if adapterRptXML: adapterRptXML.document = self.document adapterRptXML.traverse4Rpt(level + 1, comments) #self.files2delete.extend(adapterRptPdf.files2delete) del adapterRptXML except TypeError, errText: logger.error(u"Problem in adaption: %s (%s)" %\ (errText, oobj.ikName))
def objs(self): """List of Content objects""" return [obj for obj in self.context.values() if ISuperclass.providedBy(obj)]
def update(self): """update all widgets""" if ISuperclass.providedBy(self.context): self.label = self.context.ikName form.Form.update(self)
def appendReqXmlData(self, objects, rootElement): for (dummy_name, oobj) in objects: if ISuperclass.providedBy(oobj): rootElement.append(oobj.asETree())
def allNotifySubscriber(event): if not ISuperclass.providedBy(event.object): return notifierUtil = queryUtility(INotifierUtil) notifierUtil.sendNotify(event, event.object)
def traverse4DotGeneratorBody(self, \ cfgFile, \ level=0, \ comments=True, signalsOutput=False, recursive=True): """Pre-Text in graphviz dot-file""" if comments: print >> cfgFile, "%s// Body (%s,%d) - SupernodeGenGraphvizDot" \ % ("\t" * level, self.context.__name__, level) print >> cfgFile, '%s"%s" [' % ("\t" * level, self.context.objectID) print >> cfgFile, '%sshape="plaintext",' % ("\t" * (level + 1)) print >> cfgFile, '%sstyle="filled,setlinewidth(0)",' \ % ("\t" * (level + 1)) print >> cfgFile, '%sfillcolor = chartreuse2,' % ("\t" * (level + 1)) print >> cfgFile, '%smargin = 0,' % ("\t" * (level + 1)) print >> cfgFile, '%shref = "%s/@@details.html",' \ % ("\t" * (level + 1), zapi.getPath(self.context)) #print >> cfgFile, '%slabel = <<TABLE BORDER = "0" CELLBORDER = "0" ' \ #'CELLPADDING = "0" CELLSPACING = "0"><TR><TD>' \ #'<IMG SRC = "/home/markus/Projekte/IKOMtrol-hp/apple-red.png"/>' \ #'</TD></TR><TR><TD><FONT FACE = "Arial" POINT-SIZE = "10">%s' \ #'</FONT></TD></TR></TABLE>>' \ #% ("\t" * (level + 1), self.context.ikName) print >> cfgFile, '%slabel = <' % ("\t" * (level + 1)) print >> cfgFile, '%s<TABLE BORDER="0" CELLBORDER="1" CELLPADDING = "2" CELLSPACING = "0">' % ( "\t" * (level + 1)) print >> cfgFile, '%s<TR><TD WIDTH="120px">%s</TD></TR>' % ( "\t" * (level + 1), self.context.ikName) if signalsOutput: allInpNamesDict = self.context.getAllInpEventNames() for inpName in allInpNamesDict.keys(): print >> cfgFile, '%s<TR><TD ALIGN="LEFT" PORT="%s" '\ 'BGCOLOR="yellow">%s</TD></TR>' % \ ("\t" * (level + 1), inpName, inpName) allOutNamesDict = self.context.getAllOutEventNames() for outName in allOutNamesDict.keys(): print >> cfgFile, '%s<TR><TD ALIGN="RIGHT" PORT="%s" '\ 'BGCOLOR="orange">%s</TD></TR>' % \ ("\t" * (level + 1), outName, outName) #print >> cfgFile, '%s<TR><TD ALIGN="LEFT" PORT="sig_inp1" BGCOLOR="yellow">sig_inp1</TD></TR>' % ("\t" * (level + 1)) #print >> cfgFile, '%s<TR><TD ALIGN="LEFT" PORT="sig_inp2" BGCOLOR="yellow">sig_inp2</TD></TR>' % ("\t" * (level + 1)) #print >> cfgFile, '%s<TR><TD ALIGN="RIGHT" PORT="sig_out1" BGCOLOR="orange">sig_out1</TD></TR>' % ("\t" * (level + 1)) print >> cfgFile, '%s</TABLE>>' % ("\t" * (level + 1)) print >> cfgFile, '%s]; // %s' % ("\t" * level, self.context.__name__) if recursive: its = self.context.items() else: its = [] for (dummy_name, oobj) in its: if ISuperclass.providedBy(oobj): try: adapterGenGraphvizDot = IGenGraphvizDot(oobj) if adapterGenGraphvizDot: adapterGenGraphvizDot.setParent(self.context) adapterGenGraphvizDot.traverse4DotGenerator(\ cfgFile, level + 1, comments, signalsOutput) except TypeError, err: logging.error("Error in AdmUtilGraphviz::getRootDot()"\ % err)