Esempio n. 1
0
 def __init__(self,
              debug=False,
              DbOnly=False,
              doc=False,
              arch='vxWorks-ppc604_long'):
     # This is a default architecture
     self.architecture = arch
     self.simarch = False
     self.epics_base = None
     self.build_root = '.'
     self.iocname = 'example'
     # This the group of undo stacks for each table
     self.stack = QUndoGroup()
     # this is a dict of tables
     self._tables = {}
     self._tableNames = []
     # store the debug state
     self.debug = debug
     self.DbOnly = DbOnly
     self.doc = doc
     self.setLastModified()
     # this is the list of objects provided by this module, for documentation
     self.moduleObjects = []
     # store the arch and tableNames so we know we're clean
     self.setStored()
Esempio n. 2
0
 def __init__(self, debug = False, DbOnly = False, doc = False,
         arch = 'vxWorks-ppc604_long'):
     # This is a default architecture
     self.architecture = arch
     self.simarch = False
     self.epics_base = None
     self.build_root = '.'
     self.iocname = 'example'
     # This the group of undo stacks for each table
     self.stack = QUndoGroup()
     # this is a dict of tables
     self._tables = {}
     self._tableNames = []
     # store the debug state
     self.debug = debug
     self.DbOnly = DbOnly
     self.doc = doc
     self.setLastModified()
     # this is the list of objects provided by this module, for documentation
     self.moduleObjects = []
     # store the arch and tableNames so we know we're clean
     self.setStored()
Esempio n. 3
0
class Store(object):
    def __init__(self,
                 debug=False,
                 DbOnly=False,
                 doc=False,
                 arch='vxWorks-ppc604_long'):
        # This is a default architecture
        self.architecture = arch
        self.simarch = False
        self.epics_base = None
        self.build_root = '.'
        self.iocname = 'example'
        # This the group of undo stacks for each table
        self.stack = QUndoGroup()
        # this is a dict of tables
        self._tables = {}
        self._tableNames = []
        # store the debug state
        self.debug = debug
        self.DbOnly = DbOnly
        self.doc = doc
        self.setLastModified()
        # this is the list of objects provided by this module, for documentation
        self.moduleObjects = []
        # store the arch and tableNames so we know we're clean
        self.setStored()

    def setStored(self):
        self._storedarchitecture = self.architecture
        self._stored_tableNames = self._tableNames[:]
        for table in self._tables.values():
            table.stack.setClean()

    def isClean(self):
        if self._storedarchitecture != self.architecture:
            return False
        if len(self._stored_tableNames) != len(self._tableNames):
            return False
        for x, y in zip(self._tableNames, self._stored_tableNames):
            if x != y:
                return False
        return True

    def lastModified(self):
        return self._lastModified

    def setLastModified(self, index1=None, index2=None):
        self._lastModified = time.time()

    def New(self):
        '''Create a new table list by setting up ModuleVersion calls according
        to paths in release'''
        # First clear up the undo stack
        for stack in self.stack.stacks():
            self.stack.removeStack(stack)
        # then clear the table list
        self._tables.clear()
        # then clear the display list
        self._tableNames = []
        self._stored_tableNames = []
        # Now make sure there is no iocbuilder hanging around
        for k in [k for k in sys.modules if k.startswith('iocbuilder')]:
            del sys.modules[k]
        if 'iocbuilder' in globals():
            del (iocbuilder)
        # now do the import and configure of iocbuilder
        import iocbuilder
        if self.debug:
            print '# Creating IOC with Architcture %s' % (self.architecture)
            if self.simarch:
                print '# Simulation mode'
        self.iocbuilder = iocbuilder
        self.ioc_writer = None
        if self.DbOnly:
            self.ioc_writer = iocbuilder.iocwriter.DbOnlyWriter
        elif self.doc:
            self.ioc_writer = iocbuilder.iocwriter.DocumentationIocWriter
        # do the moduleversion calls
        from dls_dependency_tree import dependency_tree
        vs = self.iocbuilder.ParseAndConfigure(self, dependency_tree)
        # create AutoSubstitutions and moduleObjects
        for v in vs:
            if self.debug:
                print 'Making auto objects from %s' % v.LibPath()
            iocbuilder.AutoSubstitution.fromModuleVersion(v)
            iocbuilder.Xml.fromModuleVersion(v)
        # create our dict of classes
        classes = iocbuilder.includeXml.createClassLookup()
        # now we can make our tables
        for name, o in classes.items():
            # make a table object
            table = Table(o, self)
            # add it to our internal dict of tables
            self._tables[name] = table
            # add the undo stack
            self.stack.addStack(table.stack)
            # connect its modified signal to store a timestamp
            table.connect(
                table,
                SIGNAL(
                    'dataChanged(const QModelIndex &, const QModelIndex &)'),
                self.setLastModified)
        self.setStored()
        # failure if there were no callables
        self.setLastModified()

    def Open(self, filename, sim=None):
        if self.debug:
            print '--- Parsing %s ---' % filename
        self.iocname = os.path.basename(filename).replace('.xml', '')
        self.build_root = os.path.dirname(os.path.abspath(filename))
        # read the tables
        xml_root = xml.dom.minidom.parse(filename)
        # find the root node
        components = self._elements(xml_root)[0]
        if sim is not None:
            self.architecture = sim
            self.simarch = self.architecture
        else:
            self.architecture = str(components.attributes['arch'].value)
            self.simarch = None
        self.New()
        # proccess each component in turn
        problems = []
        warnings = []
        commentText = ""
        for node in components.childNodes:
            # try to find the class of each component
            if node.nodeType == node.COMMENT_NODE:
                # If it's a comment, then mark as a comment and try to process
                # its content
                commented = True
                text = '<junk>' + node.toxml()[4:-3] + '</junk>'
                root = self._elements(xml.dom.minidom.parseString(text))[0]
                nodes = self._elements(root)
                if len(nodes) == 0:
                    # treat this as a comment on the next node
                    commentText = str(node.nodeValue)
            elif node.nodeType == node.ELEMENT_NODE:
                # If it's an element node, then just add this node
                commented = False
                nodes = [node]
            else:
                # Ignore whitespace
                continue
            for node in nodes:
                # find the correct table
                obname = str(node.nodeName)
                if self._tables.has_key(obname):
                    pass
                elif self._tables.has_key(obname.replace("auto_", "")):
                    node.nodeName = obname.replace("auto_", "")
                    obname = str(node.nodeName)
                else:
                    problems.append(obname)
                    continue
                table = self.getTable(obname)
                if obname not in self._tableNames:
                    self._tableNames.append(obname)
                # make a new row
                warnings += table.addNode(node, commented, commentText)
                commentText = ""
        self.setStored()
        self.setLastModified()
        return self._unique(problems, warnings)

    def _unique(self, *ls):
        # make each list in args unique, then return a tuple of them
        ret = []
        for l in ls:
            newl = []
            for x in l:
                if x not in newl:
                    newl.append(x)
            ret.append(newl)
        return tuple(ret)

    def _elements(self, xml):
        return [n for n in xml.childNodes if n.nodeType == n.ELEMENT_NODE]

    def Save(self, filename):
        # write the tables to disk
        impl = xml.dom.minidom.getDOMImplementation()
        doc = impl.createDocument(None, 'components', None)
        # look at each table that is displayed
        for name in self._tableNames:
            table = self._tables[name]
            # make the xml elements and add them to doc
            table.createElements(doc, name)
        doc.documentElement.setAttribute('arch', self.architecture)
        text = doc.toprettyxml()
        open(filename, 'w').write(text)
        self.setStored()

    def getTable(self, name):
        # return the table
        table = self._tables[name]
        self.stack.setActiveStack(table.stack)
        return table

    def allTableNames(self):
        return sorted(self._tables.keys())

    def setTableNames(self, names):
        self._tableNames = names

    def getTableNames(self):
        return self._tableNames

    def getArch(self):
        return self.architecture

    def setArch(self, arch):
        self.architecture = arch
Esempio n. 4
0
class Store(object):
    def __init__(self, debug = False, DbOnly = False, doc = False,
            arch = 'vxWorks-ppc604_long'):
        # This is a default architecture
        self.architecture = arch
        self.simarch = False
        self.epics_base = None
        self.build_root = '.'
        self.iocname = 'example'
        # This the group of undo stacks for each table
        self.stack = QUndoGroup()
        # this is a dict of tables
        self._tables = {}
        self._tableNames = []
        # store the debug state
        self.debug = debug
        self.DbOnly = DbOnly
        self.doc = doc
        self.setLastModified()
        # this is the list of objects provided by this module, for documentation
        self.moduleObjects = []
        # store the arch and tableNames so we know we're clean
        self.setStored()

    def setStored(self):
        self._storedarchitecture = self.architecture
        self._stored_tableNames = self._tableNames[:]
        for table in self._tables.values():
            table.stack.setClean()

    def isClean(self):
        if self._storedarchitecture !=  self.architecture:
            return False
        if len(self._stored_tableNames) != len(self._tableNames):
            return False
        for x,y in zip(self._tableNames, self._stored_tableNames):
            if x != y:
                return False
        return True

    def lastModified(self):
        return self._lastModified

    def setLastModified(self, index1=None, index2=None):
        self._lastModified = time.time()

    def New(self, filename = ""):
        '''Create a new table list by setting up ModuleVersion calls according
        to paths in release'''
        self.iocname = os.path.basename(filename).replace('.xml','')
        if filename:
            self.build_root = os.path.dirname(os.path.abspath(filename))        
        else:
            self.build_root = os.getcwd()
        if self.debug:
            print "IOC name: %s" % self.iocname
            print "Build root: %s" % self.build_root
        # First clear up the undo stack
        for stack in self.stack.stacks():
            self.stack.removeStack(stack)
        # then clear the table list
        self._tables.clear()
        # then clear the display list
        self._tableNames = []
        self._stored_tableNames = []
        # Now make sure there is no iocbuilder hanging around
        for k in [ k for k in sys.modules if k.startswith('iocbuilder') ]:
            del sys.modules[k]
        if 'iocbuilder' in globals():
            del(iocbuilder)
        # now do the import and configure of iocbuilder
        import iocbuilder
        if self.debug:
            print '# Creating IOC with Architecture %s' % (self.architecture)
            if self.simarch:
                print '# Simulation mode'
        self.iocbuilder = iocbuilder
        self.ioc_writer = None
        if self.DbOnly:
            self.ioc_writer = iocbuilder.iocwriter.DbOnlyWriter
        elif self.doc:
            self.ioc_writer = iocbuilder.iocwriter.DocumentationIocWriter
        # do the moduleversion calls
        from dls_dependency_tree import dependency_tree
        vs = self.iocbuilder.ParseAndConfigure(self, dependency_tree)
        # create AutoSubstitutions and moduleObjects
        for v in vs:
            if self.debug:
                print 'Making auto objects from %s' % v.LibPath()
            iocbuilder.AutoSubstitution.fromModuleVersion(v)
            iocbuilder.Xml.fromModuleVersion(v)
        # create our dict of classes
        classes = iocbuilder.includeXml.createClassLookup()
        # now we can make our tables
        for name, o in classes.items():
            # make a table object
            table = Table(o, self)
            # add it to our internal dict of tables
            self._tables[name] = table
            # add the undo stack
            self.stack.addStack(table.stack)
            # connect its modified signal to store a timestamp
            table.connect(table, SIGNAL(
                'dataChanged(const QModelIndex &, const QModelIndex &)'),
                self.setLastModified)
        self.setStored()
        # failure if there were no callables
        self.setLastModified()


    def Open(self, filename, sim = None):
        if self.debug:
            print '--- Parsing %s ---'%filename
        # read the tables
        xml_root = xml.dom.minidom.parse(filename)
        # find the root node
        components = self._elements(xml_root)[0]
        if sim is not None:
            self.architecture = sim
            self.simarch = self.architecture
        else:
            self.architecture = str(components.attributes['arch'].value)
            self.simarch = None
        self.New(filename)
        # proccess each component in turn
        problems = []
        warnings = []
        commentText = ""
        for node in components.childNodes:
            # try to find the class of each component
            if node.nodeType == node.COMMENT_NODE:
                # If it's a comment, then mark as a comment and try to process
                # its content
                commented = True
                text = '<junk>'+node.toxml()[4:-3]+'</junk>'
                root = self._elements(xml.dom.minidom.parseString(text.replace("&dashdash;","--")))[0]
                nodes = self._elements(root)
                if len(nodes) == 0:
                    # treat this as a comment on the next node
                    commentText += str(node.nodeValue) + "\n"
            elif node.nodeType == node.ELEMENT_NODE:
                # If it's an element node, then just add this node
                commented = False
                nodes = [node]
            else:
                # Ignore whitespace
                continue
            for node in nodes:
                # find the correct table
                obname = str(node.nodeName)
                if self._tables.has_key(obname):
                    pass
                elif self._tables.has_key(obname.replace("auto_", "")):
                    node.nodeName = obname.replace("auto_", "")
                    obname = str(node.nodeName)
                else:
                    problems.append(obname)
                    continue
                table = self.getTable(obname)
                if obname not in self._tableNames:
                    self._tableNames.append(obname)
                # make a new row
                warnings += table.addNode(node, commented, commentText)
                commentText = ""
        self.setStored()
        self.setLastModified()
        return self._unique(problems, warnings)

    def _unique(self, *ls):
        # make each list in args unique, then return a tuple of them
        ret = []
        for l in ls:
            newl = []
            for x in l:
                if x not in newl:
                    newl.append(x)
            ret.append(newl)
        return tuple(ret)

    def _elements(self,xml):
        return [n for n in xml.childNodes if n.nodeType == n.ELEMENT_NODE]

    def Save(self, filename):
        # write the tables to disk
        impl = xml.dom.minidom.getDOMImplementation()
        doc = impl.createDocument(None, 'components', None)
        # look at each table that is displayed
        for name in self._tableNames:
            table = self._tables[name]
            # make the xml elements and add them to doc
            table.createElements(doc, name)
        doc.documentElement.setAttribute('arch',self.architecture)
        text = doc.toprettyxml()
        open(filename,'w').write(text)
        self.setStored()

    def getTable(self, name):
        # return the table
        table = self._tables[name]
        self.stack.setActiveStack(table.stack)
        return table

    def allTableNames(self):
        return sorted(self._tables.keys())

    def setTableNames(self, names):
        self._tableNames = names

    def getTableNames(self):
        return self._tableNames

    def getArch(self):
        return self.architecture

    def setArch(self, arch):
        self.architecture = arch
Esempio n. 5
0
    def createActions(self):
        self.undoGroup = QUndoGroup(self)
        self.undoStack = QUndoStack(self)

        self.__createUndoRedoActions()

        self.slots["File"] = FileSlots(self)
        self.slots["List"] = ListSlots(self)
        self.slots["Edit"] = EditSlots(self)
        self.slots["Item"] = ItemSlots(self)
        self.slots["Server"] = ServerSlots(self)
        self.slots["Help"] = HelpSlots(self)
        self.slots["Windows"] = WindowsSlots(self)

        for sl in self.slots.values():
            self.__setActions(sl)
            self.__setTasks(sl)

        self.slots["Windows"].updateWindowMenu()

        if not PYTANGO_AVAILABLE:
            self.ui.actionConnectServer.setDisabled(True)
        self.disableServer(True)

        viewCompDockAction = self.ui.compDockWidget.toggleViewAction()
        viewCompDockAction.setToolTip("Show/Hide the dock lists")
        viewCompDockAction.setStatusTip("Show/Hide the dock lists")

        viewLogDockAction = self.ui.logDockWidget.toggleViewAction()
        viewLogDockAction.setToolTip("Show/Hide the logger")
        viewLogDockAction.setStatusTip("Show/Hide the logger")

        self.ui.menuView.insertAction(self.ui.menuView.actions()[0],
                                      viewLogDockAction)

        self.ui.menuView.insertAction(self.ui.menuView.actions()[0],
                                      viewCompDockAction)

        self.__setAction(self.ui.actionAllAttributesView,
                         "&All Attributes",
                         self.viewAllAttributes,
                         "",
                         tip="Go to the component list",
                         checkable=True)

        # Signals
        self.connect(self.componentList.ui.elementListWidget,
                     SIGNAL("itemDoubleClicked(QListWidgetItem*)"),
                     self.slots["Edit"].componentEdit)

        self.connect(self.sourceList.ui.elementListWidget,
                     SIGNAL("itemDoubleClicked(QListWidgetItem*)"),
                     self.slots["Edit"].dsourceEdit)

        ## Component context menu
        self.ui.mdi.setContextMenuPolicy(Qt.ActionsContextMenu)
        self.contextMenuActions = (
            self.ui.actionNewGroupItem, self.ui.actionNewFieldItem,
            self.ui.actionNewDataSourceItem, self.ui.actionNewStrategyItem,
            self.ui.actionNewAttributeItem, self.ui.actionNewLinkItem, None,
            self.ui.actionLoadSubComponentItem,
            self.ui.actionLoadDataSourceItem, None,
            self.ui.actionAddDataSourceItem, self.ui.actionLinkDataSourceItem,
            None, self.ui.actionCutItem, self.ui.actionCopyItem,
            self.ui.actionPasteItem, self.ui.actionTakeDataSourceItem, None,
            self.ui.actionMoveUpComponentItem,
            self.ui.actionMoveDownComponentItem, None,
            self.ui.actionApplyComponentItem, None,
            self.ui.actionClearComponentItems)

        ## Component list menu
        self.componentListMenuActions = (
            self.ui.actionNew, self.ui.actionEditComponent,
            self.ui.actionMergeComponentItems, self.ui.actionClose, None, {
                "File":
                (self.ui.actionLoad, self.ui.actionSave, self.ui.actionSaveAs,
                 self.ui.actionSaveAll, self.ui.actionReloadList,
                 self.ui.actionChangeDirectory)
            }, None, {
                "Server": (self.ui.actionFetchComponentsServer,
                           self.ui.actionStoreComponentServer,
                           self.ui.actionStoreAllComponentsServer,
                           self.ui.actionDeleteComponentServer,
                           self.ui.actionGetMandatoryComponentsServer,
                           self.ui.actionSetComponentMandatoryServer,
                           self.ui.actionUnsetComponentMandatoryServer)
            }, None, self.ui.actionTakeDataSources)

        ## DataSource list menu
        self.dsourceListMenuActions = (
            self.ui.actionNewDataSource, self.ui.actionEditDataSource,
            self.ui.actionApplyDataSource, self.ui.actionCloseDataSource, None,
            self.ui.actionCopyDataSource, self.ui.actionCutDataSource,
            self.ui.actionPasteDataSource, None, {
                "File":
                (self.ui.actionLoadDataSource, self.ui.actionSaveDataSource,
                 self.ui.actionSaveDataSourceAs,
                 self.ui.actionSaveAllDataSources,
                 self.ui.actionReloadDataSourceList,
                 self.ui.actionChangeDataSourceDirectory)
            }, None, {
                "Server": (self.ui.actionFetchDataSourcesServer,
                           self.ui.actionStoreDataSourceServer,
                           self.ui.actionStoreAllDataSourcesServer,
                           self.ui.actionDeleteDataSourceServer)
            })

        # datasource widget actions
        self.externalDSActions = {
            "externalSave": self.slots["File"].dsourceSaveButton,
            "externalApply": self.slots["Edit"].dsourceApplyButton,
            "externalClose": self.slots["Windows"].dsourceClose,
            "externalStore": self.slots["Server"].serverStoreDataSourceButton
        }

        # component widget actions
        self.externalCPActions = {
            "externalSave": self.slots["File"].componentSaveButton,
            "externalStore": self.slots["Server"].serverStoreComponentButton,
            "externalApply": self.slots["Item"].componentApplyItemButton,
            "externalClose": self.slots["Windows"].componentClose,
            "externalDSLink":
            self.slots["Item"].componentLinkDataSourceItemButton
        }