pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/doc/guide doc/guide: use Python instead of Perl for au...
details: https://anonhg.NetBSD.org/pkgsrc/rev/4cecdb46173c
branches: trunk
changeset: 395060:4cecdb46173c
user: rillig <rillig%pkgsrc.org@localhost>
date: Mon Apr 29 16:18:41 2019 +0000
description:
doc/guide: use Python instead of Perl for autogenerating help topics
The code is shorter and there's less line noise.
diffstat:
doc/guide/Makefile | 9 +++--
doc/guide/files/generate-help-topics.pl | 49 ---------------------------------
doc/guide/files/help-topics.gen.py | 31 ++++++++++++++++++++
3 files changed, 36 insertions(+), 53 deletions(-)
diffs (125 lines):
diff -r c0d8e16bd91e -r 4cecdb46173c doc/guide/Makefile
--- a/doc/guide/Makefile Mon Apr 29 16:09:05 2019 +0000
+++ b/doc/guide/Makefile Mon Apr 29 16:18:41 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.53 2019/04/28 15:22:24 rillig Exp $
+# $NetBSD: Makefile,v 1.54 2019/04/29 16:18:41 rillig Exp $
DISTNAME= pkgsrc-guide-${PKGVERSION}
CATEGORIES= # empty
@@ -16,7 +16,6 @@
DIST_SUBDIR= ${PKGBASE}
USE_LANGUAGES= # empty
MAKE_ENV+= SED=${SED:Q}
-USE_TOOLS+= perl
PLIST_VARS= ascii html pdf
@@ -64,10 +63,10 @@
${MKDIR} ${WRKSRC}
${LN} -s ${FILESDIR}/* ${WRKSRC}
-post-extract: generate-help-topics
+pre-configure: generate-help-topics
generate-help-topics: .PHONY
${RUN} ${MAKE} help topic=:index > ${WRKSRC}/help-topics.data
- ${RUN} cd ${WRKSRC} && perl generate-help-topics.pl
+ ${RUN} cd ${WRKSRC} && python help-topics.gen.py
do-build:
.for _output_ in ${OUTPUTS}
@@ -157,4 +156,6 @@
-s ',^,htdocs/,' \
global.css share
+PYTHON_FOR_BUILD_ONLY= tool
+.include "../../lang/python/tool.mk"
.include "../../mk/bsd.pkg.mk"
diff -r c0d8e16bd91e -r 4cecdb46173c doc/guide/files/generate-help-topics.pl
--- a/doc/guide/files/generate-help-topics.pl Mon Apr 29 16:09:05 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-#! perl
-# $NetBSD: generate-help-topics.pl,v 1.1 2019/04/28 15:22:24 rillig Exp $
-
-use strict;
-use warnings;
-
-my $tmpl_file = "help-topics.tmpl.xml";
-my $data_file = "help-topics.data";
-my $out_file = "help-topics.xml";
-
-sub read_topics() {
- my @xmltopics;
- open(my $topics, "<", $data_file) or die;
- my $header1 = <$topics>;
- my $header2 = <$topics>;
-
- while (defined(my $topic = <$topics>)) {
- chomp($topic);
- $topic =~ s,&,\&,g;
- $topic =~ s,<,\<,g;
- push(@xmltopics, $topic);
- }
-
- close($topics) or die;
- return @xmltopics;
-}
-
-sub merge() {
- open(my $tmpl, "<", $tmpl_file) or die;
- open(my $out, ">", "$out_file.tmp") or die;
-
- while (defined(my $tmpl_line = <$tmpl>)) {
- if ($tmpl_line =~ /\@topic\@/) {
- foreach my $xmltopic (read_topics()) {
- my $line = $tmpl_line;
- $line =~ s,\@topic\@,$xmltopic,e;
- print $out ($line);
- }
- } else {
- print $out ($tmpl_line);
- }
- }
- close($tmpl) or die;
- close($out) or die;
-
- rename("$out_file.tmp", $out_file) or die;
-}
-
-merge();
diff -r c0d8e16bd91e -r 4cecdb46173c doc/guide/files/help-topics.gen.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/guide/files/help-topics.gen.py Mon Apr 29 16:18:41 2019 +0000
@@ -0,0 +1,31 @@
+#! python
+# $NetBSD: help-topics.gen.py,v 1.1 2019/04/29 16:18:41 rillig Exp $
+
+import os
+
+tmpl_file = "help-topics.tmpl.xml"
+data_file = "help-topics.data"
+out_file = "help-topics.xml"
+
+
+def merge():
+ def read_lines(filename):
+ with open(filename) as f:
+ return f.readlines()
+
+ out = []
+ for tmpl_line in read_lines(tmpl_file):
+ if '@topic@' in tmpl_line:
+ for topic in read_lines(data_file)[2:]:
+ xml_topic = topic.replace('&', '%amp;').replace('<', '<')
+ out.append(tmpl_line.replace('@topic@', xml_topic))
+ else:
+ out.append(tmpl_line)
+
+ with open(f'{out_file}.tmp', 'w') as f:
+ f.writelines(out)
+ os.rename(f'{out_file}.tmp', out_file)
+
+
+if __name__ == '__main__':
+ merge()
Home |
Main Index |
Thread Index |
Old Index