Ejemplo 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
Ejemplo n.º 2
0
def convert_robot_data_file(original_filepath):
    from robot.tidy import Tidy
    from base64 import b64encode

    converted_content = Tidy(format='robot').file(original_filepath)

    if sys.version_info < (3, 0, 0):
        return b64encode(converted_content.encode('utf-8'))
    else:
        return str(b64encode(bytes(converted_content, 'utf-8')), 'utf-8')
Ejemplo n.º 3
0
def robot_source_format(source, space_count=4):
    if not source.strip():
        return None

    from robot.tidy import Tidy

    t = Tidy(space_count=space_count)
    from io import StringIO

    s = StringIO()
    if isinstance(source, bytes):
        source = source.decode("utf-8", "replace")

    s.write(source)
    s.seek(0)
    formatted = t.file(s)
    if not formatted:
        return None

    return formatted
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