2828from ._constants import TOP_OBJECT
2929from ._formatting import (
3030 TABLE_FAILURE_STRING ,
31+ TABLE_UNKNOWN_STRING ,
3132 TOTAL_USED_FREE ,
33+ catch_missing_property ,
3234 get_property ,
3335 print_table ,
3436)
@@ -124,7 +126,12 @@ def size_triple(mofs: Any) -> SizeTriple:
124126 """
125127 Calculate size triple
126128 """
127- return SizeTriple (Range (mofs .Size ()), get_property (mofs .Used (), Range , None ))
129+ return SizeTriple (
130+ catch_missing_property (lambda mo : Range (mo .Size ()), None )(mofs ),
131+ catch_missing_property (
132+ lambda mo : get_property (mo .Used (), Range , None ), None
133+ )(mofs ),
134+ )
128135
129136
130137class Table (ListFilesystem ): # pylint: disable=too-few-public-methods
@@ -158,16 +165,31 @@ def filesystem_size_quartet(
158165 )
159166 return f"{ triple_str } / { limit } "
160167
168+ def missing_property (func : Callable [[Any ], str ]) -> Callable [[Any ], str ]:
169+ return catch_missing_property (func , TABLE_UNKNOWN_STRING )
170+
171+ pool_name_func = missing_property (
172+ lambda mo : self .pool_object_path_to_pool_name .get (
173+ mo .Pool (), TABLE_UNKNOWN_STRING
174+ )
175+ )
176+ name_func = missing_property (lambda mofs : mofs .Name ())
177+ size_func = missing_property (
178+ lambda mofs : filesystem_size_quartet (
179+ ListFilesystem .size_triple (mofs ),
180+ get_property (mofs .SizeLimit (), Range , None ),
181+ )
182+ )
183+ devnode_func = missing_property (lambda mofs : mofs .Devnode ())
184+ uuid_func = missing_property (lambda mofs : self .uuid_formatter (mofs .Uuid ()))
185+
161186 tables = [
162187 (
163- self .pool_object_path_to_pool_name [mofilesystem .Pool ()],
164- mofilesystem .Name (),
165- filesystem_size_quartet (
166- ListFilesystem .size_triple (mofilesystem ),
167- get_property (mofilesystem .SizeLimit (), Range , None ),
168- ),
169- mofilesystem .Devnode (),
170- self .uuid_formatter (mofilesystem .Uuid ()),
188+ pool_name_func (mofilesystem ),
189+ name_func (mofilesystem ),
190+ size_func (mofilesystem ),
191+ devnode_func (mofilesystem ),
192+ uuid_func (mofilesystem ),
171193 )
172194 for mofilesystem in self .filesystems_with_props
173195 ]
@@ -198,29 +220,52 @@ def display(self):
198220
199221 fs = self .filesystems_with_props [0 ]
200222
201- size_triple = ListFilesystem .size_triple (fs )
202- limit = get_property (fs .SizeLimit (), Range , None )
203- created = (
204- date_parser .isoparse (fs .Created ()).astimezone ().strftime ("%b %d %Y %H:%M" )
205- )
223+ def missing_property (func : Callable [[Any ], str ]) -> Callable [[Any ], str ]:
224+ return catch_missing_property (func , TABLE_UNKNOWN_STRING )(fs )
206225
207- origin = get_property (fs .Origin (), self .uuid_formatter , None )
226+ uuid = missing_property (lambda mo : self .uuid_formatter (mo .Uuid ()))
227+ print (f"UUID: { uuid } " )
228+
229+ name = missing_property (lambda mo : mo .Name ())
230+ print (f"Name: { name } " )
231+
232+ pool = missing_property (
233+ lambda mo : self .pool_object_path_to_pool_name .get (
234+ mo .Pool (), TABLE_UNKNOWN_STRING
235+ ),
236+ )
237+ print (f"Pool: { pool } " )
208238
209- print (f"UUID: { self .uuid_formatter (fs .Uuid ())} " )
210- print (f"Name: { fs .Name ()} " )
211- print (f"Pool: { self .pool_object_path_to_pool_name [fs .Pool ()]} " )
239+ devnode = missing_property (lambda mo : mo .Devnode ())
212240 print ()
213- print (f"Device: { fs .Devnode ()} " )
241+ print (f"Device: { devnode } " )
242+
243+ created = missing_property (
244+ lambda mo : date_parser .isoparse (mo .Created ())
245+ .astimezone ()
246+ .strftime ("%b %d %Y %H:%M" ),
247+ )
214248 print ()
215249 print (f"Created: { created } " )
250+
251+ origin = missing_property (
252+ lambda mo : get_property (mo .Origin (), self .uuid_formatter , str (None ))
253+ )
216254 print ()
217255 print (f"Snapshot origin: { origin } " )
218256 if origin is not None :
219- scheduled = "Yes" if fs .MergeScheduled () else "No"
257+ scheduled = missing_property (
258+ lambda mo : "Yes" if mo .MergeScheduled () else "No"
259+ )
220260 print (f" Revert scheduled: { scheduled } " )
261+
262+ size_triple = ListFilesystem .size_triple (fs )
221263 print ()
222264 print ("Sizes:" )
223- print (f" Logical size of thin device: { size_triple .total ()} " )
265+ print (
266+ " Logical size of thin device: "
267+ f"{ TABLE_FAILURE_STRING if size_triple .total () is None else size_triple .total ()} "
268+ )
224269 print (
225270 " Total used (including XFS metadata): "
226271 f"{ TABLE_FAILURE_STRING if size_triple .used () is None else size_triple .used ()} "
@@ -229,5 +274,9 @@ def display(self):
229274 " Free: "
230275 f"{ TABLE_FAILURE_STRING if size_triple .free () is None else size_triple .free ()} "
231276 )
277+
278+ limit = missing_property (
279+ lambda mo : get_property (mo .SizeLimit (), lambda x : str (Range (x )), str (None ))
280+ )
232281 print ()
233282 print (f" Size Limit: { limit } " )
0 commit comments