Changeset 87716 in vbox
- Timestamp:
- Feb 11, 2021 7:54:41 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/manual/htmlhelp-qthelp.py
r87630 r87716 1 #!/usr/bin/python 1 #!/usr/bin/python3 2 2 3 3 # $Id$ 4 4 ## @file 5 # A python 2.x script to create a .qhp file outof a given htmlhelp5 # A python script to create a .qhp file out of a given htmlhelp 6 6 # folder. Lots of things about the said folder is assumed. Please 7 # readthe code and inlined comments.7 # see the code and inlined comments. 8 8 9 9 import sys, getopt … … 12 12 import codecs 13 13 import logging 14 from HTMLParser import HTMLParser 14 15 if sys.version_info.major >= 3: 16 from html.parser import HTMLParser 17 else: 18 from HTMLParser import HTMLParser 19 15 20 16 21 __copyright__ = \ … … 27 32 """ 28 33 29 30 34 # number of opened and not yet closed section tags of toc section 31 35 open_section_tags = 0 32 36 33 37 html_files = [] 34 35 class html_parser(HTMLParser):36 def __init__(self):37 HTMLParser.__init__(self)38 self.a_tag=[]39 40 def handle_starttag(self, tag, attributes):41 if tag != 'div' and tag != 'a':42 return43 if tag == 'a':44 for a in attributes:45 if a[0] == 'name':46 self.a_tag.append(a[1])47 38 48 39 # use html_parser stuff to collect <a name tags … … 51 42 for html_file_name in html_files: 52 43 full_html_path = os.path.join(folder, html_file_name) 53 file_content = open(full_html_path, 'r').read() 44 file_content = codecs.open(full_html_path, encoding='iso-8859-1').read() 45 46 class html_parser(HTMLParser): 47 def __init__(self): 48 HTMLParser.__init__(self) 49 self.a_tag=[] 50 def handle_starttag(self, tag, attributes): 51 if tag != 'div' and tag != 'a': 52 return 53 if tag == 'a': 54 for a in attributes: 55 if a[0] == 'name': 56 self.a_tag.append(a[1]) 57 54 58 parser = html_parser() 55 59 parser.feed(file_content) … … 86 90 return html_file_lines 87 91 full_path = os.path.join(folder, 'htmlhelp.hhp') 88 file = open(full_path, "r") 92 file = codecs.open(full_path, encoding='iso-8859-1') 93 89 94 lines = file.readlines() 90 95 file.close() … … 135 140 logging.warning('Skipping the line "%s" since next two tags are supposed to be param tags', lines[index]) 136 141 return result 137 138 142 title = parse_param_tag(lines[index + 1]) 139 143 ref = parse_param_tag(lines[index + 2]) … … 175 179 176 180 # parse toc.hhc file. assuming all the relevant information 177 # is stored in tags and attributes. data "whatever is outside of181 # is stored in tags and attributes. whatever is outside of 178 182 # <... > pairs is filtered out. we also assume < ..> are not nested 179 183 # and each < matches to a > … … 218 222 219 223 def usage(arg): 220 print 'htmlhelp-qthelp.py -d <helphtmlfolder> -o <outputfilename>'221 sys.exit( arg)224 print('htmlhelp-qthelp.py -d <helphtmlfolder> -o <outputfilename>') 225 sys.exit() 222 226 223 227 def main(argv): … … 227 231 opts, args = getopt.getopt(sys.argv[1:],"hd:o:") 228 232 except getopt.GetoptError as err: 229 print err233 print(err) 230 234 usage(2) 231 235 for opt, arg in opts: … … 260 264 out_xml_lines += ['</filterSection>', '</QtHelpProject>'] 261 265 262 out_file = open(output_filename, 'w ')266 out_file = open(output_filename, 'wb') 263 267 out_file.write('\n'.join(out_xml_lines).encode('utf8')) 264 268 out_file.close()
Note:
See TracChangeset
for help on using the changeset viewer.