示例#1
0
def run_tests(input_path, output_path, adopath, standalone=True):
    all_fn = os.listdir(input_path)

    for base_fn in all_fn:
        fn = os.path.join(input_path, base_fn)
        current_file = os.path.splitext(os.path.basename(fn))[0]

        # Transform SMCL representation into XML representation
        lines = read_smcl(fn)
        lines = expand_includes(lines, adopath) # Replace lines like "INCLUDE help fvvarlist"
        lines = newline_after_p_end(lines)
        xml = smcl2xml(lines)

        # Construct tree
        root = etree.fromstring(xml)

        # Modify tree to create better abstractions
        root = smcl_parser.parse_blocks(root, current_file)
        root = smcl_parser.parse_inlines(root, current_file)
        root = smcl_parser.parse_improvements(root)

        # Create complete html file (standalone option)
        if standalone:
            doctype = '<!DOCTYPE html>'
            root = make_standalone(root, current_file)
        else:
            doctype = None

        # Export file
        out_fn = os.path.join(output_path, current_file + '.html')
        text = etree.tostring(root, encoding='utf-8', method='html', 
                              pretty_print=True, xml_declaration=True, doctype=doctype)
        with open(out_fn, mode='wb') as fh:
            fh.write(text)
示例#2
0
    lines = expand_includes(lines, args.adopath) # Replace lines like "INCLUDE help fvvarlist"
    lines = newline_after_p_end(lines)
    xml = smcl2xml(lines)

    if args.xml:
        # Only save intermediate XML file
        xml = xml.replace('<newline/>', '<newline/>\n')
        with open(args.output, mode='w') as fh:
            fh.write(xml)
    else:
        # Construct tree
        root = etree.fromstring(xml)
        #tree = etree.ElementTree(root)

        # Modify tree to create better abstractions
        root = smcl_parser.parse_blocks(root, args.current_file)
        root = smcl_parser.parse_inlines(root, args.current_file)
        root = smcl_parser.parse_improvements(root)

        # Create complete html file (standalone option)
        if args.standalone:
            doctype = '<!DOCTYPE html>'
            root = make_standalone(root, args.current_file)
        else:
            doctype = None

        # Export file
        text = etree.tostring(root, encoding='utf-8', method='html', 
                              pretty_print=True, xml_declaration=True, doctype=doctype)
        with open(args.output, mode='wb') as fh:
            fh.write(text)