コード例 #1
0
ファイル: config.py プロジェクト: josegutab/scipion
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)
コード例 #2
0
ファイル: config.py プロジェクト: liz18/scipion
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
コード例 #3
0
ファイル: config.py プロジェクト: kevinpetersavage/scipion
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)