removed RCS keyword cruft from Last-Modified & Version headers of plaintext PEPs; added copy_aux_files() for graphics etc.; fixed reST output to include template (which contains a warning in a comment); removed unused code from main()
This commit is contained in:
parent
c5b5d3c83d
commit
4d324e8108
|
@ -212,17 +212,22 @@ def fixfile(inpath, input_lines, outfile):
|
||||||
otherpep)
|
otherpep)
|
||||||
v = otherpeps
|
v = otherpeps
|
||||||
elif k.lower() in ('last-modified',):
|
elif k.lower() in ('last-modified',):
|
||||||
date = v or time.strftime('%d-%b-%Y',
|
date = v or time.strftime('%Y-%m-%d',
|
||||||
time.localtime(os.stat(inpath)[8]))
|
time.localtime(os.stat(inpath)[8]))
|
||||||
|
if date.startswith('$' 'Date: ') and date.endswith(' $'):
|
||||||
|
date = date[6:-2]
|
||||||
try:
|
try:
|
||||||
url = PEPCVSURL % int(pep)
|
url = PEPCVSURL % int(pep)
|
||||||
v = '<a href="%s">%s</a> ' % (url, cgi.escape(date))
|
v = '<a href="%s">%s</a> ' % (url, cgi.escape(date))
|
||||||
except ValueError, error:
|
except ValueError, error:
|
||||||
v = date
|
v = date
|
||||||
elif k.lower() in ('content-type',):
|
elif k.lower() == 'content-type':
|
||||||
url = PEPURL % 9
|
url = PEPURL % 9
|
||||||
pep_type = v or 'text/plain'
|
pep_type = v or 'text/plain'
|
||||||
v = '<a href="%s">%s</a> ' % (url, cgi.escape(pep_type))
|
v = '<a href="%s">%s</a> ' % (url, cgi.escape(pep_type))
|
||||||
|
elif k.lower() == 'version':
|
||||||
|
if v.startswith('$' 'Revision: ') and v.endswith(' $'):
|
||||||
|
v = cgi.escape(v[11:-2])
|
||||||
else:
|
else:
|
||||||
v = cgi.escape(v)
|
v = cgi.escape(v)
|
||||||
print >> outfile, (' <tr><th class="field-name">%s: </th>'
|
print >> outfile, (' <tr><th class="field-name">%s: </th>'
|
||||||
|
@ -292,7 +297,7 @@ def fix_rst_pep(inpath, input_lines, outfile):
|
||||||
settings=docutils_settings,
|
settings=docutils_settings,
|
||||||
# Allow Docutils traceback if there's an exception:
|
# Allow Docutils traceback if there's an exception:
|
||||||
settings_overrides={'traceback': 1})
|
settings_overrides={'traceback': 1})
|
||||||
outfile.write(parts['body'])
|
outfile.write(parts['whole'])
|
||||||
title = 'PEP %s -- %s' % (parts['pepnum'], parts['title'][0])
|
title = 'PEP %s -- %s' % (parts['pepnum'], parts['title'][0])
|
||||||
return title
|
return title
|
||||||
|
|
||||||
|
@ -365,6 +370,7 @@ def make_html(inpath, verbose=0):
|
||||||
# for PEP 0, copy body to parent directory as well
|
# for PEP 0, copy body to parent directory as well
|
||||||
if pepnum == '0000':
|
if pepnum == '0000':
|
||||||
shutil.copyfile(outpath, os.path.join(destDir, '..', 'body.html'))
|
shutil.copyfile(outpath, os.path.join(destDir, '..', 'body.html'))
|
||||||
|
copy_aux_files(inpath, destDir)
|
||||||
return outpath
|
return outpath
|
||||||
|
|
||||||
def set_up_pyramid(inpath):
|
def set_up_pyramid(inpath):
|
||||||
|
@ -401,6 +407,20 @@ def write_pyramid_index(destDir, title):
|
||||||
fp.close()
|
fp.close()
|
||||||
os.chmod(filename, 0664)
|
os.chmod(filename, 0664)
|
||||||
|
|
||||||
|
def copy_aux_files(pep_path, dest_dir):
|
||||||
|
"""
|
||||||
|
Copy auxiliary files whose names match 'pep-XXXX-*.*'.
|
||||||
|
"""
|
||||||
|
dirname, pepname = os.path.split(pep_path)
|
||||||
|
base, ext = os.path.splitext(pepname)
|
||||||
|
files = glob.glob(os.path.join(dirname, base) + '-*.*')
|
||||||
|
for path in files:
|
||||||
|
filename = os.path.basename(path)
|
||||||
|
dest_path = os.path.join(dest_dir, filename)
|
||||||
|
print '%s -> %s' % (path, dest_path)
|
||||||
|
shutil.copy(path, dest_path)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PEP_TYPE_DISPATCH = {'text/plain': fixfile,
|
PEP_TYPE_DISPATCH = {'text/plain': fixfile,
|
||||||
'text/x-rst': fix_rst_pep}
|
'text/x-rst': fix_rst_pep}
|
||||||
|
@ -466,25 +486,15 @@ def main(argv=None):
|
||||||
verbose = 0
|
verbose = 0
|
||||||
|
|
||||||
if args:
|
if args:
|
||||||
peptxt = []
|
|
||||||
html = []
|
|
||||||
for pep in args:
|
for pep in args:
|
||||||
file = find_pep(pep)
|
filename = find_pep(pep)
|
||||||
peptxt.append(file)
|
make_html(filename, verbose=verbose)
|
||||||
newfile = make_html(file, verbose=verbose)
|
|
||||||
if newfile:
|
|
||||||
html.append(newfile)
|
|
||||||
else:
|
else:
|
||||||
# do them all
|
# do them all
|
||||||
peptxt = []
|
|
||||||
html = []
|
|
||||||
files = glob.glob("pep-*.txt")
|
files = glob.glob("pep-*.txt")
|
||||||
files.sort()
|
files.sort()
|
||||||
for file in files:
|
for filename in files:
|
||||||
peptxt.append(file)
|
make_html(filename, verbose=verbose)
|
||||||
newfile = make_html(file, verbose=verbose)
|
|
||||||
if newfile:
|
|
||||||
html.append(newfile)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue