File: qthelp_generator.py

package info (click to toggle)
cantor 4%3A25.04.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,828 kB
  • sloc: cpp: 43,775; ansic: 5,802; pascal: 1,027; python: 642; xml: 457; sh: 308; makefile: 207; lisp: 91
file content (136 lines) | stat: -rw-r--r-- 4,930 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#
#     This program is free software; you can redistribute it and/or
#     modify it under the terms of the GNU General Public License
#     as published by the Free Software Foundation; either version 2
#     of the License, or (at your option) any later version.

#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.

#     You should have received a copy of the GNU General Public License
#     along with this program; if not, write to the Free Software
#     Foundation, Inc., 51 Franklin Street, Fifth Floor,
#     Boston, MA  02110-1301, USA.

#     ---
#     Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
#

# Script to parse index and generate a txt file containing all the keywords
# and then generate QtHelp files using the keywords generated

import os
import re
from bs4 import BeautifulSoup

# QtHelp files
qhp = open('./help.qhp', 'w')
qhcp = open('./help.qhcp', 'w')

index = open("genindex.html", "r")

#######################################
#code for generation of QtHelp files##
######################################

# populate qhp file with headers and table of contents
qhp.writelines("""<?xml version="1.0" encoding="UTF-8"?>
<QtHelpProject version="1.0">
    <namespace>org.kde.numpy.1.19</namespace>

    <virtualFolder>doc</virtualFolder>
    
    <customFilter name="NumPy">
        <filterAttribute>NumPy Documentation</filterAttribute>
        <filterAttribute>1.19</filterAttribute>
    </customFilter>
    
    <filterSection>
        <toc>
            <section title="NumPy v1.19 Manual" ref="index.html">
                <section title="For users:" ref="index.html">
                    <section title="Setting Up" ref="user/setting-up.html"></section>
                    <section title="Quickstart Tutorial" ref="user/quickstart.html"></section>
                    <section title="Absolute Beginners Tutorial" ref="user/absolute_beginners.html"></section>
                    <section title="Tutorials" ref="user/tutorials_index.html"></section>
                    <section title="How Tos" ref="user/howtos_index.html"></section>
                    <section title="NumPy API Reference" ref="reference/index.html"></section>
                    <section title="Explanations" ref="user/explanations_index.html"></section>
                    <section title="F2Py Guide" ref="f2py/index.html"></section>
                    <section title="Glossary" ref="glossary.html"></section>
                </section>
            </section>
        </toc>\n
        <keywords>""")

# code to write keywords to qhp file
html = index.read()
soup = BeautifulSoup(html, features='html.parser')

for i in soup.find_all('a'):
    # replace the characters which produces error while qhcp file
    keyword = i.text.replace("<", "").replace("&", "")
    keyword = re.sub(r" ?\([^)]+\)", "", keyword)
    link = i['href']
    
    if keyword != "":
        line = '<keyword name = "{}" ref = "{}"/>\n'.format(keyword, link)
        qhp.write(line)

# write the tail
qhp.writelines("""</keywords>
            <files>
            <file>./*</file>
            <file>_static/*</file>
            <file>_static/img/*</file>
            <file>_images/*</file>
            <file>_images/math/*</file>
            <file>_sources/*</file>
            <file>dev/*</file>
            <file>dev/conducct/*</file>
            <file>dev/gitwash/*</file>
            <file>dev/gitwash/governance/*</file>
            <file>docs/*</file>
            <file>f2py/*</file>
            <file>reference/*</file>
            <file>reference/c-api/*</file>
            <file>reference/dist-utils/*</file>
            <file>reference/generated/*</file>
            <file>reference/random/*</file>
            <file>release/*</file>
            <file>user/*</file>
            <file>user/plots/*</file>
        </files>
    </filterSection>
</QtHelpProject> """)

# populate qhcp file
qhcp.writelines("""<?xml version="1.0" encoding="utf-8" ?>
            <QHelpCollectionProject version="1.0">

                <docFiles>
                    <generate>
                        <file>
                            <input>help.qhp</input>
                            <output>help.qch</output>
                        </file>
                    </generate>

                    <register>
                        <file>help.qch</file>
                    </register>
                </docFiles>

            </QHelpCollectionProject>""")

##############################################################
#qhp, qhcp input files are generate, now generate output files
#############################################################

stream = os.popen('qhelpgenerator help.qhcp -o help.qhc')

qhp.close()
qhcp.close()
index.close()