当前位置: 首页>>代码示例>>Python>>正文


Python Policy.exists方法代码示例

本文整理汇总了Python中lsst.pex.policy.Policy.exists方法的典型用法代码示例。如果您正苦于以下问题:Python Policy.exists方法的具体用法?Python Policy.exists怎么用?Python Policy.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lsst.pex.policy.Policy的用法示例。


在下文中一共展示了Policy.exists方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testSetNothing

# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import exists [as 别名]
 def testSetNothing(self):
     p = Policy()
     try:
         p.set("foo", None)
         self.assert_(False, "Setting value to None succeeded.")
     except RuntimeError:
         self.assertFalse(p.exists("foo"))
开发者ID:lsst-dm,项目名称:bp,代码行数:9,代码来源:Policy_1.py

示例2: _DataReadyComp

# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import exists [as 别名]
class _DataReadyComp(object):

    def setup(self, policyDict="DataReady_dict.paf"):
        deffile = DefaultPolicyFile("ctrl_sched", policyDict, "policies")
        defpol = Policy.createPolicy(deffile, deffile.getRepositoryPath())

        if not hasattr(self,"policy") or not self.policy:
            self.policy = Policy()
        self.policy.mergeDefaults(defpol.getDictionary())

#        self.mode = self.policy.getString("mode")
#        if self.mode not in "parallel serial":
#            raise RuntimeError("Stage %s: Unsupported mode: %s" %
#                               (self.getName(), self.mode))

        self.clipboardKeys = {}
        self.clipboardKeys["completedDatasets"] = \
           self.policy.getString("inputKeys.completedDatasets")
        self.clipboardKeys["possibleDatasets"] = \
           self.policy.getString("inputKeys.possibleDatasets")

        self.dataclients = []
        clpols = []
        if self.policy.exists("datasets"):
            clpols = self.policy.getPolicyArray("datasets")
        for pol in clpols:
            dstype = None
            if pol.exists("datasetType"):
                dstype = pol.getString("datasetType")
            topic = pol.getString("dataReadyEvent")
            reportAll = pol.getBool("reportAllPossible")
            client = DataReadyClient(self.getRun(), self.getName(), topic,
                                     self.getEventBrokerHost(), dstype,
                                     reportAll)
            self.dataclients.append(client)
        

    def tellDataReady(self, clipboard):
        """
        send an event reporting on the output datasets that have been
        attempted by this pipeline.
        @param clipboard     the pipeline clipboard containing the output
                               datasets
        """
        completed = clipboard.get(self.clipboardKeys["completedDatasets"])
        possible = clipboard.get(self.clipboardKeys["possibleDatasets"])

        for client in self.dataclients:
            if not possible:
                break
            self.log.log(Log.DEBUG, "completed: " + str(completed))
            possible = client.tellDataReady(possible, completed)

        # update the possible list for the ones we have not reported
        # on yet.
        clipboard.put(self.clipboardKeys["possibleDatasets"], possible)
开发者ID:jonathansick-shadow,项目名称:ctrl_sched,代码行数:58,代码来源:pipeline.py

示例3: testPolicySetget

# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import exists [as 别名]
    def testPolicySetget(self):
        p = Policy()
        self.assert_(not p.exists("foo"), "empty existence test failed")
        self.assertEqual(p.valueCount("foo.bar"), 0,
                         "empty valueCount test failed")

        self.assertRaises(NameNotFound, p.getTypeInfo, "foo")

        p.set("doall", "true")

        # non-existence tests on a non-empty policy
        self.failUnless(not p.exists("foo"),
                        "non-empty non-existence test failed")
        self.assertEqual(p.valueCount("foo.bar"), 0,
                         "empty valueCount test failed")
        self.failUnless(not p.isInt("foo"),
                        "non-empty non-existence type test failed")
        self.assertRaises(NameNotFound, p.getTypeInfo, "foo")

        # existence tests
        self.assert_(p.exists("doall"), "non-empty existence test failed")
        self.assertEquals(p.valueCount("doall"), 1,
                          "single valueCount test failed")

        self.assertRaises(Exception, p.getInt, "doall")
        self.assertRaises(Exception, p.getDoubleArray, "doall")

        self.assertEquals(p.get("doall"), "true",
                          "top-level getString failed")
        p.set("doall", "duh")
        self.assertEquals(p.get("doall"), "duh",
                          "top-level getString failed")
        
        # test array access
        ary = p.getArray("doall")
        self.assertEquals(len(ary), 1,
                          "scalar property has more than one value")


        self.assertEquals(ary[0], "duh", "scalar access via array failed")

        p.add("doall", "never")
        self.assertEquals(p.valueCount("doall"), 2,
                          "2-elem. valueCount test failed")
        self.assertEquals(p.get("doall"), "never", "top-level add failed")
        ary = p.getArray("doall")
        self.assertEquals(len(ary), 2,
                          "scalar property has wrong number of values")
        self.assertEquals(ary[0], "duh",
                          "scalar access via (2-el) array failed")
        self.assertEquals(ary[-1], "never",
                          "scalar access via (2-el) array failed")

        # test hierarchical access

        # list names

        # test types
        p.set("pint", 5)
        self.assertEquals(p.getInt("pint"), 5, "support for type int failed")
        self.assertEquals(type(p.get("pint")), type(5),
                          "auto-typing for int failed")
        p.set("pdbl", 5.1)
        self.assertAlmostEquals(p.getDouble("pdbl"), 5.1, 7, 
                                "support for type double failed")
        self.assertEquals(type(p.get("pdbl")), type(5.1),
                          "auto-typing for double failed")
        p.set("pbool", True)
        self.assert_(p.getBool("pbool"), "support for type bool failed")
        self.assertEquals(type(p.get("pbool")), type(True),
                          "auto-typing for bool failed")
        p.add("pbool", False)

        # test shallow & deep copies

        # test raise NameNotFound if not present
        try:
            p.get("nonexistent")
            self.fail() # should never reach here
        except Exception, e:
            self.assert_(isinstance(e, NameNotFound))
开发者ID:lsst-dm,项目名称:bp,代码行数:83,代码来源:Policy_1.py

示例4: PolicyBlackboardItem

# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import exists [as 别名]
class PolicyBlackboardItem(BlackboardItem):
    """
    An implementation of a BlackboardItem that stores properities via a
    policy
    """

    def __init__(self, policyfile=None):
        """
        create an item with the given properties.
        @param policyfile    A policy
        """
        # the properties attached to this items
        self._props = None
        if policyfile:
            self._props = Policy.createPolicy(policyfile)
        else:
            self._props = Policy()

    def getProperty(self, name, default=None):
        """
        return the value for a property
        @param name      the property name
        @parma default   the default value to return if the name is not set
        """
        if not self._props.exists(name):
            return default
        elif self._props.isArray(name):
            return self._props.getArray(name)
        else:
            return self._props.get(name)

    def hasProperty(self, name):
        """
        return True if the property with the given name is available
        """
        return self._props.exists(name)

    def __getitem__(self, name):
        if not self._props.exists(name):
            raise KeyError(name)
        return BlackboardItem.__getitem__(self, name)

    def _setProperty(self, name, val):
        # set a property value
        if isinstance(val, list):
            self._props.set(name, val.pop(0))
            for v in val:
                self._props.add(name, v)
        else:
            self._props.set(name, val)

    def getPropertyNames(self):
        """
        return the property names that make up this item
        """
        return self._props.names()

    def _copyFrom(self, item):
        for name in item.getPropertyNames():
            self._setProperty(name, item.getProperty(name))

    @staticmethod
    def createFormatter():
        return PolicyBlackboardItem._Fmtr()

    class _Fmtr(object):
        def write(self, filename, item):
            pol = None
            if isinstance(item, PolicyBlackboardItem):
                pol = item._props
            else:
                delegate = PolicyBlackboardItem()
                delegate._copyFrom(item)
                pol = delegate._props

            writer = PAFWriter(filename)
            try:
                writer.write(pol, True)
            finally:
                writer.close()

        def openItem(self, filename):
            out = PolicyBlackboardItem()
            out._props = Policy.createPolicy(filename)
            return out

        def filenameExt(self):
            """
            return the recommended extension for the format this writes out
            """
            return "paf"
开发者ID:jonathansick-shadow,项目名称:ctrl_sched,代码行数:93,代码来源:item.py


注:本文中的lsst.pex.policy.Policy.exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。