|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# Copyright (C) 2011, 2012 p12 <tir5c3@yahoo.co.uk> |
| 4 | +# |
| 5 | +# This file is part of cppreference-doc |
| 6 | +# |
| 7 | +# This program is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU General Public License as published by |
| 9 | +# the Free Software Foundation, either version 3 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | +# |
| 12 | +# This program is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU General Public License |
| 18 | +# along with this program. If not, see http://www.gnu.org/licenses/. |
| 19 | + |
| 20 | +import fnmatch |
| 21 | +import re |
| 22 | +import os |
| 23 | + |
| 24 | +# copy the source tree |
| 25 | +os.system('rm -rf output') |
| 26 | +os.system('mkdir output') |
| 27 | +os.system('cp -rt output reference/*') |
| 28 | + |
| 29 | +# find all html and css files |
| 30 | +html_files = [] |
| 31 | +css_files = [] |
| 32 | +for root, dirnames, filenames in os.walk('output'): |
| 33 | + for filename in fnmatch.filter(filenames, '*.html'): |
| 34 | + html_files.append(os.path.join(root, filename)) |
| 35 | + for filename in fnmatch.filter(filenames, '*.css'): |
| 36 | + css_files.append(os.path.join(root, filename)) |
| 37 | + |
| 38 | +# |
| 39 | +r1 = re.compile('<!-- Added by HTTrack -->.*?<!-- \/Added by HTTrack -->') |
| 40 | +r2 = re.compile('<!-- Mirrored from .*?-->') |
| 41 | + |
| 42 | +# clean the html files |
| 43 | +for fn in html_files: |
| 44 | + f = open(fn, "r") |
| 45 | + text = f.read() |
| 46 | + f.close() |
| 47 | + |
| 48 | + text = r1.sub('', text); |
| 49 | + text = r2.sub('', text); |
| 50 | + |
| 51 | + f = open(fn, "w") |
| 52 | + f.write(text) |
| 53 | + f.close() |
| 54 | + |
| 55 | + tmpfile = fn + '.tmp'; |
| 56 | + os.system('xsltproc --novalid --html preprocess.xsl "' + fn + '" > "' + tmpfile + '"') |
| 57 | + os.system('mv "' + tmpfile + '" "' + fn + '"') |
| 58 | + |
| 59 | + |
| 60 | +os.system('cat preprocess-css.css >> "output/en.cppreference.com/mwiki/load7fe1.css"') |
0 commit comments