[med-svn] [fastaq] 01/01: new python usage conversion to manp pages

Jorge Soares jssoares-guest at moszumanska.debian.org
Thu Oct 16 16:05:16 UTC 2014


This is an automated email from the git hooks/post-receive script.

jssoares-guest pushed a commit to tag 1.5.0
in repository fastaq.

commit 0da67e8739b7ecf92bf737db7c027be1884caa87
Author: Jorge Soares <j.s.soares at gmail.com>
Date:   Thu Oct 16 16:57:09 2014 +0100

    new python usage conversion to manp pages
---
 debian/rules        |   2 +-
 debian/usage_to_man | 153 +++++++++++++++++++++++++++++++---------------------
 2 files changed, 94 insertions(+), 61 deletions(-)

diff --git a/debian/rules b/debian/rules
index d3d035e..58f2a1b 100755
--- a/debian/rules
+++ b/debian/rules
@@ -17,7 +17,7 @@ override_dh_auto_build:
 
 override_dh_auto_clean:
 	rm -rf build .pybuild
-	rm -rf man
+	rm -rf $(mandir)
 
 override_dh_installman:
 	mkdir -p $(mandir)
diff --git a/debian/usage_to_man b/debian/usage_to_man
index 16793ce..47b7f2d 100755
--- a/debian/usage_to_man
+++ b/debian/usage_to_man
@@ -1,67 +1,100 @@
-#!/bin/bash
-
-#Converts the Fastaq python scripts usage into man pages
-#The man pages are placed in the man folder of the main Fastaq directory  
-
-source='scripts'
-destination='debian/man'
-
-if [ ! -d "$destination" ]; then
-    mkdir $destination
-fi
-
-for i in $source/fastaq_*; do
-    if [ -e $i ]; then
-	echo "Converting $i to man - first pass";
-	j=$(echo $i | sed "s/$source\///");
-	out_file=$destination/$j.1
-
-	help2man -m $j -n $j --no-discard-stderr $i |
-	grep -v $j': error: too few arguments' |
-	sed "s/usage://gi" > $out_file;
-    else
-	echo "File $i does not exist"; exit 1;
-    fi
-
-done
-
-
-
-for file in $destination/*.1; do
-
-    if [ -e $file ]; then
-	echo "Final checks for file  $file - second pass";
-	out_file=$(echo $file | sed 's/\.1/\.2/');
-	filename=$(echo $file | sed "s/\($destination\/*\)\([a-zA-Z_0-9]* *\)\.1/\2/")
-	while read line
-	do
-	    echo $line |
-	    sed "s/\-\s\($filename *\)/\1/" |
-	    sed "s/\(.TH *\)\([a-zA-Z_0-9]* *\)\(\"[0-9\"]* *\)\(\"[a-zA-Z0-9_ ]*\" *\)\(\"[a-zA-Z0-9_\<\>\/ ]*\" *\)\(\"[a-zA-Z0-9_]*\" *\)/\1 \2 \6 \3/" |
-	    sed "s/\(The\sfull\sdocumentation\sfor*\)/$filename -h will display the original python documentation/" |
-	    sed "s/^\.B//" |
-	    sed "s/^is\smaintained\sas\sa\sTexinfo\smanual.\sIf\sthe//" |
-	    sed "s/^\.B//" |
-	    sed "s/\sinfo//" |
-	    sed "s/^and//" |
-	    sed "s/^programs\sare\sproperly\sinstalled\sat\syour\ssite\,\sthe\scommand//" |
-	    sed "s/\(.IP\r*\)//" |
-	    sed "s/^should\sgive\syou\saccess\sto\sthe\scomplete\smanual\.//"
-
-	done < $file > $out_file
-	cat <<EOF >> $out_file
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Data::Dumper;
+
+#Converts Fastaq python scripts usage into man pages.
+#The man pages are placed in the man folder of the main Fastaq directory
+
+createManPages();
+
+sub createManPages {
+
+  my $source= 'scripts';
+  my $destination= 'debian/man';
+  my $app_name = 'Fastaq';
+
+
+  unless ( -d $destination ) {
+    system(mkdir $destination);
+  }
+
+  my @files;
+
+  push(@files,`ls $source/fastaq_*`);
+
+  if ( scalar @files > 0 ) {
+
+    print "Creating manpages\n";
+    for my $file ( @files ) {
+      $file =~ s/\n$//;
+
+      my $filename = $file;
+      $filename =~ s/$source\///;
+
+      my $uc_filename = uc($filename);
+      my $man_file = $filename;
+
+      $man_file = $destination . '/' . $man_file . '.1';
+
+      open (my $man_fh, ">", $man_file);
+
+      my $grep_string = $filename . ': error: too few arguments';
+
+      my $cmd = "help2man -m $filename -n $filename --no-discard-stderr $file | sed 's/usage://gi'";
+      my @output;
+      push(@output, `$cmd`);
+
+      for my $line (@output) {
+	$line =~ s/\n$//;
+
+      }
+
+      for (my $i = 0; $i < scalar @output; $i++) {
+	my $output_line = $output[$i];
+
+	if ($output_line =~ m/^\.TH/) {
+	  $output_line =~ s/\s+/ /g;
+	  $output_line =~ s/(\.TH) ("\d+") ("[a-zA-Z0-9_ ]*") ("[a-zA-Z0-9_<>\[\]\/\.\(\), ]*") ("[a-zA-Z0-9_]*")/$1 $uc_filename $2 $3 "$app_name" "Fastaq executables"/;
+	}
+
+	$output_line =~ s/ \\- $filename/$filename/;
+
+	if ( $output_line =~ m/^.PP/ && $output[$i + 1] =~ m/^$filename\:/ ) {
+	  $output_line = $output[$i + 1] = '';
+	}
+
+	if ($output_line =~ m/^\.SH "SEE ALSO"/) {
+	  last;
+	}
+	print $man_fh "$output_line\n";
+      }
+
+      writeAuthorAndCopyright($man_fh,$filename);
+      close($man_fh);
+    }
+    print "Manpage creation complete\n";
+  }
+}
+
+sub writeAuthorAndCopyright {
+
+  my ($man_fh,$filename) = @_;
+
+  my $author_blurb = <<END_OF_AUTHOR_BLURB;
 .SH "AUTHOR"
 .sp
-$filename was originally written by Martin Hunt (mh12 at sanger\&.ac\&.uk)
+$filename was originally written by Martin Hunt (mh12\@sanger.ac.uk)
+END_OF_AUTHOR_BLURB
+
+  print $man_fh "$author_blurb\n";
+
+  my $copyright_blurb = <<'END_OF_C_BLURB';
 .SH "COPYING"
 .sp
 Wellcome Trust Sanger Institute Copyright \(co 2013 Wellcome Trust Sanger Institute This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version\&.
-EOF
+END_OF_C_BLURB
 
-	mv $out_file $file
-	exit 1;
-    else
-	echo "File $file does not exist"; exit 1;
-    fi
+  print $man_fh "$copyright_blurb\n";
 
-done
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/fastaq.git



More information about the debian-med-commit mailing list