def main(): arg_parser = argparse.ArgumentParser( description='list PureData objects in pddoc') arg_parser.add_argument('--properties', '-p', action='store_true', help='list properties') arg_parser.add_argument('--objects', '-o', action='store_true', help='list objects') arg_parser.add_argument('--methods', '-m', action='store_true', help='list methods') arg_parser.add_argument('name', metavar='PDDOC', help="Documentation file in PDDOC(XML) format") args = vars(arg_parser.parse_args()) in_file = args['name'] xml = parse_xml(in_file) if not xml: exit(1) pddoc = xml.getroot() for child_tag in pddoc: if child_tag.tag == "object": dobj = DocObject() dobj.from_xml(child_tag) dobj.traverse(ListObjectVisitor())
def main(): arg_parser = argparse.ArgumentParser( description='PureData pddoc to html converter') arg_parser.add_argument('name', metavar='PDDOC', help="Documentation file in PDDOC format") arg_parser.add_argument('output', metavar='OUTNAME', nargs='?', default='', help="HTML output file name") args = vars(arg_parser.parse_args()) in_file = args['name'] output = args['output'] if not os.path.exists(in_file): logging.error("File not exists: \"%s\"", in_file) exit(1) if not output: output = os.path.splitext(os.path.basename(in_file))[0] + ".html" xml = parse_xml(in_file) if not xml: exit(1) css_file = "theme.css" factory.add_import('ceammc') pddoc = xml.getroot() for child_tag in pddoc: if child_tag.tag == "object": dobj = DocObject() dobj.from_xml(child_tag) v = HtmlDocVisitor() v.set_css_file(css_file) v.set_image_prefix(child_tag.attrib["name"]) v.set_search_dir(os.path.dirname(in_file)) # traverse doc dobj.traverse(v) # generate images v.generate_images() html_data = v.render() f = open(output, "w") f.write(html_data) f.close() # copy css theme file to current folder src_css = os.path.join(os.path.dirname(__file__), "../share", css_file) shutil.copyfile(src_css, css_file)
def test_parse(self): xml = parse_xml("sample.pddoc") if not xml: exit(1) pddoc = xml.getroot() for child_tag in pddoc: if child_tag.tag == "object": dobj = DocObject() dobj.from_xml(child_tag)
def test_init(self): nl = NoLogging() xml = etree.parse("float.pddoc") pddoc = xml.getroot() for child in pddoc: if child.tag == "object": dobj = DocObject() dobj.from_xml(child) lv = LatexDocObjectVisitor() dobj.traverse(lv) lv.generate_images() latex_data = lv.render() f = open("out/float.tex", "w") f.write(latex_data) f.close()
def test_float_export(self): dobj = DocObject() xml = ET.parse("float.pddoc") pddoc = xml.getroot() for child in pddoc: if child.tag == "object": dobj.from_xml(child) v = HtmlDocVisitor() dobj.traverse(v) v.generate_images() s = v.render() f = open("out/float.html", "w") f.write(s) f.close() break
def main(): arg_parser = argparse.ArgumentParser(description='PureData pddoc to Markdown converter') arg_parser.add_argument('name', metavar='PDDOC', help="Documentation file in PDDOC format") arg_parser.add_argument('output', metavar='OUTNAME', nargs='?', default='', help="Markdown output file name") arg_parser.add_argument('--locale', '-l', metavar='locale', default='EN', help='locale (currently EN or RU)') args = vars(arg_parser.parse_args()) in_file = args['name'] output = args['output'] if not os.path.exists(in_file): logging.error("File not exists: \"%s\"", in_file) exit(1) if not output: output = os.path.splitext(os.path.basename(in_file))[0] + ".md" xml = parse_xml(in_file) if not xml: exit(1) factory.add_import('ceammc') pddoc = xml.getroot() for child_tag in pddoc: if child_tag.tag == "object": dobj = DocObject() dobj.from_xml(child_tag) v = MarkdownVisitor(args['locale']) v.set_image_prefix(child_tag.attrib["name"]) v.set_search_dir(os.path.dirname(in_file)) # traverse doc dobj.traverse(v) # generate images v.generate_images() html_data = v.render() f = open(output, "w") f.write(html_data) f.close()
class TestXletDocVisitor(TestCase): def setUp(self): self._xml = parse_xml(os.path.join(CWD, "test_xlet_doc_visitor.pddoc")) self.assertTrue(self._xml is not None) self._doc_obj = DocObject() self._doc_obj.from_xml(self._xml.getroot()[0]) self.XLET_DB = os.path.join(CWD, "test_xlet_doc_visitor-xlet_db.txt") def tearDown(self): if os.path.exists(self.XLET_DB): os.remove(self.XLET_DB) def traverse(self, v): self._doc_obj.traverse(v) def test_inlets_begin(self): v = XletDocVisitor() self.traverse(v) self.assertEqual(v.inlet_types(), [1, 0]) self.assertTrue(os.path.exists(self.XLET_DB)) with open(self.XLET_DB, "r") as f: txt = f.read().strip() self.assertEqual(txt, "test_xlet_doc_visitor\t\t~.\t\t~..") obj = PdObject("test_xlet_doc_visitor") self.assertEqual(obj.inlets(), [1, 0]) self.assertEqual(obj.outlets(), [1, 0, 0]) PdObject.remove_object_xlet_info("test_xlet_doc_visitor") def test_outlets_begin(self): v = XletDocVisitor(write_to_file=False, add_to_mem_db=False) self.traverse(v) self.assertEqual(v.outlet_types(), [1, 0, 0]) self.assertFalse(os.path.exists(self.XLET_DB)) obj = PdObject("test_xlet_doc_visitor") self.assertEqual(obj.inlets(), []) self.assertEqual(obj.outlets(), [])
def main(): arg_parser = argparse.ArgumentParser( description='PureData pddoc to pd patch converter') arg_parser.add_argument('--website', '-w', metavar='URL', help='library website URL') arg_parser.add_argument('--license', '-l', metavar='license', help='library license') arg_parser.add_argument('--version', '-v', metavar='version', default='0.0', help='library version') arg_parser.add_argument('--force', '-f', action='store_true', help='force to overwrite existing file') arg_parser.add_argument('--xlet-db', metavar='PATH', action='append', help='inlet/outlet database file paths', default=[]) arg_parser.add_argument('name', metavar='PDDOC', help="Documentation file in PDDOC(XML) format") arg_parser.add_argument('output', metavar='OUTNAME', nargs='?', default='', help="Pd output patch file name") args = vars(arg_parser.parse_args()) in_file = args['name'] output = args['output'] # add input pddoc file dir to search path for abstractions PdObject.xlet_patch_finder.add_search_dir(os.path.dirname(in_file)) if not output: output = os.path.splitext(os.path.basename(in_file))[0] + "-help.pd" if os.path.exists(output) and not args['force']: print( "Error: file already exists: '{0}'. Use --force flag to overwrite." .format(output)) exit(1) add_xlet_db(args['xlet_db']) xml = parse_xml(in_file) if not xml: exit(1) factory.add_import('ceammc') pddoc = xml.getroot() for child_tag in pddoc: if child_tag.tag == "object": dobj = DocObject() dobj.from_xml(child_tag) x = XletDocVisitor() dobj.traverse(x) v = PdDocVisitor() if 'version' in args: v._version = args['version'] if 'license' in args: v._license['name'] = args['license'] if 'website' in args: v._website = args['website'] dobj.traverse(v) patch_data = v.render() if not patch_data: print("convertion error") exit(1) with open(output, 'w') as f: f.write(patch_data)
def main(): arg_parser = argparse.ArgumentParser(description='PureData pddoc to pd patch converter') arg_parser.add_argument('--website', '-w', metavar='URL', help='library website URL') arg_parser.add_argument('--license', '-l', metavar='license', help='library license') arg_parser.add_argument('--version', '-v', metavar='version', default='0.0', help='library version') arg_parser.add_argument('--force', '-f', action='store_true', help='force to overwrite existing file') arg_parser.add_argument('--xlet-db', metavar='PATH', action='append', help='inlet/outlet database file paths', default=[]) arg_parser.add_argument('name', metavar='PDDOC', help="Documentation file in PDDOC(XML) format") arg_parser.add_argument('output', metavar='OUTNAME', nargs='?', default='', help="Pd output patch file name") args = vars(arg_parser.parse_args()) in_file = args['name'] output = args['output'] if not output: output = os.path.splitext(os.path.basename(in_file))[0] + "-help.pd" if os.path.exists(output) and not args['force']: print("Error: file already exists: '{0}'. Use --force flag to overwrite.".format(output)) exit(1) add_xlet_db(args['xlet_db']) xml = parse_xml(in_file) if not xml: exit(1) factory.add_import('ceammc') pddoc = xml.getroot() for child_tag in pddoc: if child_tag.tag == "object": dobj = DocObject() dobj.from_xml(child_tag) x = XletDocVisitor() dobj.traverse(x) v = PdDocVisitor() if 'version' in args: v._version = args['version'] if 'license' in args: v._license['name'] = args['license'] if 'website' in args: v._website = args['website'] dobj.traverse(v) patch_data = v.render() if not patch_data: print("convertion error") exit(1) with open(output, 'w') as f: f.write(patch_data)