Beispiel #1
0
    def write(self, dbPath=None):
        self.setName('ProjectSettings')
        if dbPath is not None:
            self.mapper = SqliteMapper(dbPath, globals())
        else:
            if self.mapper is None:
                raise Exception("Can't write ProjectSettings without mapper or dbPath")

        self.mapper.deleteAll()
        self.mapper.insert(self)
        self.mapper.commit()
Beispiel #2
0
 def createMapper(self, sqliteFn):
     """ Create a new SqliteMapper object and pass as classes dict
     all globas and update with data and protocols from em.
     """
     classesDict = dict(pwobj.__dict__)
     classesDict.update(em.getProtocols())
     classesDict.update(em.getObjects())
     mapper = SqliteMapper(sqliteFn, classesDict)
     if not self.chdir:
         mapper.setWorkingDir(self.path)
     return mapper
 def test_StepExecutor(self):
     """Test the list with several Complex"""
     fn = self.getOutputPath("protocol.sqlite")   
     mapper = SqliteMapper(fn, globals())
     prot = MyProtocol(mapper=mapper, n=2, workingDir=self.getOutputPath(''))
     prot._stepsExecutor = StepExecutor(hostConfig=None)
     prot.run()
     
     self.assertEqual(prot._steps[0].getStatus(), STATUS_FINISHED)
     
     mapper2 = SqliteMapper(fn, globals())
     prot2 = mapper2.selectById(prot.getObjId())
     
     self.assertEqual(prot.endTime.get(), prot2.endTime.get())
Beispiel #4
0
def saveConfig(filename):
    from pyworkflow.mapper import SqliteMapper
    from pyworkflow.object import String, Integer
    
    mapper = SqliteMapper(filename)
    o = Config()
    for k, v in globals().iteritems():
        if k.startswith('cfg'):
            if type(v) is str:
                value = String(v)
            else: 
                value = Integer(v)
            setattr(o, k, value)
    mapper.insert(o)
    mapper.commit()
Beispiel #5
0
    def test_StepExecutor(self):
        """Test the list with several Complex"""
        fn = self.getOutputPath("protocol.sqlite")
        mapper = SqliteMapper(fn, globals())
        prot = MyProtocol(mapper=mapper,
                          n=2,
                          workingDir=self.getOutputPath(''))
        prot._stepsExecutor = StepExecutor(hostConfig=None)
        prot.run()

        self.assertEqual(prot._steps[0].getStatus(), STATUS_FINISHED)

        mapper2 = SqliteMapper(fn, globals())
        prot2 = mapper2.selectById(prot.getObjId())

        self.assertEqual(prot.endTime.get(), prot2.endTime.get())
Beispiel #6
0
def loadSettings(dbPath):
    """ Load a ProjectSettings from dbPath. """
    classDict = dict(globals())
    classDict.update(pwobj.__dict__)
    mapper = SqliteMapper(dbPath, classDict)
    settingList = mapper.selectByClass('ProjectSettings')
    n = len(settingList)

    if n == 0:
        raise Exception("Can't load ProjectSettings from %s" % dbPath)
    elif n > 1:
        raise Exception("Only one ProjectSettings is expected in db, found %d in %s" % (n, dbPath))

    settings = settingList[0]
    settings.mapper = mapper

    return settings
Beispiel #7
0
def loadSettings(dbPath):
    """ Load a ProjectSettings from dbPath. """
    classDict = dict(globals())
    classDict.update(pwobj.__dict__)
    mapper = SqliteMapper(dbPath, classDict)
    settingList = mapper.selectByClass('ProjectSettings')
    n = len(settingList)

    if n == 0:
        raise Exception("Can't load ProjectSettings from %s" % dbPath)
    elif n > 1:
        raise Exception("Only one ProjectSettings is expected in db, found %d in %s" % (n, dbPath))

    settings = settingList[0]
    settings.mapper = mapper

    return settings
Beispiel #8
0
class DbTreeProvider(ObjectTreeProvider):
    """Retrieve the elements from the database"""
    def __init__(self, dbName, classesDict):
        ObjectTreeProvider.__init__(self)
        self.mapper = SqliteMapper(dbName, classesDict)

    def _getObjectList(self):
        return self.mapper.selectAll()
Beispiel #9
0
class DbTreeProvider(ObjectTreeProvider):
    """Retrieve the elements from the database"""
    def __init__(self, dbName, classesDict):
        ObjectTreeProvider.__init__(self)
        self.mapper = SqliteMapper(dbName, classesDict)
    
    def _getObjectList(self):
        return self.mapper.selectAll()
Beispiel #10
0
 def createMapper(self, sqliteFn):
     """ Create a new SqliteMapper object and pass as classes dict
     all globas and update with data and protocols from em.
     """
     classesDict = pwobj.Dict(default=pwprot.LegacyProtocol)
     classesDict.update(pwobj.__dict__)
     classesDict.update(em.getProtocols())
     classesDict.update(em.getObjects())
     return SqliteMapper(sqliteFn, classesDict)
Beispiel #11
0
 def createMapper(self, sqliteFn):
     """ Create a new SqliteMapper object and pass as classes dict
     all globas and update with data and protocols from em.
     """
     #TODO: REMOVE THE USE OF globals() here
     classesDict = dict(pwobj.__dict__)
     classesDict.update(em.getProtocols())
     classesDict.update(em.getObjects())
     return SqliteMapper(sqliteFn, classesDict)
Beispiel #12
0
    def write(self, dbPath=None):
        self.setName('ProjectSettings')
        if dbPath is not None:
            self.mapper = SqliteMapper(dbPath, globals())
        else:
            if self.mapper is None:
                raise Exception("Can't write ProjectSettings without mapper or dbPath")

        self.mapper.deleteAll()
        self.mapper.insert(self)
        self.mapper.commit()
Beispiel #13
0
    def test_basicObjectOutput(self):
        """Test the list with several Complex"""
        fn = self.getOutputPath("protocol.sqlite")
        mapper = SqliteMapper(fn, globals())
        prot = ProtOutputTest(mapper=mapper,
                              n=2,
                              workingDir=self.getOutputPath(''))

        # Add and old style output, not in the outputs dictionary
        prot.output1 = EMObject()

        self.assertFalse(prot._useOutputList.get(),
                         "useOutputList wrongly initialized")

        outputs = [output for output in prot.iterOutputAttributes()]
        self.assertTrue(1, len(outputs))

        prot._stepsExecutor = StepExecutor(hostConfig=None)
        prot.run()

        self.assertEqual(prot._steps[0].getStatus(), STATUS_FINISHED)

        # Check there is an output
        self.assertOutput(prot)

        outputs = [output for output in prot.iterOutputAttributes()]

        # We are intentionally ignoring a protocol with output (EMObject)
        # That has been continued, We do not find a real case now.
        self.assertEqual(1,
                         len(outputs),
                         msg="Integer output not registered properly.")

        outputs = [output for output in prot.iterOutputAttributes(Integer)]

        # Test passing a filter
        self.assertEqual(1,
                         len(outputs),
                         msg="Integer not matched when filtering outputs.")
        # Test with non existing class
        outputs = [output for output in prot.iterOutputAttributes(DataSet)]

        # Test passing a class
        self.assertEqual(0,
                         len(outputs),
                         msg="Filter by class in iterOutputAttributes does "
                         "not work.")

        self.assertTrue(prot._useOutputList.get(),
                        "useOutputList not activated")
Beispiel #14
0
def saveConfig(filename):
    from pyworkflow.mapper import SqliteMapper
    from pyworkflow.object import String, Integer

    mapper = SqliteMapper(filename)
    o = Config()
    for k, v in globals().iteritems():
        if k.startswith('cfg'):
            if type(v) is str:
                value = String(v)
            else:
                value = Integer(v)
            setattr(o, k, value)
    mapper.insert(o)
    mapper.commit()
Beispiel #15
0
 def __init__(self, filename, dictClasses=None):
     if dictClasses is None:
         dictClasses = globals()
     SqliteMapper.__init__(self, filename, dictClasses)
Beispiel #16
0
class ProjectSettings(pwobj.OrderedObject):
    """ Store settings related to a project. """

    COLOR_MODE_STATUS = 0
    COLOR_MODE_LABELS = 1
    COLOR_MODE_AGE = 2
    COLOR_MODES = (COLOR_MODE_STATUS, COLOR_MODE_LABELS, COLOR_MODE_AGE)

    def __init__(self, confs={}, **kwargs):
        pwobj.OrderedObject.__init__(self, **kwargs)
        self.config = ProjectConfig()
        # Store the current view selected by the user
        self.currentProtocolsView = pwobj.String()
        # Store the color mode: 0= Status, 1=Labels, ...
        self.colorMode = pwobj.Integer(ProjectSettings.COLOR_MODE_STATUS)
        self.nodeList = NodeConfigList(
        )  # Store graph nodes positions and other info
        self.labelsList = LabelsList()  # Label list
        self.mapper = None  # This should be set when load, or write
        self.runsView = pwobj.Integer(1)  # by default the graph view
        self.readOnly = pwobj.Boolean(False)
        self.runSelection = pwobj.CsvList(int)  # Store selected runs
        self.dataSelection = pwobj.CsvList(int)  # Store selected runs
        # Some extra settings stored, now mainly used
        # from the webtools
        # Time when the project was created
        self.creationTime = pwobj.String(dt.datetime.now())
        # Number of days that this project is active
        # if None, the project will not expire
        # This is used in webtools where a limited time
        # is allowed for each project
        self.lifeTime = pwobj.Integer()
        # Set a disk quota for the project (in Gb)
        # if None, quota is unlimited
        self.diskQuota = pwobj.Integer()

    def commit(self):
        """ Commit changes made. """
        self.mapper.commit()

    def getRunsView(self):
        return self.runsView.get()

    def setRunsView(self, value):
        self.runsView.set(value)

    def getReadOnly(self):
        return self.readOnly.get()

    def setReadOnly(self, value):
        self.readOnly.set(value)

    def getCreationTime(self):
        return self.creationTime.datetime()

    def setCreationTime(self, value):
        self.creationTime.set(value)

    def getLifeTime(self):
        return self.lifeTime.get()

    def setLifeTime(self, value):
        self.lifeTime.set(value)

    def getConfig(self):
        return self.config

    def getProtocolView(self):
        return self.currentProtocolsView.get()

    def setProtocolView(self, protocolView):
        """ Set the new protocol Menu given its index.
        The new ProtocolMenu will be returned.
        """
        self.currentProtocolsView.set(protocolView)

    def getColorMode(self):
        return self.colorMode.get()

    def setColorMode(self, colorMode):
        """ Set the color mode to use when drawing the graph.
        """
        self.colorMode.set(colorMode)

    def statusColorMode(self):
        return self.getColorMode() == self.COLOR_MODE_STATUS

    def labelsColorMode(self):
        return self.getColorMode() == self.COLOR_MODE_LABELS

    def ageColorMode(self):
        return self.getColorMode() == self.COLOR_MODE_AGE

    def write(self, dbPath=None):
        self.setName('ProjectSettings')
        if dbPath is not None:
            self.mapper = SqliteMapper(dbPath, globals())
        else:
            if self.mapper is None:
                raise Exception(
                    "Can't write ProjectSettings without mapper or dbPath")

        self.mapper.deleteAll()
        self.mapper.insert(self)
        self.mapper.commit()

    def getNodes(self):
        return self.nodeList

    def getNodeById(self, nodeId):
        return self.nodeList.getNode(nodeId)

    def addNode(self, nodeId, **kwargs):
        return self.nodeList.addNode(nodeId, **kwargs)

    def getLabels(self):
        return self.labelsList

    @classmethod
    def load(cls, dbPath):
        """ Load a ProjectSettings from dbPath. """
        classDict = dict(globals())
        classDict.update(pwobj.__dict__)
        mapper = SqliteMapper(dbPath, classDict)
        settingList = mapper.selectByClass('ProjectSettings')
        n = len(settingList)

        if n == 0:
            raise Exception("Can't load ProjectSettings from %s" % dbPath)
        elif n > 1:
            raise Exception(
                "Only one ProjectSettings is expected in db, found %d in %s" %
                (n, dbPath))

        settings = settingList[0]
        settings.mapper = mapper

        return settings
Beispiel #17
0
 def __init__(self, dbName, classesDict):
     ObjectTreeProvider.__init__(self)
     self.mapper = SqliteMapper(dbName, classesDict)
Beispiel #18
0
 def __init__(self, dbName, classesDict):
     ObjectTreeProvider.__init__(self)
     self.mapper = SqliteMapper(dbName, classesDict)
Beispiel #19
0
class ProjectSettings(pwobj.OrderedObject):
    """ Store settings related to a project. """
    def __init__(self, confs={}, **kwargs):
        pwobj.OrderedObject.__init__(self, **kwargs)
        self.config = ProjectConfig()
        self.currentProtocolsView = pwobj.String() # Store the current view selected by the user
        self.nodeList = NodeConfigList() # Store graph nodes positions and other info
        self.mapper = None # This should be set when load, or write
        self.runsView = pwobj.Integer(1) # by default the graph view
        self.readOnly = pwobj.Boolean(False)
        self.runSelection = pwobj.CsvList(int) # Store selected runs
        # Some extra settings stored, now mainly used
        # from the webtools
        self.creationTime = pwobj.String(dt.datetime.now()) # Time when the project was created
        # Number of days that this project is active
        # if None, the project will not expire
        # This is used in webtools where a limited time
        # is allowed for each project
        self.lifeTime = pwobj.Integer()
        # Set a disk quota for the project (in Gb)
        # if None, quota is unlimited
        self.diskQuota = pwobj.Integer()          

    def commit(self):
        """ Commit changes made. """
        self.mapper.commit()

    def getRunsView(self):
        return self.runsView.get()
    
    def setRunsView(self, value):
        self.runsView.set(value)
        
    def getReadOnly(self):
        return self.readOnly.get()
    
    def setReadOnly(self, value):
        self.readOnly.set(value)
        
    def getCreationTime(self):
        f = "%Y-%m-%d %H:%M:%S.%f"
        creationTime = self.creationTime.get()

        return dt.datetime.strptime(creationTime, f)
    
    def setCreationTime(self, value):
        self.creationTime.set(value)
        
    def getLifeTime(self):
        return self.lifeTime.get()
    
    def setLifeTime(self, value):
        self.lifeTime.set(value)

    def getConfig(self):
        return self.config

    def getProtocolView(self):
        return self.currentProtocolsView.get()

    def setProtocolView(self, protocolView):
        """ Set the new protocol Menu given its index.
        The new ProtocolMenu will be returned.
        """
        self.currentProtocolsView.set(protocolView)

    def write(self, dbPath=None):
        self.setName('ProjectSettings')
        if dbPath is not None:
            self.mapper = SqliteMapper(dbPath, globals())
        else:
            if self.mapper is None:
                raise Exception("Can't write ProjectSettings without mapper or dbPath")

        self.mapper.deleteAll()
        self.mapper.insert(self)
        self.mapper.commit()
        
    def getNodes(self):
        return self.nodeList
    
    def getNodeById(self, nodeId):
        return self.nodeList.getNode(nodeId)
    
    def addNode(self, nodeId, **kwargs):
        return self.nodeList.addNode(nodeId, **kwargs)
Beispiel #20
0
 def __init__(self, filename, dictClasses=None):
     if dictClasses is None:
         dictClasses = globals()
     SqliteMapper.__init__(self, filename, dictClasses)
Beispiel #21
0
class ProjectSettings(pwobj.OrderedObject):
    """ Store settings related to a project. """
    def __init__(self, confs={}, **kwargs):
        pwobj.OrderedObject.__init__(self, **kwargs)
        self.config = ProjectConfig()
        self.currentProtocolsView = pwobj.String() # Store the current view selected by the user
        self.nodeList = NodeConfigList() # Store graph nodes positions and other info
        self.mapper = None # This should be set when load, or write
        self.runsView = pwobj.Integer(1) # by default the graph view
        self.readOnly = pwobj.Boolean(False)
        self.runSelection = pwobj.CsvList(int) # Store selected runs
        # Some extra settings stored, now mainly used
        # from the webtools
        self.creationTime = pwobj.String(dt.datetime.now()) # Time when the project was created
        # Number of days that this project is active
        # if None, the project will not expire
        # This is used in webtools where a limited time
        # is allowed for each project
        self.lifeTime = pwobj.Integer()
        # Set a disk quota for the project (in Gb)
        # if None, quota is unlimited
        self.diskQuota = pwobj.Integer()          

    def commit(self):
        """ Commit changes made. """
        self.mapper.commit()

    def getRunsView(self):
        return self.runsView.get()
    
    def setRunsView(self, value):
        self.runsView.set(value)
        
    def getReadOnly(self):
        return self.readOnly.get()
    
    def setReadOnly(self, value):
        self.readOnly.set(value)
        
    def getCreationTime(self):
        f = "%Y-%m-%d %H:%M:%S.%f"
        creationTime = self.creationTime.get()

        return dt.datetime.strptime(creationTime, f)
    
    def setCreationTime(self, value):
        self.creationTime.set(value)
        
    def getLifeTime(self):
        return self.lifeTime.get()
    
    def setLifeTime(self, value):
        self.lifeTime.set(value)

    def getConfig(self):
        return self.config

    def getProtocolView(self):
        return self.currentProtocolsView.get()

    def setProtocolView(self, protocolView):
        """ Set the new protocol Menu given its index.
        The new ProtocolMenu will be returned.
        """
        self.currentProtocolsView.set(protocolView)

    def write(self, dbPath=None):
        self.setName('ProjectSettings')
        if dbPath is not None:
            self.mapper = SqliteMapper(dbPath, globals())
        else:
            if self.mapper is None:
                raise Exception("Can't write ProjectSettings without mapper or dbPath")

        self.mapper.deleteAll()
        self.mapper.insert(self)
        self.mapper.commit()
        
    def getNodes(self):
        return self.nodeList
    
    def getNodeById(self, nodeId):
        return self.nodeList.getNode(nodeId)
    
    def addNode(self, nodeId, **kwargs):
        return self.nodeList.addNode(nodeId, **kwargs)