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 __slots__ = () 

41 

42 

43@dataclass(frozen=True) 

44class StoredFileInfo(StoredDatastoreItemInfo): 

45 """Datastore-private metadata associated with a file stored in a Datastore. 

46 """ 

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

48 "checksum", "file_size"} 

49 

50 def __init__(self, formatter: FormatterParameter, 

51 path: str, 

52 storageClass: StorageClass, 

53 component: Optional[str], 

54 checksum: Optional[str], 

55 file_size: int): 

56 

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

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

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

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

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

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

63 

64 if isinstance(formatter, str): 

65 # We trust that this string refers to a Formatter 

66 formatterStr = formatter 

67 elif isinstance(formatter, Formatter) or \ 

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

69 formatterStr = formatter.name() 

70 else: 

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

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

73 

74 formatter: str 

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

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

77 

78 path: str 

79 """Path to dataset within Datastore.""" 

80 

81 storageClass: StorageClass 

82 """StorageClass associated with Dataset.""" 

83 

84 component: Optional[str] 

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

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

87 

88 checksum: Optional[str] 

89 """Checksum of the serialized dataset.""" 

90 

91 file_size: int 

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