def make_dir_obsolete(directory):
 p = directory.parent
 if ((p is not None) and (p.child_dirs.filter(obsolete=False).count() == 1)):
  make_dir_obsolete(p)
 directory.obsolete = True
 directory.save()

def make_dir_obsolete ( directory ) : p = directory . parent if ( ( p is not None ) and ( p . child_dirs . filter ( obsolete = False ) . count ( ) == 1 ) ) : make_dir_obsolete ( p ) directory . obsolete = True directory . save ( )
make directory and its parents obsolete if a parent contains one empty directory only .