Exemplo n.º 1
0
    def pretty(self, args, cell):
        """pretty-print the robot text"""
        tidier = Tidy()

        with tempfile.TemporaryDirectory() as td:
            tdp = Path(td)
            it = tdp / "ugly.robot"
            it.write_text(cell, **ENC)
            tidier.inplace(str(it))
            cell = it.read_text(**ENC)

        lexer = RobotFrameworkLexer()
        formatter = HtmlFormatter(cssclass=self.PRETTY_CLASS, style=args.style)
        css = formatter.get_style_defs(f".{self.PRETTY_CLASS}")
        highlighted = highlight(cell, lexer, formatter)
        html = HTML(f"""
            <ul><li>
            <details>
                <summary>Formatted Robot Code</summary>
                <style>{css}</style>{highlighted}
            </details>
            </li></ul>
        """)

        return html
def main(argv=None):
    parser = argparse.ArgumentParser()
    parser.add_argument('filenames', nargs='*', help='Filenames to run')
    parser.add_argument('--use-pipes',
                        action='store_true',
                        dest='use_pipes',
                        default=False)
    parser.add_argument('--space-count',
                        type=int,
                        dest='space_count',
                        default=4)
    args = parser.parse_args(argv)

    tidier = Tidy(use_pipes=args.use_pipes, space_count=args.space_count)
    for filename in args.filenames:
        try:
            tidier.inplace(filename)
        except (DataError, OSError):
            pass

    return 0