def getMetaCmd(self, id):
   obs = self.getMetaCmds(sort=False)
   # Filter by id.
   obs = [x for x in obs if x['id'] == id]
   # Not found!
   if len(obs) == 0:
     return None
   # Refresh Object.
   metaCmd = obs[0]
   if metaCmd.get('home',None)==None:
     return None
   if 'exec' in metaCmd:
     metaCmd['execution'] = metaCmd['exec']
     del metaCmd['exec']
   container = self.aq_parent
   src = zopeutil.getObject(metaCmd['home'], metaCmd['id'])
   newData = zopeutil.readObject(metaCmd['home'], metaCmd['id'], '')
   data = zopeutil.readObject(container, metaCmd['id'], '')
   acquiredExternalMethod = metaCmd.get('acquired',0) and src.meta_type=='External Method'
   if src is not None and (newData != data or acquiredExternalMethod):
     newId = metaCmd['id']
     newMethod = src.meta_type
     newTitle = '*** DO NOT DELETE OR MODIFY ***'
     zopeutil.removeObject(container, newId, removeFile=False)
     zopeutil.addObject(container, newMethod, ['',metaCmd['home'].getHome().getId()+'.'][acquiredExternalMethod]+newId, newTitle, newData)
   ob = zopeutil.getObject(container, metaCmd['id'])
   if ob is not None:
     metaCmd['meta_type'] = ob.meta_type
     metaCmd['data'] = zopeutil.readObject(container, metaCmd['id'], '')
     metaCmd['bobobase_modification_time'] = DateTime(ob._p_mtime)
   return metaCmd
Exemple #2
0
 def setProcess(self,
                oldId,
                newId,
                newAcquired=0,
                newName='',
                newType='process',
                newCommand=None):
     if newCommand is None:
         newCommand = ''
         if newType in ['Script (Python)']:
             newCommand += '# --// BO ' + newId + ' //--\n'
             newCommand += '# Example code:\n'
             newCommand += '\n'
             newCommand += '# Import a standard function, and get the HTML request and response objects.\n'
             newCommand += 'from Products.PythonScripts.standard import html_quote\n'
             newCommand += 'request = container.REQUEST\n'
             newCommand += 'RESPONSE =  request.RESPONSE\n'
             newCommand += '\n'
             newCommand += '# Return a string identifying this script.\n'
             newCommand += 'p = []\n'
             newCommand += 'p.append("This is the Python Script %s" % script.getId())\n'
             newCommand += 'p.append("in %s" % container.absolute_url())\n'
             newCommand += 'return "\\n".join(p)\n'
             newCommand += '\n'
             newCommand += '# --// EO ' + newId + ' //--\n'
         elif newType in ['External Method']:
             newCommand = ''
             newCommand += '# Example code:\n'
             newCommand += '\n'
             newCommand += 'def ' + newId + '( self, request):\n'
             newCommand += '  return "This is the external method ' + newId + '"\n'
     # Remove Zope-Object (if exists)
     zopeutil.removeObject(self, oldId)
     zopeutil.removeObject(self, newId)
     # Insert Zope-Object.
     if isinstance(newCommand, _blobfields.MyBlob):
         newCommand = newCommand.getData()
     if standard.is_str(newCommand):
         newCommand = newCommand.replace('\r', '')
     zopeutil.addObject(self, newType, newId, newName, newCommand)
     # Set.
     obs = self.processes
     ob = {}
     ob['acquired'] = newAcquired
     ob['name'] = newName
     ob['type'] = newType
     ob['command'] = newCommand
     obs[newId] = ob
     # Set attribute.
     self.processes = obs.copy()
     # Return with new id.
     return newId
Exemple #3
0
 def setTransition(self,
                   id,
                   newId,
                   newName,
                   newType,
                   newIconClass='',
                   newFrom=[],
                   newTo='',
                   newPerformer=[],
                   newData=''):
     message = ''
     obs = self.transitions
     # Remove exisiting entry.
     if id in obs:
         i = obs.index(id)
         del obs[i]
         del obs[i]
     else:
         i = len(obs)
     if len(newTo) == 0:
         newTo = []
     elif isinstance(newTo, str):
         newTo = [newTo]
     # Values.
     newValues = {}
     newValues['name'] = newName
     newValues['icon_clazz'] = newIconClass
     newValues['from'] = newFrom
     newValues['to'] = newTo
     newValues['performer'] = newPerformer
     # Zope Object.
     [zopeutil.removeObject(self, x) for x in [id, newId]]
     zopeutil.addObject(self, newType, newId, newName, newData)
     # Update attribute.
     obs.insert(i, newValues)
     obs.insert(i, newId)
     self.transitions = copy.copy(obs)
     # Return with message.
     return message
 def setMetacmd(self, id, newId, newAcquired, newPackage='', newRevision='0.0.0', newName='', newTitle='', newMethod=None, \
       newData=None, newExecution=0, newDescription='', newIconClazz='', newMetaTypes=[], \
       newRoles=['ZMSAdministrator'], newNodes='{$}'):
   
   # Catalog.
   obs = self.commands
   old = [x for x in obs if x['id'] in [id, newId]]
   if len(old) > 0:
     obs.remove(old[0])
   
   # Values.
   new = {}
   new['id'] = newId
   new['package'] = newPackage
   new['acquired'] = newAcquired
   new['revision'] = newRevision
   new['name'] = newName
   new['title'] = newTitle
   new['description'] = newDescription
   new['icon_clazz'] = newIconClazz
   new['meta_types'] = newMetaTypes
   new['roles'] = newRoles
   new['nodes'] = newNodes
   new['execution'] = newExecution
   obs.append(new)
   self.commands = copy.deepcopy(self.commands) # Make persistent.
   
   # Insert Object.
   if not newAcquired:
     container = self.getDocumentElement()
     if newMethod is None:
       newMethod = getattr(container, id).meta_type
     if id is None and newData is None:
       if newMethod in ['DTML Document', 'DTML Method']:
         newData = dtmlExampleCode
       elif newMethod == 'Page Template':
         newData = pageTemplateExampleCode 
       elif newMethod == 'Script (Python)':
         newData = pyScriptExampleCode
       elif newMethod == 'External Method':
         newData = ''
         newData += '# Example code:\n'
         newData += '\n'
         newData += 'def ' + newId + '( self):\n'
         newData += '  return "This is the external method ' + newId + '"\n'
     zopeutil.removeObject(container, id)
     zopeutil.removeObject(container, newId)
     object = zopeutil.addObject(container, newMethod, newId, newTitle, newData, permissions={'Authenticated':['View']})
   
   # Return with new id.
   return newId