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# 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__ = ("StoredFileInfo", "StoredDatastoreItemInfo") 

25 

26import inspect 

27from dataclasses import dataclass 

28from typing import Optional 

29 

30from .formatter import Formatter, FormatterParameter 

31from .storageClass import StorageClass 

32 

33 

34class StoredDatastoreItemInfo: 

35 """Internal information associated with a stored dataset in a `Datastore`. 

36 

37 This is an empty base class. Datastore implementations are expected to 

38 write their own subclasses. 

39 """ 

40 

41 __slots__ = () 

42 

43 

44@dataclass(frozen=True) 

45class StoredFileInfo(StoredDatastoreItemInfo): 

46 """Datastore-private metadata associated with a Datastore file.""" 

47 

48 __slots__ = {"formatter", "path", "storageClass", "component", 

49 "checksum", "file_size"} 

50 

51 def __init__(self, formatter: FormatterParameter, 

52 path: str, 

53 storageClass: StorageClass, 

54 component: Optional[str], 

55 checksum: Optional[str], 

56 file_size: int): 

57 

58 # Use these shenanigans to allow us to use a frozen dataclass 

59 object.__setattr__(self, "path", path) 

60 object.__setattr__(self, "storageClass", storageClass) 

61 object.__setattr__(self, "component", component) 

62 object.__setattr__(self, "checksum", checksum) 

63 object.__setattr__(self, "file_size", file_size) 

64 

65 if isinstance(formatter, str): 

66 # We trust that this string refers to a Formatter 

67 formatterStr = formatter 

68 elif isinstance(formatter, Formatter) or \ 

69 (inspect.isclass(formatter) and issubclass(formatter, Formatter)): 

70 formatterStr = formatter.name() 

71 else: 

72 raise TypeError(f"Supplied formatter '{formatter}' is not a Formatter") 

73 object.__setattr__(self, "formatter", formatterStr) 

74 

75 formatter: str 

76 """Fully-qualified name of Formatter. If a Formatter class or instance 

77 is given the name will be extracted.""" 

78 

79 path: str 

80 """Path to dataset within Datastore.""" 

81 

82 storageClass: StorageClass 

83 """StorageClass associated with Dataset.""" 

84 

85 component: Optional[str] 

86 """Component associated with this file. Can be None if the file does 

87 not refer to a component of a composite.""" 

88 

89 checksum: Optional[str] 

90 """Checksum of the serialized dataset.""" 

91 

92 file_size: int 

93 """Size of the serialized dataset in bytes."""