1313
1414
1515class Layer (_Layer , Mapping ):
16+ """
17+ OCI image layer
18+
19+ :author: Garden Linux Maintainers
20+ :copyright: Copyright 2024 SAP SE
21+ :package: gardenlinux
22+ :subpackage: oci
23+ :since: 0.7.0
24+ :license: https://www.apache.org/licenses/LICENSE-2.0
25+ Apache License, Version 2.0
26+ """
27+
1628 def __init__ (
1729 self ,
1830 blob_path : PathLike | str ,
1931 media_type : Optional [str ] = None ,
2032 is_dir : bool = False ,
2133 ):
34+ """
35+ Constructor __init__(Index)
36+
37+ :param blob_path: The path of the blob for the layer
38+ :param media_type: Media type for the blob (optional)
39+ :param is_dir: Is the blob a directory?
40+
41+ :since: 0.7.0
42+ """
43+
2244 if not isinstance (blob_path , PathLike ):
2345 blob_path = Path (blob_path )
2446
@@ -28,11 +50,26 @@ def __init__(
2850 ANNOTATION_TITLE : blob_path .name ,
2951 }
3052
53+ @property
54+ def dict (self ):
55+ """
56+ Return a dictionary representation of the layer
57+
58+ :return: (dict) OCI manifest layer metadata dictionary
59+ :since: 0.7.2
60+ """
61+ layer = _Layer .to_dict (self )
62+ layer ["annotations" ] = self ._annotations
63+
64+ return layer
65+
3166 def __delitem__ (self , key ):
3267 """
3368 python.org: Called to implement deletion of self[key].
3469
3570 :param key: Mapping key
71+
72+ :since: 0.7.0
3673 """
3774
3875 if key == "annotations" :
@@ -49,6 +86,7 @@ def __getitem__(self, key):
4986 :param key: Mapping key
5087
5188 :return: (mixed) Mapping key value
89+ :since: 0.7.0
5290 """
5391
5492 if key == "annotations" :
@@ -63,6 +101,7 @@ def __iter__(self):
63101 python.org: Return an iterator object.
64102
65103 :return: (object) Iterator object
104+ :since: 0.7.0
66105 """
67106
68107 iter (_SUPPORTED_MAPPING_KEYS )
@@ -71,7 +110,8 @@ def __len__(self):
71110 """
72111 python.org: Called to implement the built-in function len().
73112
74- :return: (int) Number of database instance attributes
113+ :return: (int) Number of attributes
114+ :since: 0.7.0
75115 """
76116
77117 return len (_SUPPORTED_MAPPING_KEYS )
@@ -82,6 +122,8 @@ def __setitem__(self, key, value):
82122
83123 :param key: Mapping key
84124 :param value: self[key] value
125+
126+ :since: 0.7.0
85127 """
86128
87129 if key == "annotations" :
@@ -91,21 +133,16 @@ def __setitem__(self, key, value):
91133 f"'{ self .__class__ .__name__ } ' object is not subscriptable except for keys: { _SUPPORTED_MAPPING_KEYS } "
92134 )
93135
94- def to_dict (self ):
95- """
96- Return a dictionary representation of the layer
97- """
98- layer = _Layer .to_dict (self )
99- layer ["annotations" ] = self ._annotations
100-
101- return layer
102-
103136 @staticmethod
104137 def generate_metadata_from_file_name (file_name : PathLike | str , arch : str ) -> dict :
105138 """
106- :param str file_name: file_name of the blob
107- :param str arch: the arch of the target image
108- :return: dict of oci layer metadata for a given layer file
139+ Generates OCI manifest layer metadata for the given file path and name.
140+
141+ :param file_name: File path and name of the target layer
142+ :param arch: The arch of the target image
143+
144+ :return: (dict) OCI manifest layer metadata dictionary
145+ :since: 0.7.0
109146 """
110147
111148 if not isinstance (file_name , PathLike ):
@@ -122,8 +159,12 @@ def generate_metadata_from_file_name(file_name: PathLike | str, arch: str) -> di
122159 @staticmethod
123160 def lookup_media_type_for_file_name (file_name : str ) -> str :
124161 """
125- :param str file_name: file_name of the target layer
126- :return: mediatype
162+ Looks up the media type based on file extension.
163+
164+ :param file_name: File path and name of the target layer
165+
166+ :return: (str) Media type
167+ :since: 0.7.0
127168 """
128169
129170 if not isinstance (file_name , PathLike ):
0 commit comments