Coverage for python/lsst/daf/butler/_dataset_existence.py: 95%

20 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-14 09:11 +0000

1# This file is part of daf_butler. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

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

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

7# for details of code ownership. 

8# 

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

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

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

12# (at your option) any later version. 

13# 

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

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

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

17# GNU General Public License for more details. 

18# 

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

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

21 

22from __future__ import annotations 

23 

24__all__ = ["DatasetExistence"] 

25 

26from enum import Flag, auto 

27 

28 

29class DatasetExistence(Flag): 

30 """Flags representing the different states that a dataset can have 

31 in a Butler repository. 

32 

33 If a flag evaluates to `True` that will indicate that a dataset is 

34 present in the Butler repository. The different states for `KNOWN` 

35 and `VERIFIED` both evaluate to `True` and differ solely on whether 

36 the artifact was checked to make sure it exists or not. 

37 

38 Some flag are combinations of other flags, so in order to determine 

39 whether a dataset is present in datastore it is necessary to use logical 

40 ``AND``. 

41 

42 .. code-block :: py 

43 

44 exists = DatasetExistence.VERIFIED 

45 if (DatasetExistence.DATASTORE & exists) == DatasetExistence.DATASTORE: 

46 # The datastore knows about this dataset. 

47 """ 

48 

49 UNRECOGNIZED = 0 

50 """The dataset is not recognized as part of this registry or datastore. 

51 

52 Evaluates to `False` in Boolean context. 

53 """ 

54 

55 RECORDED = auto() 

56 """Known to registry or equivalent. 

57 

58 Evaluates to `False` in Boolean context. 

59 """ 

60 

61 DATASTORE = auto() 

62 """Known to the datastore. 

63 

64 Evaluates to `False` in Boolean context. 

65 """ 

66 

67 _ARTIFACT = auto() 

68 """Internal flag indicating that the datastore artifact has been 

69 confirmed to exist.""" 

70 

71 _ASSUMED = auto() 

72 """Internal flag indicating that the existence of the datastore artifact 

73 was never verified.""" 

74 

75 KNOWN = RECORDED | DATASTORE | _ASSUMED 

76 """The dataset is known to registry and datastore. The presence of the 

77 artifact in datastore has not been verified. 

78 

79 Evaluates to `True` in Boolean context. 

80 """ 

81 

82 VERIFIED = RECORDED | DATASTORE | _ARTIFACT 

83 """The dataset is known to registry and datastore and the presence of the 

84 artifact has been verified. 

85 

86 Evaluates to `True` in Boolean context. 

87 """ 

88 

89 def __bool__(self) -> bool: 

90 """Indicate whether the dataset exists. 

91 

92 Returns 

93 ------- 

94 exists : `bool 

95 Evaluates to `True` if the flags evaluate to either ``KNOWN`` 

96 or ``VERIFIED``. 

97 """ 

98 return self.value == self.KNOWN.value or self.value == self.VERIFIED.value