Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# 

2# This file is part of ap_verify. 

3# 

4# Developed for the LSST Data Management System. 

5# This product includes software developed by the LSST Project 

6# (http://www.lsst.org). 

7# See the COPYRIGHT file at the top-level directory of this distribution 

8# for details of code ownership. 

9# 

10# This program is free software: you can redistribute it and/or modify 

11# it under the terms of the GNU General Public License as published by 

12# the Free Software Foundation, either version 3 of the License, or 

13# (at your option) any later version. 

14# 

15# This program is distributed in the hope that it will be useful, 

16# but WITHOUT ANY WARRANTY; without even the implied warranty of 

17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

18# GNU General Public License for more details. 

19# 

20# You should have received a copy of the GNU General Public License 

21# along with this program. If not, see <http://www.gnu.org/licenses/>. 

22# 

23 

24from lsst.daf.persistence import Policy 

25 

26 

27class Config: 

28 """Confuration manager for ``ap_verify``. 

29 

30 This is a singleton `lsst.daf.persistence.Policy` that may be accessed 

31 from other modules in ``ap_verify`` as needed using `Config.instance`. 

32 Please do not construct objects of this class directly. 

33 

34 Objects of this type are immutable. 

35 """ 

36 

37 def __init__(self): 

38 path = Policy.defaultPolicyFile('ap_verify', 'dataset_config.yaml', 'config') 

39 self._allInfo = Policy(path) 

40 self._validate() 

41 

42 def _validate(self): 

43 """Test that the loaded configuration is correct. 

44 

45 Raises 

46 ------ 

47 RuntimeError 

48 Raised if validation failed 

49 """ 

50 try: 

51 datasetMap = self._allInfo['datasets'] 

52 if not isinstance(datasetMap, Policy): 52 ↛ 53line 52 didn't jump to line 53, because the condition on line 52 was never true

53 raise TypeError('`datasets` is not a dictionary') 

54 except (KeyError, TypeError) as e: 

55 raise RuntimeError('Invalid config file.') from e 

56 

57 def __getitem__(self, key): 

58 return self._allInfo[key] 

59 

60 def __contains__(self, key): 

61 return key in self._allInfo 

62 

63 

64Config.instance = Config() 

65"""The sole `Config` object used by the program. 

66"""