Example #1
0
def cli(ctx, path, expand_macros=False, **kwds):
    """Generate normalized tool XML from input (breaks formatting).

    This will break the formatting of your tool and is currently only intended
    for viewing macro expansions for for use with XSD validation (see
    https://github.com/JeanFred/Galaxy-XSD for instance). Please do not use
    the output as is - it frequently makes tool less readable not more.

    The top-level blocks will be reordered and whitespace fixed according to
    the tool development best practices outlined on the Galaxy wiki.

    ::

        % # Print normalized version of tool.
        % planemo normalize tool.xml
        <tool>
        ...
        % # Print a variant of tool with all macros expanded out, useful for
        % # debugging complex macros.
        % planemo normalize --expand_macros tool.xml
        <tool>
        ...
    """
    if expand_macros:
        tree = load_tool(path)
    else:
        tree = raw_tool_xml_tree(path)

    root = tree.getroot()
    if not kwds.get("skip_reorder", False):
        last_index = len(TAG_ORDER)
        data = []
        for elem in root:
            tag = elem.tag
            if tag in TAG_ORDER:
                key = TAG_ORDER.index(tag)
            else:
                key = last_index
                last_index += 1
            data.append((key, elem))
        data.sort()
        root[:] = [item[-1] for item in data]
    if not kwds.get("skip_reindent", False):
        _indent(root)
    ElementTree.dump(root)
Example #2
0
def cli(ctx, path, expand_macros=False, **kwds):
    """Generate normalized tool XML from input (breaks formatting).

    This will break the formatting of your tool and is currently only intended
    for viewing macro expansions for for use with XSD validation (see
    https://github.com/JeanFred/Galaxy-XSD for instance). Please do not use
    the output as is - it frequently makes tool less readable not more.

    The top-level blocks will be reordered and whitespace fixed according to
    the tool development best practices outlined on the Galaxy wiki.

    ::

        % # Print normalized version of tool.
        % planemo normalize tool.xml
        <tool>
        ...
        % # Print a variant of tool with all macros expanded out, useful for
        % # debugging complex macros.
        % planemo normalize --expand_macros tool.xml
        <tool>
        ...
    """
    if expand_macros:
        tree = load_tool(path)
    else:
        tree = raw_tool_xml_tree(path)

    root = tree.getroot()
    if not kwds.get("skip_reorder", False):
        last_index = len(TAG_ORDER)
        data = []
        for elem in root:
            tag = elem.tag
            if tag in TAG_ORDER:
                key = TAG_ORDER.index(tag)
            else:
                key = last_index
                last_index += 1
            data.append((key, elem))
        data.sort()
        root[:] = [item[-1] for item in data]
    if not kwds.get("skip_reindent", False):
        _indent(root)
    ElementTree.dump(root)