From 5772b7cdf3f8823a1b3b12cf15e6e08732d1b2c8 Mon Sep 17 00:00:00 2001 From: nicholasyang Date: Mon, 8 Apr 2024 16:20:06 +0800 Subject: [PATCH] Dev: doc/website-v1: adapt to python3 (#1374) --- doc/website-v1/make-news.py | 4 ++-- doc/website-v1/postprocess.py | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/doc/website-v1/make-news.py b/doc/website-v1/make-news.py index f3c9073856..c9c2c00bfb 100644 --- a/doc/website-v1/make-news.py +++ b/doc/website-v1/make-news.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """ Output a combined news.adoc document Also write an Atom feed document @@ -63,7 +63,7 @@ def __init__(self, fname): raise ValueError("Missing date") def atom_id(self): - return root_id + '::' + hashlib.sha1(self.filename).hexdigest() + return root_id + '::' + hashlib.sha1(self.filename.encode('utf-8')).hexdigest() def atom_date(self): return self.date.replace(' ', 'T') + ':00' + time.tzname[0] diff --git a/doc/website-v1/postprocess.py b/doc/website-v1/postprocess.py index 859abaa566..5dd153886e 100644 --- a/doc/website-v1/postprocess.py +++ b/doc/website-v1/postprocess.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # create a table of contents for pages that need it import sys @@ -6,6 +6,7 @@ import argparse TOC_PAGES = ['man/index.html', + 'man-4.6/index.html', 'man-4.3/index.html', 'man-3/index.html', 'man-2.0/index.html', @@ -48,7 +49,7 @@ def read_toc_data(infile, debug): def generate_toc(infile, outfile, debug): if debug: - print "Infile:", infile + print(f"Infile: {infile}") toc = read_toc_data(infile, debug) ''' toc_data = [] @@ -73,11 +74,11 @@ def generate_toc(infile, outfile, debug): # Write TOC to outfile if outfile: if debug: - print "Writing TOC:" - print "----" - print toc - print "----" - print "Outfile:", outfile + print("Writing TOC:") + print("----") + print(toc) + print("----") + print(f"Outfile: {outfile}") fil = open(outfile) f = fil.readlines() fil.close() @@ -96,14 +97,14 @@ def generate_v2(page, debug): m = section.match(line) if m: if debug: - print "toc_data: %s" % str(((m.group('depth'), m.group('text'), m.group('id')))) + print("toc_data: %s" % str(((m.group('depth'), m.group('text'), m.group('id'))))) toc_data.append((m.group('depth'), m.group('text'), m.group('id'))) toc = '' if len(toc_data) > 0: toc = '
\n' for depth, text, link in toc_data: - if depth >= 2 and link is not None: + if int(depth) >= 2 and link is not None: toc += '\n' % ( int(depth) - 1, link, text) toc += '
\n' @@ -126,7 +127,7 @@ def main(): debug = args.debug outfile = args.output infile = args.input - print "+ %s -> %s" % (infile, outfile) + print("+ %s -> %s" % (infile, outfile)) gen = False for tocpage in TOC_PAGES: if not gen and outfile.endswith(tocpage):