Exemplo n.º 1
0
 def changeIdentifier(self, old_identifier, new_identifier):
     old_config = get_configuration_file(self._location, old_identifier)
     new_config = get_configuration_file(self._location, new_identifier)
     try:
         os.rename(old_config, new_config)
     except OSError:
         pass
Exemplo n.º 2
0
    def saveState(self, ws):
        connectionMap = {}
        stepList = []
        for item in self._items:
            if item.Type == MetaStep.Type:
                stepList.append(item)
            elif item.Type == Connection.Type:
                if item.source() in connectionMap:
                    connectionMap[item.source()].append(item)
                else:
                    connectionMap[item.source()] = [item]

        location = self._manager.location()
        ws.beginGroup('view')
        for key in self._view_parameters:
            ws.setValue(key, self._view_parameters[key])
        ws.endGroup()

        ws.remove('nodes')
        ws.beginGroup('nodes')
        ws.beginWriteArray('nodelist')
        nodeIndex = 0
        for metastep in stepList:
            if metastep.hasIdentifierChanged():
                if metastep.getIdentifier() and metastep.getStepIdentifier():
                    self._manager.changeIdentifier(metastep.getIdentifier(), metastep.getStepIdentifier())
                metastep.syncIdentifier()

            identifier = metastep.getIdentifier() or metastep.getUniqueIdentifier()
            step = metastep.getStep()
            step_config = step.serialize()
            if step_config:
                with open(get_configuration_file(location, identifier), 'w') as f:
                    f.write(step_config)
            ws.setArrayIndex(nodeIndex)
            source_uri = step.getSourceURI()
            if source_uri is not None:
                ws.setValue('source_uri', source_uri)
            ws.setValue('name', step.getName())
            ws.setValue('position', metastep.getPos())
            ws.setValue('selected', metastep.getSelected())
            ws.setValue('identifier', identifier)
            ws.setValue('unique_identifier', metastep.getUniqueIdentifier())
            ws.beginWriteArray('connections')
            connectionIndex = 0
            if metastep in connectionMap:
                for connectionItem in connectionMap[metastep]:
                    ws.setArrayIndex(connectionIndex)
                    ws.setValue('connectedFromIndex', connectionItem.sourceIndex())
                    ws.setValue('connectedTo', stepList.index(connectionItem.destination()))
                    ws.setValue('connectedToIndex', connectionItem.destinationIndex())
                    ws.setValue('selected', connectionItem.getSelected())
                    connectionIndex += 1
            ws.endArray()
            nodeIndex += 1
        ws.endArray()
        ws.endGroup()
Exemplo n.º 3
0
def loadConfiguration(location, identifier):
    filename = get_configuration_file(location, identifier)
    configuration = '{}'
    try:
        with open(filename) as f:
            configuration = f.read()
    except Exception:
        pass
    return configuration