示例#1
0
    def gen(self, key, node, content_root) :
        '''
        Recursively parse source tree dictionary.
        If current_node is file : parse file using parseHTML
        Else If : current_node is directory : recurse and generate pkg.toc.html for that dir
                                              (optionally generate bundle info if present)
        :param key: string | the name of current_node in path tree
        :param node: dict | the parent tree of current_node
        :param content_root: string | real path to current node in html doc dir
        '''
        current_node = node[key]
        if type(current_node) != dict:
            if key == 'bundle.ecl' :
                return None
            parser = ParseHTML(self, node[key])
            parser.parse()
            file = {'name' : key,
                    'target' : key + '.html',
                    'type' : 'file',
                    'doc' : parser.docstring() }
            return file
        else :
            file = {'name' : key,
                    'target': joinpath(key, 'pkg.toc.html'),
                    'type': 'dir',
                    'doc' : '' }

            bundle = None
            if 'bundle.ecl' in current_node :
                bundle_xml_path = joinpath(self.xml_root, dirname(current_node['bundle.ecl']), 'bundle.xml')
                bundle = etree.parse(bundle_xml_path).getroot()
                license = bundle.find('License')
                license.text = '<a href="' + license.text + '">' + license.text + '</a>'
                file['type'] = 'bundle'

            childfiles = []
            keys = sorted(current_node.keys(), key=str.lower)
            for chkey in keys :
                child_root = joinpath(content_root, chkey)
                child_dict = self.gen(chkey, current_node, child_root)
                if child_dict is not None : childfiles.append(child_dict)

            childfiles = sorted(childfiles, key=lambda x : x['type'])

            root_relpath = relpath(self.output_root, content_root)
            parent_relpath = ''
            if content_root != self.html_root :
                parent_relpath = relpath(dirname(content_root), content_root)

            render = self.toc_template.render(name=key,
                                              files=childfiles,
                                              parent=joinpath(parent_relpath, 'pkg.toc.html'),
                                              output_root=root_relpath,
                                              bundle=bundle)
            os.makedirs(content_root, exist_ok=True)
            render_path = joinpath(content_root, 'pkg.toc.html')
            write_to_file(render_path, render)

            return file
示例#2
0
    def __init__(self, generator, ecl_file):
        self.xml_file = joinpath(generator.xml_root, ecl_file + '.xml')
        self.tex_file = joinpath(generator.tex_root, ecl_file + '.tex')

        tex_relpath = relpath(self.tex_file, generator.tex_path)
        self.dirname = dirname(tex_relpath)

        self.template = generator.content_template
        self.options = generator.options

        os.makedirs(dirname(self.tex_file), exist_ok=True)
示例#3
0
    def __init__(self, generator, ecl_file):
        self.xml_file = joinpath(generator.xml_root, ecl_file + '.xml')
        self.txt_file = joinpath(generator.txt_root, ecl_file + '.txt')
        self.template = generator.content_template
        self.options = generator.options

        os.makedirs(dirname(self.txt_file), exist_ok=True)
示例#4
0
    def __init__(self, generator, ecl_file) :
        self.output_root = generator.output_root
        self.xml_file = joinpath(generator.xml_root, (ecl_file + '.xml'))
        self.html_file = joinpath(generator.html_root, (ecl_file + '.html'))
        self.template = generator.content_template

        ### Parent node of given file in path tree
        self.parent = getRoot(generator.ecl_file_tree, ecl_file)
        self.options = generator.options

        os.makedirs(dirname(self.html_file), exist_ok=True)
示例#5
0
    def parse(self) :
        tree = etree.parse(self.xml_file)
        root = tree.getroot()
        src = root.find('Source')
        self.src = src
        self.doc = src.find('Documentation')

        for child in root.iter() :
            attribs = child.attrib
            ### Convert links from XML FOrmat to HTML Format
            if 'target' in attribs :
                attribs['target'] = re.sub(r'\$\$_ECLDOC-FORM_\$\$', 'html', attribs['target'])
                attribs['target'] = re.sub(r'\.xml$', '.html', attribs['target'])

            ### Fullname act as HTML Id for Definitions
            ### '.' is invalid char in HTML Id so replaced by '-'
            if 'fullname' in attribs :
                attribs['origfn'] = attribs['fullname']
                attribs['fullname'] = re.sub(r'\.', '-', attribs['fullname'])

        self.parseSource()

        files = []
        keys = sorted(self.parent.keys(), key=str.lower)
        for key in keys :
            if type(self.parent[key]) != dict :
                file = {'name': key,
                        'target': key + '.html',
                        'type': 'file'}
                files.append(file)
            else :
                file = {'name': key,
                        'target': joinpath(key, 'pkg.toc.html'),
                        'type': 'dir'}
                files.append(file)

        files = sorted(files, key=lambda x : x['type'])

        parent = 'pkg.toc.html'
        output_relpath = relpath(self.output_root, dirname(self.html_file))
        render = self.template.render(src=src,
                                      files=files,
                                      parent=parent,
                                      output_root=output_relpath,
                                      defn_tree=self.defn_tree)
        write_to_file(self.html_file, render)
示例#6
0
    def gen(self, key, node, content_root):
        '''
        Recursively parse source tree dictionary.
        If current_node is file : parse file using parseTEX
        Else If : current_node is directory : recurse and generate pkg.toc.tex for that dir
                                              (optionally generate bundle info if present)
        :param key: string | the name of current_node in path tree
        :param node: dict | the parent tree of current_node
        :param content_root: string | real path to current node in tex doc dir
        '''
        current_node = node[key]
        if type(current_node) != dict:
            if key == 'bundle.ecl':
                return
            parser = ParseTEX(self, current_node)
            parser.parse()
            file = {'name': key, 'type': 'file', 'doc': parser.docstring()}
            file['target'] = relpath(parser.tex_file, self.tex_path)
            file['label'] = parser.src.attrib['name']
            return file
        else:
            os.makedirs(content_root, exist_ok=True)
            render_path = joinpath(content_root, 'pkg.toc.tex')
            temptoc_render_path = joinpath(content_root, 'pkg.tmp.tex')
            index_render_path = joinpath(content_root, 'index.tex')

            tex_relpath = relpath(content_root, self.tex_path)
            target_relpath = relpath(render_path, self.tex_path)

            file = {
                'name': key,
                'type': 'dir',
                'doc': '',
                'target': target_relpath,
                'label': tex_relpath
            }

            bundle = None
            if 'bundle.ecl' in current_node:
                bundle_xml_path = joinpath(self.xml_root,
                                           dirname(current_node['bundle.ecl']),
                                           'bundle.xml')
                bundle = etree.parse(bundle_xml_path).getroot()
                file['type'] = 'bundle'

            childfiles = []
            child_keys = sorted(current_node.keys(), key=str.lower)
            for chkey in child_keys:
                child_root = joinpath(content_root, chkey)
                child_dict = self.gen(chkey, current_node, child_root)
                if child_dict is not None: childfiles.append(child_dict)

            childfiles = sorted(childfiles,
                                key=lambda x: x['type'],
                                reverse=True)

            render = self.toc_template.render(name=key,
                                              files=childfiles,
                                              bundle=bundle,
                                              label=tex_relpath,
                                              up=dirname(tex_relpath))
            write_to_file(render_path, render)

            render = self.toc_template.render(
                name=key,
                files=[x for x in childfiles if x['type'] == 'file'],
                bundle=bundle,
                label=tex_relpath,
                up="")
            write_to_file(temptoc_render_path, render)

            start_path = relpath(temptoc_render_path, self.tex_path)
            render = self.index_template.render(root=start_path)
            write_to_file(index_render_path, render)

            subprocess.run([
                'pdflatex ' + '-output-directory ' +
                relpath(content_root, self.tex_path) + ' ' +
                relpath(index_render_path, self.tex_path)
            ],
                           cwd=self.tex_path,
                           shell=True)

            return file