[med-svn] [ncbi-entrez-direct] 04/08: Substitute diversions for conflicts.

Aaron M. Ucko ucko at moszumanska.debian.org
Wed Jan 25 03:00:00 UTC 2017


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

ucko pushed a commit to branch master
in repository ncbi-entrez-direct.

commit 77e48a809eefc8e8da8b8b36db06e5079727c9fe
Author: Aaron M. Ucko <ucko at debian.org>
Date:   Mon Jan 16 22:49:46 2017 -0500

    Substitute diversions for conflicts.
    
    Resolve conflicts by diverting acedb-other's efetch and epub-utils'
    einfo to efetch.acedb and einfo.epub respectively (and likewise for
    their man pages) and deploying wrapper scripts that try to figure out
    which implementation the user intended to run.  (Proper usage differs
    radically, so ambiguity is unlikely to be an issue in practice.)
---
 debian/changelog |   7 +-
 debian/control   |   2 -
 debian/efetch    | 254 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 debian/einfo     | 243 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 debian/postrm    |  12 +++
 debian/preinst   |  19 +++++
 debian/rules     |   5 +-
 7 files changed, 536 insertions(+), 6 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 706f42f..ce3cf6d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,8 +1,13 @@
 ncbi-entrez-direct (6.00.20170109+ds-1) UNRELEASED; urgency=medium
 
   * New upstream release.  (NOT YET RELEASED.)
+  * Resolve conflicts by diverting acedb-other's efetch and epub-utils'
+    einfo to efetch.acedb and einfo.epub respectively (and likewise for
+    their man pages) and deploying wrapper scripts that try to figure out
+    which implementation the user intended to run.  (Proper usage differs
+    radically, so ambiguity is unlikely to be an issue in practice.)
 
- -- Aaron M. Ucko <ucko at debian.org>  Mon, 09 Jan 2017 22:55:17 -0500
+ -- Aaron M. Ucko <ucko at debian.org>  Mon, 16 Jan 2017 22:49:45 -0500
 
 ncbi-entrez-direct (6.00.20170105+ds-1) unstable; urgency=medium
 
diff --git a/debian/control b/debian/control
index 97c3096..346bbcf 100644
--- a/debian/control
+++ b/debian/control
@@ -17,8 +17,6 @@ Depends: libwww-perl,
          ${misc:Depends},
          ${perl:Depends},
          ${shlibs:Depends}
-Conflicts: acedb-other,
-           epub-utils
 Description: NCBI Entrez utilities on the command line
  Entrez Direct (EDirect) is an advanced method for accessing NCBI's set
  of interconnected databases (publication, sequence, structure, gene,
diff --git a/debian/efetch b/debian/efetch
new file mode 100755
index 0000000..60bc2ac
--- /dev/null
+++ b/debian/efetch
@@ -0,0 +1,254 @@
+#!/usr/bin/perl -w
+# Detect whether to run efetch.acedb or edirect -fetch.
+
+use strict;
+
+my $usage = <<EOF;
+USAGE: efetch [<AceDB efetch options>] [<database>:]<query>
+ -or-  efetch [<NCBI Entrez Direct efetch options>]
+
+per, respectively,
+
+    efetch.acedb -h (or man efetch.acedb)
+    edirect -fetch -help (no man page, at least so far)
+EOF
+
+if ( !@ARGV  ||  ! -x '/usr/bin/efetch.acedb' ) {
+    ExecNCBI();
+} elsif (grep /--?help/, @ARGV) {
+    print $usage;
+    exit 0;
+}
+
+my $acedb_flags = 'afqHprmMbAxw';
+my $acedb_keys  = 'seDdilBn';
+
+my %ncbi_supported = (
+    'db'          => 's',
+    'id'          => 's',
+    'format'      => 's',
+    'mode'        => 's',
+    'seq_start'   => 'i',
+    'seq_stop'    => 'i',
+    'strand'      => 's',
+    'complexity'  => 'i',
+    'chr_start'   => 'i',
+    'extend'      => 'i',
+    'extrafeat'   => 'i',
+    'start'       => 'i',
+    'stop'        => 'i',
+    'nogi'        => undef,
+    'email'       => 's',
+    'tool'        => 's',
+    'pipe'        => undef,
+    'help'        => undef,
+    'silent'      => undef,
+    'verbose'     => undef,
+    'debug'       => undef,
+    'log'         => undef,
+    'http'        => 's',
+    'https'       => 's',
+    'alias'       => 's',
+    'base'        => 's');
+
+my %ncbi_abbrev = ();
+{
+    my @names = sort keys %ncbi_supported;
+    unshift @names, '';
+    push @names, '';
+    my $i;
+    my $j;
+    for ($i = 1;  $i + 1 < @names;  ++$i) {
+        my $name      = $names[$i];
+        my $prev_name = $names[$i - 1];
+        my $next_name = $names[$i + 1];
+        for ($j = 1;  $j < length($name);  ++$j) {
+            my $abbrev = substr($name, 0, $j);
+            if ($abbrev ne substr($prev_name, 0, $j)
+                &&  $abbrev ne substr($next_name, 0, $j)) {
+                $ncbi_abbrev{$abbrev} = $name;
+            }
+        }
+    }
+}
+
+my @acedb_red_flags;
+my @acedb_yellow_flags;
+my $acedb_value_expected;
+my $acedb_query;
+my @ncbi_red_flags;
+my @ncbi_yellow_flags;
+my $ncbi_value_expected;
+
+for (@ARGV) {
+    if (/^-\d+$/  ||  !/^-/) {
+        if ( !defined $acedb_value_expected ) {
+            if (defined $acedb_query) {
+                push @acedb_yellow_flags, "$acedb_query $_";
+            }
+            $acedb_query = $_;
+        }
+        if ( !defined $ncbi_value_expected ) {
+            push @ncbi_red_flags, $_;
+        }
+        undef $acedb_value_expected;
+        undef $ncbi_value_expected;
+    } else {
+        my $acedb_type;
+        if (defined $acedb_value_expected) {
+            push @acedb_red_flags, "$acedb_value_expected $_";
+            $acedb_type = 'nominal-value';
+            undef $acedb_value_expected;
+        } elsif (/^-[ho]$/  ||  /^-[$acedb_flags]*(?:[$acedb_keys].+)?$/) {
+            $acedb_type = 'flag';
+        } elsif (/^-[$acedb_flags]*([$acedb_keys])$/) {
+            $acedb_type = 'key';
+            $acedb_value_expected = "-$1";
+        } else {
+            $acedb_type = 'invalid';
+            push @acedb_red_flags, $_;
+        }
+
+        my $ncbi_type;
+        if (defined $ncbi_value_expected) {
+            push @ncbi_red_flags, "$ncbi_value_expected $_";
+            $ncbi_type = 'nominal-value';
+            undef $ncbi_value_expected;
+        } elsif (/^--?([^=]+)(=.*)?/) {
+            my $base = lc($1);
+            my $has_value = defined $2;
+            if (exists $ncbi_abbrev{$base}) {
+                $base = $ncbi_abbrev{$base};
+                push @ncbi_yellow_flags, $_;
+            }
+            if ( !exists $ncbi_supported{$base}
+                 ||  ($has_value  &&  !defined $ncbi_supported{$base})) {
+                $ncbi_type = 'invalid';
+                push @ncbi_red_flags, $_;
+            } else {
+                if (lc($1) eq $base  &&  $1 =~ /[A-Z]/) {
+                    # Worry about capitalization only if otherwise OK
+                    push @ncbi_yellow_flags, $_;
+                }
+                if (defined $ncbi_supported{$base}  &&  !$has_value) {
+                    $ncbi_type = 'key';
+                    $ncbi_value_expected = $_;
+                } else {
+                    $ncbi_type = 'flag';
+                }
+            }
+        } else {
+            $ncbi_type = 'invalid';
+            push @ncbi_red_flags, $_;
+        }
+
+        if ($acedb_type =~ /^[fk]/  &&  $ncbi_type =~ /^[fk]/) {
+            # Could technically be valid for efetch.acedb, but far likelier
+            # to have been intended for edirect -fetch.
+            push @acedb_yellow_flags, $_;
+        }
+    }
+}
+
+if ( !defined $acedb_query ) {
+    push @acedb_red_flags, "no query";
+}
+if (defined $acedb_value_expected) {
+    push @acedb_red_flags, "$acedb_value_expected with no value";
+}
+if (defined $ncbi_value_expected) {
+    push @ncbi_red_flags, "$ncbi_value_expected with no value";
+}
+
+my $acedb_red  = @acedb_red_flags;
+my $acedb_ylw  = @acedb_yellow_flags;
+my $ncbi_red   = @ncbi_red_flags;
+my $ncbi_ylw   = @ncbi_yellow_flags;
+
+if ($acedb_red  &&  !$ncbi_red) {
+    # clear-cut, even if there happen to be NCBI yellow flags
+    ExecNCBI();
+} elsif ($ncbi_red  &&  !$acedb_red) {
+    ExecAceDB();
+}
+
+my $acedb_misgivings = "AceDB misgivings ($acedb_red major, $acedb_ylw minor):";
+my $ncbi_misgivings  = "NCBI misgivings ($ncbi_red major, $ncbi_ylw minor):";
+
+for (@acedb_red_flags) {
+    $acedb_misgivings .= "\n  $_ (major)";
+}
+for (@acedb_yellow_flags) {
+    $acedb_misgivings .= "\n  $_ (minor)";
+}
+for (@ncbi_red_flags) {
+    $ncbi_misgivings .= "\n  $_ (major)";
+}
+for (@ncbi_yellow_flags) {
+    $ncbi_misgivings .= "\n  $_ (minor)";
+}
+
+if ($ncbi_red > $acedb_red
+    ||  ($ncbi_red == $acedb_red  &&  $ncbi_ylw > $acedb_ylw)) {
+    if ($acedb_red  ||  $acedb_ylw) {
+        warn <<EOF;
+Launching AceDB efetch rather than NCBI efetch despite misgivings,
+due to more severe misgivings about NCBI syntax compatibility.  If you
+meant to run NCBI efetch, please explicitly run it via edirect -fetch.
+$ncbi_misgivings
+$acedb_misgivings
+EOF
+    }
+    ExecAceDB();
+}
+
+if ($acedb_red > $ncbi_red
+    ||  ($acedb_red == $ncbi_red  &&  $acedb_ylw > $ncbi_ylw)) {
+    if ($ncbi_red  ||  $ncbi_ylw) {
+        warn <<EOF;
+Launching NCBI efetch rather than AceDB efetch despite misgivings,
+due to more severe misgivings about AceDB syntax compatibility.  If you
+meant to run AceDB efetch, please explicitly run it via efetch.acedb.
+$acedb_misgivings
+$ncbi_misgivings
+EOF
+    }
+    ExecNCBI();
+}
+
+if ($acedb_red) {
+    die <<EOF;
+Usage equally bad for both AceDB efetch and NCBI efetch.  Please double
+check your usage or explicitly run efetch.acedb or edirect -fetch.
+$acedb_misgivings
+$ncbi_misgivings
+
+$usage
+EOF
+} elsif ($acedb_ylw) {
+    die <<EOF;
+Usage equally suspect (but still technically valid, at least to first
+approximation) for both AceDB efetch and NCBI efetch.  Please double
+check your usage or explicitly run efetch.acedb or edirect -fetch.
+$acedb_misgivings
+$ncbi_misgivings
+
+$usage
+EOF
+} else {
+    die <<EOF;
+Usage apparently valid (at least to first approximation) for both
+AceDB efetch and NCBI efetch.  Please disambiguate your usage or
+explicitly run efetch.acedb or edirect -fetch.
+EOF
+}
+
+sub ExecAceDB
+{
+    # exec {'/usr/bin/efetch.acedb'} ('/usr/bin/efetch', @ARGV);
+    exec('/usr/bin/efetch.acedb', @ARGV);
+}
+sub ExecNCBI
+{
+    exec('/usr/bin/edirect', '-fetch', @ARGV);
+}
diff --git a/debian/einfo b/debian/einfo
new file mode 100755
index 0000000..3db849c
--- /dev/null
+++ b/debian/einfo
@@ -0,0 +1,243 @@
+#!/usr/bin/perl -w
+# Detect whether to run einfo.epub or edirect -info.
+
+use strict;
+
+my $usage = <<EOF;
+USAGE: einfo [<epub einfo options>] <filename>
+ -or-  einfo [<NCBI Entrez Direct einfo options>]
+
+per, respectively,
+
+    einfo.epub -h (or man efetch.epub)
+    edirect -info -help (no man page, at least so far)
+EOF
+
+if ( !@ARGV  ||  ! -x '/usr/bin/einfo.epub' ) {
+    ExecNCBI();
+} elsif (grep /--?help/, @ARGV) {
+    print $usage;
+    exit 0;
+}
+
+my $epub_flags = 'qvdp';
+my $epub_keys  = 't';
+
+my %ncbi_supported = (
+    'db'          => 's',
+    'dbs'         => undef,
+    'fields'      => undef,
+    'links'       => undef,
+    'email'       => 's',
+    'tool'        => 's',
+    'help'        => undef,
+    'silent'      => undef,
+    'verbose'     => undef,
+    'debug'       => undef,
+    'log'         => undef,
+    'http'        => 's',
+    'https'       => 's',
+    'alias'       => 's',
+    'base'        => 's');
+
+my %ncbi_abbrev = ();
+{
+    my @names = sort keys %ncbi_supported;
+    unshift @names, '';
+    push @names, '';
+    my $i;
+    my $j;
+    for ($i = 1;  $i + 1 < @names;  ++$i) {
+        my $name      = $names[$i];
+        my $prev_name = $names[$i - 1];
+        my $next_name = $names[$i + 1];
+        for ($j = 1;  $j < length($name);  ++$j) {
+            my $abbrev = substr($name, 0, $j);
+            if ($abbrev ne substr($prev_name, 0, $j)
+                &&  $abbrev ne substr($next_name, 0, $j)) {
+                $ncbi_abbrev{$abbrev} = $name;
+            }
+        }
+    }
+}
+
+my @epub_red_flags;
+my @epub_yellow_flags;
+my $epub_value_expected;
+my $epub_query;
+my @ncbi_red_flags;
+my @ncbi_yellow_flags;
+my $ncbi_value_expected;
+
+for (@ARGV) {
+    if (/^-\d+$/  ||  !/^-/) {
+        if ( !defined $epub_value_expected ) {
+            if (defined $epub_query) {
+                push @epub_red_flags, "$epub_query $_";
+            }
+            $epub_query = $_;
+        }
+        if ( !defined $ncbi_value_expected ) {
+            push @ncbi_red_flags, $_;
+        }
+        undef $epub_value_expected;
+        undef $ncbi_value_expected;
+    } else {
+        my $epub_type;
+        if (defined $epub_value_expected) {
+            push @epub_red_flags, "$epub_value_expected $_";
+            $epub_type = 'nominal-value';
+            undef $epub_value_expected;
+        } elsif (/^-[ho]$/  ||  /^-[$epub_flags]*(?:[$epub_keys].+)?$/) {
+            $epub_type = 'flag';
+        } elsif (/^-[$epub_flags]*([$epub_keys])$/) {
+            $epub_type = 'key';
+            $epub_value_expected = "-$1";
+        } else {
+            $epub_type = 'invalid';
+            push @epub_red_flags, $_;
+        }
+
+        my $ncbi_type;
+        if (defined $ncbi_value_expected) {
+            push @ncbi_red_flags, "$ncbi_value_expected $_";
+            $ncbi_type = 'nominal-value';
+            undef $ncbi_value_expected;
+        } elsif (/^--?([^=]+)(=.*)?/) {
+            my $base = lc($1);
+            my $has_value = defined $2;
+            if (exists $ncbi_abbrev{$base}) {
+                $base = $ncbi_abbrev{$base};
+                push @ncbi_yellow_flags, $_;
+            }
+            if ( !exists $ncbi_supported{$base}
+                 ||  ($has_value  &&  !defined $ncbi_supported{$base})) {
+                $ncbi_type = 'invalid';
+                push @ncbi_red_flags, $_;
+            } else {
+                if (lc($1) eq $base  &&  $1 =~ /[A-Z]/) {
+                    # Worry about capitalization only if otherwise OK
+                    push @ncbi_yellow_flags, $_;
+                }
+                if (defined $ncbi_supported{$base}  &&  !$has_value) {
+                    $ncbi_type = 'key';
+                    $ncbi_value_expected = $_;
+                } else {
+                    $ncbi_type = 'flag';
+                }
+            }
+        } else {
+            $ncbi_type = 'invalid';
+            push @ncbi_red_flags, $_;
+        }
+
+        if ($epub_type =~ /^[fk]/  &&  $ncbi_type =~ /^[fk]/) {
+            # Could technically be valid for einfo.epub, but far likelier
+            # to have been intended for edirect -info.
+            push @epub_yellow_flags, $_;
+        }
+    }
+}
+
+if ( !defined $epub_query ) {
+    push @epub_red_flags, "no filename";
+}
+if (defined $epub_value_expected) {
+    push @epub_red_flags, "$epub_value_expected with no value";
+}
+if (defined $ncbi_value_expected) {
+    push @ncbi_red_flags, "$ncbi_value_expected with no value";
+}
+
+my $epub_red  = @epub_red_flags;
+my $epub_ylw  = @epub_yellow_flags;
+my $ncbi_red   = @ncbi_red_flags;
+my $ncbi_ylw   = @ncbi_yellow_flags;
+
+if ($epub_red  &&  !$ncbi_red) {
+    # clear-cut, even if there happen to be NCBI yellow flags
+    ExecNCBI();
+} elsif ($ncbi_red  &&  !$epub_red) {
+    ExecEpub();
+}
+
+my $epub_misgivings = "EPUB misgivings ($epub_red major, $epub_ylw minor):";
+my $ncbi_misgivings  = "NCBI misgivings ($ncbi_red major, $ncbi_ylw minor):";
+
+for (@epub_red_flags) {
+    $epub_misgivings .= "\n  $_ (major)";
+}
+for (@epub_yellow_flags) {
+    $epub_misgivings .= "\n  $_ (minor)";
+}
+for (@ncbi_red_flags) {
+    $ncbi_misgivings .= "\n  $_ (major)";
+}
+for (@ncbi_yellow_flags) {
+    $ncbi_misgivings .= "\n  $_ (minor)";
+}
+
+if ($ncbi_red > $epub_red
+    ||  ($ncbi_red == $epub_red  &&  $ncbi_ylw > $epub_ylw)) {
+    if ($epub_red  ||  $epub_ylw) {
+        warn <<EOF;
+Launching EPUB einfo rather than NCBI einfo despite misgivings,
+due to more severe misgivings about NCBI syntax compatibility.  If you
+meant to run NCBI einfo, please explicitly run it via edirect -info.
+$ncbi_misgivings
+$epub_misgivings
+EOF
+    }
+    ExecEpub();
+}
+
+if ($epub_red > $ncbi_red
+    ||  ($epub_red == $ncbi_red  &&  $epub_ylw > $ncbi_ylw)) {
+    if ($ncbi_red  ||  $ncbi_ylw) {
+        warn <<EOF;
+Launching NCBI einfo rather than EPUB einfo despite misgivings,
+due to more severe misgivings about EPUB syntax compatibility.  If you
+meant to run EPUB einfo, please explicitly run it via einfo.epub.
+$epub_misgivings
+$ncbi_misgivings
+EOF
+    }
+    ExecNCBI();
+}
+
+if ($epub_red) {
+    die <<EOF;
+Usage equally bad for both EPUB einfo and NCBI einfo.  Please double
+check your usage or explicitly run einfo.epub or edirect -info.
+$epub_misgivings
+$ncbi_misgivings
+
+$usage
+EOF
+} elsif ($epub_ylw) {
+    die <<EOF;
+Usage equally suspect (but still technically valid, at least to first
+approximation) for both EPUB einfo and NCBI einfo.  Please double
+check your usage or explicitly run einfo.epub or edirect -info.
+$epub_misgivings
+$ncbi_misgivings
+
+$usage
+EOF
+} else {
+    die <<EOF;
+Usage apparently valid (at least to first approximation) for both
+EPUB einfo and NCBI einfo.  Please disambiguate your usage or
+explicitly run einfo.epub or edirect -info.
+EOF
+}
+
+sub ExecEpub
+{
+    # exec {'/usr/bin/einfo.epub'} ('/usr/bin/einfo', @ARGV);
+    exec('/usr/bin/einfo.epub', @ARGV);
+}
+sub ExecNCBI
+{
+    exec('/usr/bin/edirect', '-info', @ARGV);
+}
diff --git a/debian/postrm b/debian/postrm
new file mode 100755
index 0000000..5e5a803
--- /dev/null
+++ b/debian/postrm
@@ -0,0 +1,12 @@
+#!/bin/sh
+set -e
+
+#DEBHELPER#
+
+if [ "$1" = "remove" ]; then
+   for x in efetch einfo; do
+       dpkg-divert --package ncbi-entrez-direct --remove --rename /usr/bin/$x
+       dpkg-divert --package ncbi-entrez-direct --remove --rename \
+		   /usr/share/man/man1/$x.1.gz
+   done
+fi
diff --git a/debian/preinst b/debian/preinst
new file mode 100755
index 0000000..8794233
--- /dev/null
+++ b/debian/preinst
@@ -0,0 +1,19 @@
+#!/bin/sh
+set -e
+
+#DEBHELPER#
+
+case "$1" in
+    install | upgrade )
+	dpkg-divert --package ncbi-entrez-direct --rename \
+		    --divert /usr/bin/efetch.acedb /usr/bin/efetch
+	dpkg-divert --package ncbi-entrez-direct --rename \
+		    --divert /usr/share/man/man1/efetch.acedb.1.gz \
+		    /usr/share/man/man1/efetch.1.gz
+	dpkg-divert --package ncbi-entrez-direct --rename \
+		    --divert /usr/bin/einfo.epub /usr/bin/einfo
+	dpkg-divert --package ncbi-entrez-direct --rename \
+		    --divert /usr/share/man/man1/einfo.epub.1.gz \
+		    /usr/share/man/man1/einfo.1.gz
+    ;;
+esac
diff --git a/debian/rules b/debian/rules
index 7730827..93caa59 100755
--- a/debian/rules
+++ b/debian/rules
@@ -9,8 +9,7 @@ include /usr/share/dpkg/default.mk
 %:
 	dh $@
 
-MODES = address citmatch contact fetch filter info link notify post proxy \
-        search spell
+MODES = address citmatch contact filter link notify post proxy search spell
 STD_WRAPPERS = $(MODES:%=bin/e%)
 WRAPPERS = $(STD_WRAPPERS) bin/esummary
 AS_IS_SCRIPTS = amino-acid-composition between-two-genes edirutil \
@@ -34,7 +33,7 @@ bin/esummary: bin/edirect
 
 override_dh_auto_build: $(WRAPPERS)
 	dh_auto_build
-	install $(AS_IS_SCRIPTS) bin/
+	install $(AS_IS_SCRIPTS) debian/efetch debian/einfo bin/
 # Always use gccgo?  The resulting binary would be much smaller, but
 # pull in a large shared library with few other reverse dependencies.
 	go build -gccgoflags '$(CFLAGS) $(LDFLAGS)' -o bin/xtract xtract.go || \

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



More information about the debian-med-commit mailing list