Example #1
0
def gen_list_easyblocks(list_easyblocks, format_strings):
    """Get a class tree for easyblocks."""
    detailed = list_easyblocks == DETAILED

    locations = avail_easyblocks()

    def add_class(classes, cls):
        """Add a new class, and all of its subclasses."""
        children = cls.__subclasses__()
        classes.update({
            cls.__name__: {
                'module':
                cls.__module__,
                'children':
                sorted([c.__name__ for c in children], key=lambda x: x.lower())
            }
        })
        for child in children:
            add_class(classes, child)

    roots = [EasyBlock, Extension]

    classes = {}
    for root in roots:
        add_class(classes, root)

    # Print the tree, start with the roots
    txt = []

    for root in roots:
        root = root.__name__
        if detailed:
            mod = classes[root]['module']
            loc = ''
            if mod in locations:
                loc = ' @ %s' % locations[mod]['loc']
            txt.append(format_strings['det_root_templ'] % (root, mod, loc))
        else:
            txt.append(format_strings['root_templ'] % root)

        if format_strings.get('newline') is not None:
            txt.append(format_strings['newline'])
        if 'children' in classes[root]:
            txt.extend(
                avail_classes_tree(classes, classes[root]['children'],
                                   locations, detailed, format_strings))
            if format_strings.get('newline') is not None:
                txt.append(format_strings['newline'])
    return '\n'.join(txt)
Example #2
0
def gen_list_easyblocks(list_easyblocks, format_strings):
    """Get a class tree for easyblocks."""
    detailed = list_easyblocks == DETAILED

    locations = avail_easyblocks()

    def add_class(classes, cls):
        """Add a new class, and all of its subclasses."""
        children = cls.__subclasses__()
        classes.update({cls.__name__: {
            'module': cls.__module__,
            'children': sorted([c.__name__ for c in children], key=lambda x: x.lower())
        }})
        for child in children:
            add_class(classes, child)

    roots = [EasyBlock, Extension]

    classes = {}
    for root in roots:
        add_class(classes, root)

    # Print the tree, start with the roots
    txt = []

    for root in roots:
        root = root.__name__
        if detailed:
            mod = classes[root]['module']
            loc = ''
            if mod in locations:
                loc = ' @ %s' % locations[mod]['loc']
            txt.append(format_strings['det_root_templ'] % (root, mod, loc))
        else:
            txt.append(format_strings['root_templ'] % root)

        if format_strings.get('newline') is not None:
                txt.append(format_strings['newline'])
        if 'children' in classes[root]:
            txt.extend(avail_classes_tree(classes, classes[root]['children'], locations, detailed, format_strings))
            if format_strings.get('newline') is not None:
                txt.append(format_strings['newline'])
    return '\n'.join(txt)