ucscsdk/ucsccoreutils.py
def write_mo_tree(mo, level=0, depth=None, show_level=[],
                  print_tree=True, tree_dict={}, dn=None):
    """
    Prints tree structure of any managed object

    Args:
        mo (object): ManagedObject
        level (int): by default zero
        depth (int or None): last level to process
        show_level (int list): levels to display
        print_tree (bool): if True, print mo tree
        tree_dict (dict): by default {}
        dn (str): dn

    Returns:
        dictionary

    Example:
        mo=handle.query_dn("org-root")\n
        tree_dict = write_mo_tree(mo, depth=3, show_level=[1, 3])\n
    """

    if not mo.dn:
        mo.dn = dn
    indent = "    "

    level_indent = "%s%s)" % (indent * level, level)

    level_key_dn = "level_%s_dn" % (str(level))
    if level_key_dn not in tree_dict:
        tree_dict[level_key_dn] = {mo.dn: mo}
    else:
        tree_dict[level_key_dn][mo.dn] = mo

    level_key_mo = "level_%s_mo" % (str(level))
    if level_key_mo not in tree_dict:
        tree_dict[level_key_mo] = {mo.class_id: [mo]}
    else:
        if mo.class_id not in tree_dict[level_key_mo]:
            tree_dict[level_key_mo][mo.class_id] = [mo]
        else:
            tree_dict[level_key_mo][mo.class_id].append(mo)

    key_all_mo = "all_mo"
    if key_all_mo not in tree_dict:
        tree_dict[key_all_mo] = {mo.class_id: [mo]}
    else:
        if mo.class_id not in tree_dict[key_all_mo]:
            tree_dict[key_all_mo][mo.class_id] = [mo]
        else:
            tree_dict[key_all_mo][mo.class_id].append(mo)

    # print tree_dict

    if print_tree:
        if not show_level:
            print("%s %s (%s)" % (level_indent, mo.dn, mo.class_id))
        elif level in show_level:
            print("%s %s (%s)" % (level_indent, mo.dn, mo.class_id))

    for child in mo.child:
        child.mark_clean()
        level += 1
        if depth is None:
            tree_dict = write_mo_tree(child, level, depth,
                                      show_level, print_tree,
                                      tree_dict, dn)
        elif level <= depth:
            tree_dict = write_mo_tree(child, level, depth,
                                      show_level, print_tree,
                                      tree_dict, dn)
        level -= 1

    return tree_dict

    Prints tree structure of any managed object

    Args:
        mo (object): ManagedObject
        level (int): by default zero
        depth (int or None): last level to process
        show_level (int list): levels to display
        print_tree (bool): if True, print mo tree
        tree_dict (dict): by default {}
        dn (str): dn

    Returns:
        dictionary

    Example:
        mo=handle.query_dn("org-root")\n
        tree_dict = write_mo_tree(mo, depth=3, show_level=[1, 3])\n
    
Prints tree structure of any managed object
Prints tree structure of any managed object
def write_mo_tree(mo, level=0, depth=None, show_level=[],
                  print_tree=True, tree_dict={}, dn=None):
    if not mo.dn:
        mo.dn = dn
    indent = "    "
    level_indent = "%s%s)" % (indent * level, level)
    level_key_dn = "level_%s_dn" % (str(level))
    if level_key_dn not in tree_dict:
        tree_dict[level_key_dn] = {mo.dn: mo}
    else:
        tree_dict[level_key_dn][mo.dn] = mo
    level_key_mo = "level_%s_mo" % (str(level))
    if level_key_mo not in tree_dict:
        tree_dict[level_key_mo] = {mo.class_id: [mo]}
    else:
        if mo.class_id not in tree_dict[level_key_mo]:
            tree_dict[level_key_mo][mo.class_id] = [mo]
        else:
            tree_dict[level_key_mo][mo.class_id].append(mo)
    key_all_mo = "all_mo"
    if key_all_mo not in tree_dict:
        tree_dict[key_all_mo] = {mo.class_id: [mo]}
    else:
        if mo.class_id not in tree_dict[key_all_mo]:
            tree_dict[key_all_mo][mo.class_id] = [mo]
        else:
            tree_dict[key_all_mo][mo.class_id].append(mo)
    if print_tree:
        if not show_level:
            print("%s %s (%s)" % (level_indent, mo.dn, mo.class_id))
        elif level in show_level:
            print("%s %s (%s)" % (level_indent, mo.dn, mo.class_id))
    for child in mo.child:
        child.mark_clean()
        level += 1
        if depth is None:
            tree_dict = write_mo_tree(child, level, depth,
                                      show_level, print_tree,
                                      tree_dict, dn)
        elif level <= depth:
            tree_dict = write_mo_tree(child, level, depth,
                                      show_level, print_tree,
                                      tree_dict, dn)
        level -= 1
    return tree_dict
def write_mo_tree ( mo , level = 0 , depth = None , show_level = [ ] , print_tree = True , tree_dict = { } , dn = None ) : if not mo . dn : mo . dn = dn indent = "    " level_indent = "%s%s)" % ( indent * level , level ) level_key_dn = "level_%s_dn" % ( str ( level ) ) if level_key_dn not in tree_dict : tree_dict [ level_key_dn ] = { mo . dn : mo } else : tree_dict [ level_key_dn ] [ mo . dn ] = mo level_key_mo = "level_%s_mo" % ( str ( level ) ) if level_key_mo not in tree_dict : tree_dict [ level_key_mo ] = { mo . class_id : [ mo ] } else : if mo . class_id not in tree_dict [ level_key_mo ] : tree_dict [ level_key_mo ] [ mo . class_id ] = [ mo ] else : tree_dict [ level_key_mo ] [ mo . class_id ] . append ( mo ) key_all_mo = "all_mo" if key_all_mo not in tree_dict : tree_dict [ key_all_mo ] = { mo . class_id : [ mo ] } else : if mo . class_id not in tree_dict [ key_all_mo ] : tree_dict [ key_all_mo ] [ mo . class_id ] = [ mo ] else : tree_dict [ key_all_mo ] [ mo . class_id ] . append ( mo ) if print_tree : if not show_level : print ( "%s %s (%s)" % ( level_indent , mo . dn , mo . class_id ) ) elif level in show_level : print ( "%s %s (%s)" % ( level_indent , mo . dn , mo . class_id ) ) for child in mo . child : child . mark_clean ( ) level += 1 if depth is None : tree_dict = write_mo_tree ( child , level , depth , show_level , print_tree , tree_dict , dn ) elif level <= depth : tree_dict = write_mo_tree ( child , level , depth , show_level , print_tree , tree_dict , dn ) level -= 1 return tree_dict
Prints tree structure of any managed object
Prints tree structure of any managed object
"""
    Prints tree structure of any managed object

    Args:
        mo (object): ManagedObject
        level (int): by default zero
        depth (int or None): last level to process
        show_level (int list): levels to display
        print_tree (bool): if True, print mo tree
        tree_dict (dict): by default {}
        dn (str): dn

    Returns:
        dictionary

    Example:
        mo=handle.query_dn("org-root")\n
        tree_dict = write_mo_tree(mo, depth=3, show_level=[1, 3])\n
    """ # print tree_dict
None
mo
None
level
by default zero
by default zero
depth
last level to process
last level to process
show_level
levels to display
levels to display
print_tree
if True, print mo tree
if True print mo tree
tree_dict
by default {}
by default {}
dn
None
examples
mo=handle.query_dn("org-root")\n
tree_dict = write_mo_tree(mo, depth=3, show_level=[1, 3])\n
mo = handle . query_dn ( " org - root " ) \ n tree_dict = write_mo_tree ( mo depth = 3 show_level = [ 1 3 ] ) \ n