@@ -158,6 +158,26 @@ def __repr__(self):
158158 def __str__ (self ):
159159 return self .get_unique_id ()
160160
161+ def print_detailed (self , dsync : "Optional[DSync]" = None , indent : int = 0 ):
162+ """Print this model and its children."""
163+ margin = " " * indent
164+ if not dsync :
165+ dsync = self .dsync
166+ print (f"{ margin } { self .get_type ()} : { self .get_unique_id ()} " )
167+ for modelname , fieldname in self ._children .items ():
168+ print (f"{ margin } { modelname } " )
169+ child_ids = getattr (self , fieldname )
170+ if not child_ids :
171+ print (f"{ margin } (none)" )
172+ for child_id in child_ids :
173+ child = None
174+ if dsync :
175+ child = dsync .get (modelname , child_id )
176+ if not child :
177+ print (f"{ margin } { child_id } (no details available)" )
178+ else :
179+ child .print_detailed (dsync , indent + 4 )
180+
161181 @classmethod
162182 def create (cls , dsync : "DSync" , ids : dict , attrs : dict ) -> Optional ["DSyncModel" ]:
163183 """Instantiate this class, along with any platform-specific data creation.
@@ -378,6 +398,17 @@ def load(self):
378398 """Load all desired data from whatever backend data source into this instance."""
379399 # No-op in this generic class
380400
401+ def print_detailed (self , indent : int = 0 ):
402+ """Recursively print this DSync and its contained models."""
403+ margin = " " * indent
404+ for modelname in self .top_level :
405+ print (f"{ margin } { modelname } " )
406+ models = self .get_all (modelname )
407+ if not models :
408+ print (f"{ margin } (none)" )
409+ for model in models :
410+ model .print_detailed (self , indent + 2 )
411+
381412 # ------------------------------------------------------------------------------
382413 # Synchronization between DSync instances
383414 # ------------------------------------------------------------------------------
0 commit comments