コード例 #1
0
def dumpButlerConfig(root, searchPath=None, subset=None, outfh=sys.stdout):
    """Dump a config or subset to the specified file handle.

    Parameters
    ----------
    root : `str`
        Location of butler configuration.  Can be a path to a YAML
        file or a directory containing the configuration file.
    searchPath : `list` of `str`
        Directory paths for resolving the locations of configuration
        file lookups.
    subset : `str` or `tuple` of `str`
        Key into a subset of the configuration. If a string it should use
        the standard notation of supplying the relevant delimiter in the
        first character.
    outfh
        File descriptor to use to write the configuration content.
    """

    config = ButlerConfig(root, searchPaths=searchPath)

    if subset is not None:
        config = config[subset]

    try:
        config.dump(outfh)
    except AttributeError:
        print(config, file=outfh)
コード例 #2
0
    def testSearchPath(self):
        configFile = os.path.join(TESTDIR, "config", "basic", "butler.yaml")
        with self.assertLogs("lsst.daf.butler", level="DEBUG") as cm:
            config1 = ButlerConfig(configFile)
        self.assertNotIn("testConfigs", "\n".join(cm.output))

        overrideDirectory = os.path.join(TESTDIR, "config", "testConfigs")
        with self.assertLogs("lsst.daf.butler", level="DEBUG") as cm:
            config2 = ButlerConfig(configFile, searchPaths=[overrideDirectory])
        self.assertIn("testConfigs", "\n".join(cm.output))

        key = ("datastore", "records", "table")
        self.assertNotEqual(config1[key], config2[key])
        self.assertEqual(config2[key], "override_record")
コード例 #3
0
    def test_register(self):
        """Test that register() sets appropriate Dimensions.
        """
        registryConfigPath = os.path.join(getPackageDir("daf_butler"),
                                          "tests/config/basic/butler.yaml")
        registry = Registry.fromConfig(ButlerConfig(registryConfigPath))
        # check that the registry starts out empty
        self.assertEqual(list(registry.queryDimensions(["instrument"])), [])
        self.assertEqual(list(registry.queryDimensions(["detector"])), [])
        self.assertEqual(list(registry.queryDimensions(["physical_filter"])),
                         [])

        # register the instrument and check that certain dimensions appear
        self.instrument.register(registry)
        instrumentDataIds = list(registry.queryDimensions(["instrument"]))
        self.assertEqual(len(instrumentDataIds), 1)
        instrumentNames = {
            dataId["instrument"]
            for dataId in instrumentDataIds
        }
        self.assertEqual(instrumentNames, {self.data.name})
        detectorDataIds = list(registry.queryDimensions(["detector"]))
        self.assertEqual(len(detectorDataIds), self.data.nDetectors)
        detectorNames = {
            dataId.records["detector"].full_name
            for dataId in detectorDataIds
        }
        self.assertIn(self.data.firstDetectorName, detectorNames)
        physicalFilterDataIds = list(
            registry.queryDimensions(["physical_filter"]))
        filterNames = {
            dataId['physical_filter']
            for dataId in physicalFilterDataIds
        }
        self.assertGreaterEqual(filterNames, self.data.physical_filters)
コード例 #4
0
    def makeButler(self, **kwargs: Any) -> Butler:
        """Return new Butler instance on each call.
        """
        config = ButlerConfig()

        # make separate temporary directory for registry of this instance
        tmpdir = tempfile.mkdtemp(dir=self.root)
        config["registry", "db"] = f"sqlite:///{tmpdir}/gen3.sqlite3"
        config["root"] = self.root

        # have to make a registry first
        registryConfig = RegistryConfig(config.get("registry"))
        Registry.createFromConfig(registryConfig)

        butler = Butler(config, **kwargs)
        DatastoreMock.apply(butler)
        return butler
コード例 #5
0
ファイル: gen3.py プロジェクト: provingground-moe/ci_hsc
    def __init__(self, config=None, root=REPO_ROOT):

        self.root = root
        if config is None:
            config = self.root
        self.butlerConfig = ButlerConfig(config, searchPaths=searchPaths)
        StorageClassFactory().addFromConfig(self.butlerConfig)

        # Force the configuration directory to refer to the ci_hsc root
        self.butlerConfig.configDir = self.root
コード例 #6
0
    def test_register(self):
        """Test that register() sets appropriate Dimensions.
        """
        registryConfigPath = os.path.join(getPackageDir("daf_butler"),
                                          "tests/config/basic/butler.yaml")
        registry = Registry.fromConfig(ButlerConfig(registryConfigPath))
        # check that the registry starts out empty
        self.assertEqual(registry.findDimensionEntries('instrument'), [])
        self.assertEqual(registry.findDimensionEntries('detector'), [])
        self.assertEqual(registry.findDimensionEntries('physical_filter'), [])

        # register the instrument and check that certain dimensions appear
        self.instrument.register(registry)
        self.assertEqual(len(registry.findDimensionEntries('instrument')), 1)
        self.assertEqual(
            registry.findDimensionEntries('instrument')[0]['instrument'],
            self.data.name)
        self.assertEqual(len(registry.findDimensionEntries('detector')),
                         self.data.nDetectors)
        filterNames = {
            x['physical_filter']
            for x in registry.findDimensionEntries('physical_filter')
        }
        self.assertGreaterEqual(filterNames, self.data.physical_filters)
コード例 #7
0
        default=None,
        type=str,
        help="Subset of a configuration to report. This can be any key in the"
        " hierarchy such as '.datastore.root' where the leading '.' specified"
        " the delimiter for the hierarchy.")
    parser.add_argument(
        "--searchpath",
        "-p",
        action="append",
        type=str,
        help="Additional search paths to use for configuration overrides")
    parser.add_argument("--verbose",
                        "-v",
                        action="store_true",
                        help="Turn on debug reporting.")

    args = parser.parse_args()

    if args.verbose:
        logging.basicConfig(level=logging.DEBUG)

    config = ButlerConfig(args.root, searchPaths=args.searchpath)

    if args.subset is not None:
        config = config[args.subset]

    try:
        config.dump(sys.stdout)
    except AttributeError:
        print(config)
コード例 #8
0
 def makeRegistry(self):
     testDir = os.path.dirname(__file__)
     configFile = os.path.join(testDir, "config/basic/butler.yaml")
     butlerConfig = ButlerConfig(configFile)
     butlerConfig["registry", "limited"] = True
     return Registry.fromConfig(butlerConfig, create=True)
コード例 #9
0
 def setUp(self):
     self.testDir = os.path.dirname(__file__)
     self.configFile = os.path.join(self.testDir, "config/basic/butler.yaml")
     self.butlerConfig = ButlerConfig(self.configFile)
     self.registry = Registry.fromConfig(self.butlerConfig)