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

20 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-19 10:53 +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 software is dual licensed under the GNU General Public License and also 

10# under a 3-clause BSD license. Recipients may choose which of these licenses 

11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt, 

12# respectively. If you choose the GPL option then the following text applies 

13# (but note that there is still no warranty even if you opt for BSD instead): 

14# 

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

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

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

18# (at your option) any later version. 

19# 

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

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

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

23# GNU General Public License for more details. 

24# 

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

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

27 

28from __future__ import annotations 

29 

30__all__ = ["DatasetExistence"] 

31 

32from enum import Flag, auto 

33 

34 

35class DatasetExistence(Flag): 

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

37 in a Butler repository. 

38 

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

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

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

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

43 

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

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

46 ``AND``. 

47 

48 .. code-block :: py 

49 

50 exists = DatasetExistence.VERIFIED 

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

52 # The datastore knows about this dataset. 

53 """ 

54 

55 UNRECOGNIZED = 0 

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

57 

58 Evaluates to `False` in Boolean context. 

59 """ 

60 

61 RECORDED = auto() 

62 """Known to registry or equivalent. 

63 

64 Evaluates to `False` in Boolean context. 

65 """ 

66 

67 DATASTORE = auto() 

68 """Known to the datastore. 

69 

70 Evaluates to `False` in Boolean context. 

71 """ 

72 

73 _ARTIFACT = auto() 

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

75 confirmed to exist.""" 

76 

77 _ASSUMED = auto() 

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

79 was never verified.""" 

80 

81 KNOWN = RECORDED | DATASTORE | _ASSUMED 

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

83 artifact in datastore has not been verified. 

84 

85 Evaluates to `True` in Boolean context. 

86 """ 

87 

88 VERIFIED = RECORDED | DATASTORE | _ARTIFACT 

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

90 artifact has been verified. 

91 

92 Evaluates to `True` in Boolean context. 

93 """ 

94 

95 def __bool__(self) -> bool: 

96 """Indicate whether the dataset exists. 

97 

98 Returns 

99 ------- 

100 exists : `bool` 

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

102 or ``VERIFIED``. 

103 """ 

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