I think this new version fixes some of the problems with the one we've
used previously. However, I'd like others to eyeball it and let me know
if they find problems with any of their inputs. Best way to test it, of
course, is to use it in a web sandbox with the SOP for fedora.redhat.com
publishing. Yes, I know that will go away. One day soon. Some day.
Eventually. :-) Until then, try this out and let me know if you see
anything borken.
--
Paul W. Frields, RHCE http://paul.frields.org/
gpg fingerprint: 3DA6 A0AC 6D58 FEC4 0233 5906 ACDB C937 BD11 3717
Fedora Project Board: http://fedoraproject.org/wiki/Board
Fedora Docs Project: http://fedoraproject.org/wiki/DocsProject
#!/usr/bin/python
#
# Convert HTML generated from DocBook (i.e. xmlto) to PHP files for
# fedora.redhat.com website
# Copyright (C) 2006 Paul W. Frields <stickster gmail com>
# This script is licensed under the GNU General Public License (GPL) v2.0.
#
# Designed after Tammy Fox's original script (C) 2003.
import sys, os
import re
from glob import glob
_debug = 0
html_files = sys.argv[1:]
mungelist = []
def mungeFileRefs(fname, htmlfilename):
try:
f = open(fname, 'r')
except:
print "Cannot open file", fname
sys.exit(10)
else:
data = f.read()
f.close()
try:
f = open(fname, 'w')
except:
print "Cannot write to file", fname
sys.exit(11)
else:
f.write(data.replace(htmlfilename,
htmlfilename.replace('.html', '.php')))
f.close()
if html_files == []:
print "Usage: docbookhtml2php.py <html_files>"
sys.exit(2)
if _debug: print html_files
for file in html_files:
try:
infile = open(file, "r")
except:
print "Could not open file", file
sys.exit(3)
else:
content = infile.read()
infile.close()
header_include = ''.join(['<?\n\n',
'include("site.inc");\n',
'$template = new Page;\n',
'$template->initCommon();\n',
'$template->displayHeader();\n\n',
'?>\n\n'])
# The PHP "Date" string is broken up to prevent CVS from seeing it
footer_include = ''.join(['\n',
'<?\n\n',
'$template->displayFooter(',
"'$", 'Date', "$'",
');\n\n',
'?>\n'])
content = re.sub('<.*alink.*?>', header_include, content)
content = re.sub('<\/body.*>', footer_include, content)
phpfilename = file.split('.html')[0] + '.php'
try:
outfile = open(phpfilename, 'w')
except:
print "Could not open output file", phpfilename
sys.exit(4)
else:
outfile.write(content)
outfile.close()
mungelist.append(file)
if _debug: print mungelist
phpfiles = glob("*.php")
for phpfile in phpfiles:
for m in mungelist:
mungeFileRefs(phpfile, m)
Attachment:
signature.asc
Description: This is a digitally signed message part