VirtualBox

Changeset 87716 in vbox


Ignore:
Timestamp:
Feb 11, 2021 7:54:41 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9831. Attempting to make htmlhelp-qthelp.py Python 3 friendly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/manual/htmlhelp-qthelp.py

    r87630 r87716  
    1 #!/usr/bin/python
     1#!/usr/bin/python3
    22
    33# $Id$
    44## @file
    5 # A python 2.x script to create a .qhp file outof a given htmlhelp
     5# A python script to create a .qhp file out of a given htmlhelp
    66# folder. Lots of things about the said folder is assumed. Please
    7 # read the code and inlined comments.
     7# see the code and inlined comments.
    88
    99import sys, getopt
     
    1212import codecs
    1313import logging
    14 from HTMLParser import HTMLParser
     14
     15if sys.version_info.major >= 3:
     16    from html.parser import HTMLParser
     17else:
     18    from HTMLParser import HTMLParser
     19
    1520
    1621__copyright__ = \
     
    2732"""
    2833
    29 
    3034# number of opened and not yet closed section tags of toc section
    3135open_section_tags = 0
    3236
    3337html_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         return
    43     if tag == 'a':
    44         for a in attributes:
    45             if a[0] == 'name':
    46                 self.a_tag.append(a[1])
    4738
    4839# use html_parser stuff to collect <a name tags
     
    5142    for html_file_name in html_files:
    5243        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
    5458        parser = html_parser()
    5559        parser.feed(file_content)
     
    8690        return html_file_lines
    8791    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
    8994    lines = file.readlines()
    9095    file.close()
     
    135140        logging.warning('Skipping the line "%s" since next two tags are supposed to be param tags',  lines[index])
    136141        return result
    137 
    138142    title = parse_param_tag(lines[index + 1])
    139143    ref = parse_param_tag(lines[index + 2])
     
    175179
    176180# parse toc.hhc file. assuming all the relevant information
    177 # is stored in tags and attributes. data "whatever is outside of
     181# is stored in tags and attributes. whatever is outside of
    178182# <... > pairs is filtered out. we also assume < ..> are not nested
    179183# and each < matches to a >
     
    218222
    219223def 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()
    222226
    223227def main(argv):
     
    227231        opts, args = getopt.getopt(sys.argv[1:],"hd:o:")
    228232    except getopt.GetoptError as err:
    229         print err
     233        print(err)
    230234        usage(2)
    231235    for opt, arg in opts:
     
    260264    out_xml_lines += ['</filterSection>', '</QtHelpProject>']
    261265
    262     out_file = open(output_filename, 'w')
     266    out_file = open(output_filename, 'wb')
    263267    out_file.write('\n'.join(out_xml_lines).encode('utf8'))
    264268    out_file.close()
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette