From: Tomi Ollila Date: Fri, 8 Mar 2013 16:32:23 +0000 (+0200) Subject: [PATCH 1/1] devel: add post-release tools news2wiki.pl and man-to-mdwn.pl X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=eaea34f776232c96d8882c834521acba1eea94b0;p=notmuch-archives.git [PATCH 1/1] devel: add post-release tools news2wiki.pl and man-to-mdwn.pl --- diff --git a/99/68fe87ccf7d13c03bb2a65146ddc89e11c0066 b/99/68fe87ccf7d13c03bb2a65146ddc89e11c0066 new file mode 100644 index 000000000..a638f3277 --- /dev/null +++ b/99/68fe87ccf7d13c03bb2a65146ddc89e11c0066 @@ -0,0 +1,370 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 55ED4431FAF + for ; Fri, 8 Mar 2013 08:32:41 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id M0cftwnvtSsH for ; + Fri, 8 Mar 2013 08:32:38 -0800 (PST) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id CF9DF431FAE + for ; Fri, 8 Mar 2013 08:32:37 -0800 (PST) +Received: by guru.guru-group.fi (Postfix, from userid 501) + id A6BA1100650; Fri, 8 Mar 2013 18:32:25 +0200 (EET) +From: Tomi Ollila +To: notmuch@notmuchmail.org +Subject: [PATCH 1/1] devel: add post-release tools news2wiki.pl and + man-to-mdwn.pl +Date: Fri, 8 Mar 2013 18:32:23 +0200 +Message-Id: <1362760343-32620-1-git-send-email-tomi.ollila@iki.fi> +X-Mailer: git-send-email 1.8.0 +Cc: tomi.ollila@iki.fi +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Fri, 08 Mar 2013 16:32:41 -0000 + +After new notmuch release has been published the NEWS and manual +pages have been updated using these 2 programs. + +Adding the tools to notmuch repository eases their use, adds more +transparency to the "process" and gives more people chance to +do the updates is one is unavailable to do it at the time being. +--- + devel/man-to-mdwn.pl | 197 +++++++++++++++++++++++++++++++++++++++++++++++++++ + devel/news2wiki.pl | 102 ++++++++++++++++++++++++++ + 2 files changed, 299 insertions(+) + create mode 100755 devel/man-to-mdwn.pl + create mode 100755 devel/news2wiki.pl + +diff --git a/devel/man-to-mdwn.pl b/devel/man-to-mdwn.pl +new file mode 100755 +index 0000000..4b59bd6 +--- /dev/null ++++ b/devel/man-to-mdwn.pl +@@ -0,0 +1,197 @@ ++#!/usr/bin/perl ++# ++# Author: Tomi Ollila ++# License: same as notmuch ++# ++# This program is used to generate mdwn-formatted notmuch manual pages ++# for notmuch wiki. Example run: ++# ++# $ ./devel/man-to-mdwn.pl man ../notmuch-wiki ++# ++# In case taken into more generic use, modify these comments and examples. ++ ++use 5.8.1; ++use strict; ++use warnings; ++ ++unless (@ARGV == 2) { ++ warn "\n$0 \n\n"; ++ # Remove/edit this comment if this script is taken into generic use. ++ warn "Example: ./devel/man-to-mdwn.pl man ../notmuch-wiki\n\n"; ++ exit 1; ++} ++ ++die "'$ARGV[0]': no such source directory\n" unless -d $ARGV[0]; ++die "'$ARGV[1]': no such destination directory\n" unless -d $ARGV[1]; ++ ++#die "'manpages' exists\n" if -e 'manpages'; ++#die "'manpages.mdwn' exists\n" if -e 'manpages.mdwn'; ++ ++die "Expecting '$ARGV[1]/manpages' to exist.\n" . ++ "Please create it first or adjust .\n" ++ unless -d $ARGV[1] . '/manpages'; ++ ++my $ev = 0; ++my %fhash; ++ ++open P, '-|', 'find', $ARGV[0], qw/-name *.[0-9] -print/; ++while (

) ++{ ++ chomp; ++ next unless -f $_; # follows symlink. ++ $ev = 1, warn "'$_': no such file\n" unless -f $_; ++ my ($in, $on) = ($_, $_); ++ $on =~ s|.*/||; $on =~ tr/./-/; ++ my $f = $fhash{$on}; ++ $ev = 1, warn "'$in' collides with '$f' ($on.mdwn)\n" if defined $f; ++ $fhash{$on} = $in; ++} ++close P; ++ ++#undef $ENV{'GROFF_NO_SGR'}; ++#delete $ENV{'GROFF_NO_SGR'}; ++$ENV{'GROFF_NO_SGR'} = '1'; ++$ENV{'TERM'} = 'vt100'; # does this matter ? ++ ++my %htmlqh = qw/& & < < > > ' ' " "/; ++# do html quotation to $_[0] (which is an alias to the given arg) ++sub htmlquote($) ++{ ++ $_[0] =~ s/([&<>'"])/$htmlqh{$1}/ge; ++} ++ ++sub maymakelink($); ++sub mayconvert($$); ++ ++#warn keys %fhash, "\n"; ++ ++while (my ($k, $v) = each %fhash) ++{ ++ #next if -l $v; # skip symlinks here. -- not... references there may be. ++ ++ my @lines; ++ #open I, '-|', qw/groff -man -T utf8/, $v; ++ open I, '-|', qw/groff -man -T latin1/, $v; # this and GROFF_NO_SGR='1' ++ ++ my ($emptyline, $pre, $hl) = (0, 0, 'h1'); ++ while () { ++ if (/^\s*$/) { ++ $emptyline = 1; ++ next; ++ } ++ s/(?<=\S)\s{8,}.*//; # $hl = 'h1' if s/(?<=\S)\s{8,}.*//; ++ htmlquote $_; ++ s/[_&]\010&/&/g; ++ s/((?:_\010[^_])+)/$1<\/u>/g; ++ s/_\010(.)/$1/g; ++ s/((?:.\010.)+)/$1<\/b>/g; ++ s/.\010(.)/$1/g; ++ ++ if (/^\S/) { ++ $pre = 0, push @lines, "\n" if $pre; ++ s/<\/?b>//g; ++ chomp; ++ $_ = "\n<$hl>$_\n"; ++ $hl = 'h2'; ++ $emptyline = 0; ++ } ++ elsif (/^\s\s\s\S/) { ++ $pre = 0, push @lines, "\n" if $pre; ++ s/(?:^\s+)?<\/?b>//g; ++ chomp; ++ $_ = "\n

  $_

\n"; ++ $emptyline = 0; ++ } ++ else { ++ $pre = 1, push @lines, "
\n" unless $pre;
++	    $emptyline = 0, push @lines, "\n" if $emptyline;
++	}
++	push @lines, $_;
++    }
++    $lines[0] =~ s/^\n//;
++    $k = "$ARGV[1]/manpages/$k.mdwn";
++    open O, '>', $k or die;
++    print STDOUT 'Writing ', "'$k'\n";
++    select O;
++    my $pe = '';
++    foreach (@lines) {
++	if ($pe) {
++	    if (s/^(\s+)([^<]+)<\/b>\((\d+)\)//) {
++		my $link = maymakelink "$pe-$2-$3";
++		$link = maymakelink "$pe$2-$3" unless $link;
++		if ($link) {
++		    print "$pe-\n";
++		    print "$1$2($3)";
++		}
++		else {
++		    print "$pe-\n";
++		    print "$1$2($3)";
++		}
++	    } else {
++		print "$pe-\n";
++	    }
++	    $pe = '';
++	}
++	s/([^<]+)<\/b>\((\d+)\)/mayconvert($1, $2)/ge;
++	$pe = $1 if s/([^<]+)-<\/b>\s*$//;
++	print $_;
++    }
++}
++
++sub maymakelink($)
++{
++#    warn "$_[0]\n";
++    return "../$_[0]/" if exists $fhash{$_[0]};
++    return '';
++}
++
++sub mayconvert($$)
++{
++    my $f = "$_[0]-$_[1]";
++#    warn "$f\n";
++    return "$_[0]($_[1])" if exists $fhash{$f};
++    return "$_[0]($_[1])";
++}
++
++# Finally, make manpages.mdwn
++
++open O, '>', $ARGV[1] . '/manpages.mdwn' or die $!;
++print STDOUT "Writing '$ARGV[1]/manpages.mdwn'\n";
++select O;
++print "Manual page index\n";
++print "=================\n\n";
++
++sub srt { my ($x, $y) = ($a, $b); $x =~ tr/./-/; $y =~ tr/./-/; $x cmp $y; }
++
++foreach (sort srt values %fhash)
++{
++    my $in = $_;
++    open I, '<', $in or die $!;
++    my $s;
++    while () {
++	if (/^\s*[.]TH\s+\S+\s+(\S+)/) {
++	    $s = $1;
++	    last;
++	}
++    }
++    while () {
++	last if /^\s*[.]SH NAME/
++    }
++    my $line = '';
++    while () {
++	tr/\\//d;
++	if (/\s*(\S+)\s+(.*)/) {
++	    my $e = $2;
++	    # Ignoring the NAME in file, get from file name instead.
++	    #my $on = (-l $in)? readlink $in: $in;
++	    my $on = $in;
++	    $on =~ tr/./-/; $on =~ s|.*/||;
++	    my $n = $in; $n =~ s|.*/||; $n =~ tr/./-/; $n =~ s/-[^-]+$//;
++	    $line = "$n($s) $e\n";
++	    last;
++	}
++    }
++    die "No NAME in '$in'\n" unless $line;
++    print "* $line";
++    #warn $line;
++}
+diff --git a/devel/news2wiki.pl b/devel/news2wiki.pl
+new file mode 100755
+index 0000000..8066ba7
+--- /dev/null
++++ b/devel/news2wiki.pl
+@@ -0,0 +1,102 @@
++#!/usr/bin/perl
++#
++# Author: Tomi Ollila
++# License: same as notmuch
++
++# This program is used to split NEWS file to separate (mdwn) files
++# for notmuch wiki. Example run:
++#
++# $ ./devel/news2wiki.pl NEWS ../notmuch-wiki/news
++#
++# In case taken into more generic use, modify these comments and examples.
++
++use strict;
++use warnings;
++
++unless (@ARGV == 2) {
++    warn "\n$0  \n\n";
++    warn "Example: ./devel/news2wiki.pl NEWS ../notmuch-wiki/news\n\n";
++    exit 1;
++}
++
++die "'$ARGV[0]': no such file\n" unless -f $ARGV[0];
++die "'$ARGV[1]': no such directory\n" unless -d $ARGV[1];
++
++open I, '<', $ARGV[0] or die "Cannot open '$ARGV[0]': $!\n";
++
++open O, '>', '/dev/null' or die $!;
++my @emptylines = ();
++my $cln;
++print "\nWriting to $ARGV[1]:\n";
++while ()
++{
++    warn "$ARGV[0]:$.: tab(s) in line!\n" if /\t/;
++    warn "$ARGV[0]:$.: trailing whitespace\n" if /\s\s$/;
++    # The date part in regex recognizes wip version dates like: (201x-xx-xx).
++    if (/^Notmuch\s+(\S+)\s+\((\w\w\w\w-\w\w-\w\w)\)\s*$/) {
++	# open O... autocloses previously opened file.
++	open O, '>', "$ARGV[1]/release-$1.mdwn" or die $!;
++	print "+ release-$1.mdwn...\n";
++	print O "[[!meta date=\"$2\"]]\n\n";
++	@emptylines = ();
++    }
++
++    last if /^