@@ -80,17 +80,18 @@ def main() -> int:
8080 try :
8181 for i , target in enumerate (open_targets (args )):
8282 try :
83+ target_info = get_target_info (target , args )
8384 if args .jsonlines :
84- print (json .dumps (get_target_info ( target ) , default = str ))
85+ print (json .dumps (target_info , default = str ))
8586 elif args .json :
86- print (json .dumps (get_target_info ( target ) , indent = 4 , default = str ))
87+ print (json .dumps (target_info , indent = 4 , default = str ))
8788 elif args .record :
8889 rs = record_output (args .strings )
89- rs .write (InfoRecord (** get_target_info ( target ) , _target = target ))
90+ rs .write (InfoRecord (** target_info , _target = target ))
9091 else :
9192 if i > 0 :
9293 print ("-" * 70 )
93- print_target_info (target )
94+ print_target_info (target , target_info )
9495 except Exception as e : # noqa: PERF203
9596 target .log .error ("Exception in retrieving information for target: `%s`, use `-vv` for details" , target ) # noqa: TRY400
9697 target .log .debug ("" , exc_info = e )
@@ -102,11 +103,11 @@ def main() -> int:
102103 return 0
103104
104105
105- def get_target_info (target : Target ) -> dict [str , str | list [str ]]:
106+ def get_target_info (target : Target , args : argparse . Namespace ) -> dict [str , str | list [str ]]:
106107 return {
107108 "disks" : get_disks_info (target ),
108109 "volumes" : get_volumes_info (target ),
109- "children" : get_children_info (target ),
110+ "children" : get_children_info (target , args . recursive ),
110111 "hostname" : target .hostname ,
111112 "domain" : get_optional_func (target , "domain" ),
112113 "ips" : target .ips ,
@@ -126,10 +127,10 @@ def get_optional_func(target: Target, func: str) -> str | None:
126127 return None
127128
128129
129- def print_target_info (target : Target ) -> None :
130+ def print_target_info (target : Target , target_info : dict [ str , str | list [ str ]] ) -> None :
130131 print (target )
131132
132- for name , value in get_target_info ( target ) .items ():
133+ for name , value in target_info .items ():
133134 if name in ["disks" , "volumes" , "children" ]:
134135 if not any (value ):
135136 continue
@@ -161,8 +162,14 @@ def get_volumes_info(target: Target) -> list[dict[str, str | int]]:
161162
162163def get_children_info (target : Target , recursive : bool = False ) -> list [dict [str , str ]]:
163164 if recursive :
164- return [{"child_index" : i , "type" : c .type , "path" : str (c .path )} for i , c in target .list_children_recursive ()]
165- return [{"child_index" : i , "type" : c .type , "path" : str (c .path )} for i , c in enumerate (target .list_children ())]
165+ return [
166+ {"child_index" : i , "name" : c .name , "type" : c .type , "path" : str (c .path )}
167+ for i , c in target .list_children_recursive ()
168+ ]
169+ return [
170+ {"child_index" : i , "name" : c .name , "type" : c .type , "path" : str (c .path )}
171+ for i , c in enumerate (target .list_children ())
172+ ]
166173
167174
168175if __name__ == "__main__" :
0 commit comments