def outline(self): cmd = [] cmd.append(self.zen.get_ctags_exepath()) cmd.append('--excmd=number') cmd.append('-f -') cmd.append('--fields=+zK') cmd.append(self.file) output = self.zen.run_ctags(cmd) # Harvest info = {} for item in output: print(item) type = item[3].replace('kind:','') name = item[0] lineno = item[2] if type not in info: info[type] = [] info[type].append({'name':name, 'lineno':lineno}) # Publish for item_type in info.keys(): type_root = outliner.myNode(item_type.title(), item_type, 'nonumber', self.root) for token in info[item_type]: outliner.myNode(token['name'], item_type, token['lineno'], type_root)
def test_html_file(self): """Test file using Python HtmlParser""" try: MyHtmlParser(self.file) except Exception as e: print("Error python HTML Parser. ", e) error_template = string.Template("""Line $line Column $col Message $message""") error_msg = error_template.safe_substitute(line=str(e.lineno), col=str(e.offset), message=e.msg) outliner.myNode(error_msg, error_msg, "nonumber", self.root)
def outline(self): """Find document childs and create the QTreeview nodes""" tree = self.get_xml(self.file) if tree == "not": return doc_root = tree.getroot() _root = outliner.myNode(doc_root.tag, doc_root.tag, "nonumber", self.root) els = doc_root.findall("*") for item in els: self.add_child(item, _root)
def add_child(self, item, parent): node_text = item.tag node_line = item.sourceline # todo : specify which atribs to show setting = self.prefs.get_setting("SourceBrowser/ShowHtml_XmlAtributtes", False) if setting == True: for attrib, value in item.items(): node_text += " " + attrib + "=" + value node = outliner.myNode(node_text, node_text, node_line, parent) for child in item.getchildren(): self.add_child(child, node)
def get_xml(self, filename): """Parse HTML or XML file. Use both Python HTML Parser and lxml parsers for HTML. Only the lxml parser is used to populate the QTreeview. """ tree = "not" try: if self.language == "HTML": self.test_html_file() parser = etree.HTMLParser() if self.language == "xml": parser = etree.XMLParser() tree = etree.parse(filename, parser) except Exception as e: print("Error could not get xml or html file", e) error = parser.error_log[0] error_template = string.Template("""Line $line Column $col Message $message""") error_msg = error_template.safe_substitute( line=str(error.line), col=str(error.column), message=error.message ) outliner.myNode(error_msg, error_msg, "nonumber", self.root) return tree
def outline(self): cmd = [] cmd.append(self.zen.get_ctags_exepath()) cmd.append('--excmd=number') cmd.append('-f -') cmd.append('--fields=+zK') cmd.append(self.file) output = self.zen.run_ctags(cmd) members = [] classes = [] namespaces = [] variables = [] functions = [] ####################################################################### # Harvest for item in output: type = item[3] name = item[0] lineno = item[2] if type == 'kind:namespace': namespaces.append({'name':name, 'lineno':lineno}) if type == 'kind:function': functions.append({'name':name, 'lineno':lineno}) if type == 'kind:class': classes.append({'name':name, 'lineno':lineno}) if type == 'kind:member': if len(item) > 4: # method belongs to class members.append({'name':name, 'class':item[4].replace('class:', ''), 'lineno':lineno}) elif len(item) <= 4: # method do not belong to class members.append({'name':name, 'lineno':lineno}) if type == 'kind:variable': if len(item) > 4: # variable belongs to class variables.append({'name':name, 'class':item[4].replace('class:', ''), 'lineno':lineno}) elif len(item) <= 4: # variable do not belong to class variables.append({'name':name, 'lineno':lineno}) ####################################################################### # Publish # Get classes for class_ in classes: class_node = outliner.myNode(class_['name'], 'class', class_['lineno'], self.root) for var in variables: if 'class' in var: if var['class'] == class_['name']: outliner.myNode(var['name'], 'variable', var['lineno'], class_node) for member in members: if 'class' in member: if member['class'] == class_['name']: outliner.myNode(member['name'], 'member', member['lineno'], class_node) # Get variables not belonging to a class for var in variables: if 'class' not in var: outliner.myNode(var['name'], 'variable', var['lineno'], self.root) # Get functions for func in functions: outliner.myNode(func['name'], 'function', func['lineno'], self.root) # Get methods not belonging to a class for member in members: if 'class' not in member: outliner.myNode(member['name'], 'member', member['lineno'], self.root) # Get imports for namespace in namespaces: outliner.myNode(namespace['name'], 'namespace', namespace['lineno'], self.root)