]> git.donarmstrong.com Git - debhelper.git/commitdiff
r565: * Various minor changes based on suggestions by luca.
authorjoey <joey>
Thu, 21 Nov 2002 05:21:51 +0000 (05:21 +0000)
committerjoey <joey>
Thu, 21 Nov 2002 05:21:51 +0000 (05:21 +0000)
Debian/Debhelper/Dh_Lib.pm
autoscripts/postinst-python [new file with mode: 0644]
autoscripts/prerm-python [new file with mode: 0644]
debian/changelog
debian/copyright
dh_python [new file with mode: 0755]
examples/rules
examples/rules.indep
examples/rules.multi
examples/rules.multi2

index 7770b5abc3b9c2dc79be2c909d9c10c2347a7371..c9910bad9a826ea1a2ca2015a972fd1adfdd966c 100644 (file)
@@ -247,7 +247,7 @@ sub compat {
        }
        elsif (-e 'debian/compat') {
                # Try the file..
-               open (COMPAT_IN, "debian/compat") || die "debian/compat: $!";
+               open (COMPAT_IN, "debian/compat") || error "debian/compat: $!";
                $c=<COMPAT_IN>;
                chomp $c;
        }
@@ -392,7 +392,7 @@ sub delsubstvar {
        my $substvarfile="debian/${ext}substvars";
 
        if (-e $substvarfile) {
-               complex_doit("grep -v '^${substvar}=' $substvarfile > $substvarfile.new || true");
+               complex_doit("grep -s -v '^${substvar}=' $substvarfile > $substvarfile.new || true");
                doit("mv", "$substvarfile.new","$substvarfile");
        }
 }
@@ -416,7 +416,7 @@ sub addsubstvar {
        my $line="";
        if (-e $substvarfile) {
                my %items;
-               open(SUBSTVARS_IN, "$substvarfile") || die "read $substvarfile: $!";
+               open(SUBSTVARS_IN, "$substvarfile") || error "read $substvarfile: $!";
                while (<SUBSTVARS_IN>) {
                        chomp;
                        if (/^\Q$substvar\E=(.*)/) {
@@ -439,9 +439,12 @@ sub addsubstvar {
        }
 
        if (length $line) {
-                complex_doit("(grep -v ${substvar} $substvarfile 2>/dev/null; echo '${substvar}=$line') > $substvarfile.new");
+                complex_doit("(grep -s -v ${substvar} $substvarfile; echo '${substvar}=$line') > $substvarfile.new");
                 doit("mv", "$substvarfile.new", $substvarfile);
        }
+       else {
+               delsubstvar($package,$substvar);
+       }
 }
 
 # Reads in the specified file, one line at a time. splits on words, 
diff --git a/autoscripts/postinst-python b/autoscripts/postinst-python
new file mode 100644 (file)
index 0000000..2ecb99b
--- /dev/null
@@ -0,0 +1,6 @@
+PYTHON=#PYVER#
+DIRLIST="#DIRLIST#"
+for i in $DIRLIST ; do
+       $PYTHON -O /usr/lib/$PYTHON/compileall.py -q $i
+       $PYTHON /usr/lib/$PYTHON/compileall.py -q $i
+done
diff --git a/autoscripts/prerm-python b/autoscripts/prerm-python
new file mode 100644 (file)
index 0000000..0dc1273
--- /dev/null
@@ -0,0 +1,5 @@
+if [ "$1" = remove ]; then
+       dpkg -L #PACKAGE# |
+               awk '$0~/\.py$/ {print $0"c\n" $0"o"}' |
+               xargs rm -f >&2
+fi
index 74a730d25da8d6225abfbb6013beaffcd5ac7237..486efffede8d2ab0fb9d644e8700ce609ddfedc6 100644 (file)
@@ -1,3 +1,9 @@
+debhelper (4.1.24) unstable; urgency=low
+
+  * Various minor changes based on suggestions by luca.
+
+ -- Joey Hess <joeyh@debian.org>  Thu, 21 Nov 2002 00:13:52 -0500
+
 debhelper (4.1.23) unstable; urgency=low
 
   * Still run potodebconf after warning about templates.ll files.
index 09a0d1fdaf298863cee8a8beba5477c1831c0a6a..903e21f4be9297aea7de1a461f27634bffed1043 100644 (file)
@@ -6,6 +6,9 @@ whole thing) came from debmake, by Christoph Lameter <clameter@debian.org>.
 Some of the dh_md5sums command is from a program by Charles 
 Briscoe-Smith <cpb4@ukc.ac.uk>.
 
+dh_perl is by Brendan O'Dea <bod@debian.org>
+dh_python is by Josselin Mouette <josselin.mouette@ens-lyon.org>
+
 The copyright of this package is GPL, version 2 or later. Files in the
 examples/ directory are in the public domain. On Debian systems the
 complete text of the GPL is in /usr/share/common-licenses/GPL
diff --git a/dh_python b/dh_python
new file mode 100755 (executable)
index 0000000..b2a9ad7
--- /dev/null
+++ b/dh_python
@@ -0,0 +1,208 @@
+#!/usr/bin/perl -w
+
+=head1 NAME
+
+dh_python - calculates python dependencies and adds postinst and prerm python scripts
+
+=cut
+
+use strict;
+use File::Find;
+use Debian::Debhelper::Dh_Lib;
+
+=head1 SYNOPSIS
+
+B<dh_python> [S<I<debhelper options>>] [B<-n>] [S<I<module dirs ...>>]
+
+=head1 DESCRIPTION
+
+dh_python is a debhelper program that is responsible for generating the
+${python:Depends} substitutions and adding them to substvars files. It
+will also add a postinst and a prerm script if required.
+
+The program will look at python scripts and modules in your package, and
+will use this information to generate a dependency on python, with the
+current major version, or on pythonX.Y if your scripts or modules need a
+specific python version. The dependency will be substituted into your
+package's control file wherever you place the token "${python:Depends}".
+
+If some modules need to be byte-compiled at build time, appropriate
+postinst and prerm scripts will be generated.
+
+=head1 OPTIONS
+
+=over 4
+
+=item I<module dirs>
+
+If your package installs python modules in non-standard directories, you
+can make dh_python check those directories by passing their names on the
+command line. By default, it will check /usr/lib/site-python,
+/usr/lib/$PACKAGE, /usr/share/$PACKAGE, /usr/lib/games/$PACKAGE,
+/usr/share/games/$PACKAGE and /usr/lib/python?.?/site-packages.
+
+=item B<-n>, B<--noscripts>
+
+Do not modify postinst/postrm scripts.
+
+=back
+
+=head1 CONFORMS TO
+
+Debian policy, version 3.5.7
+
+Python policy, version 0.3.7
+
+=cut
+
+init();
+
+my $python = 'python';
+
+# The current python major version
+my $python_version;
+my $python_major;
+if(`$python -V 2>&1` =~ m/^Python\s+(\d+)\.(\d+)\.\d+\n$/) {
+       $python_version = "$1.$2" ;
+       $python_major = $1 ;
+} else { 
+       error("Cannot obtain python version.");
+}
+
+# The next python version
+my $python_nextversion = $python_version + 0.1;
+my $python_nextmajor = $python_major + 1;
+
+my @python_allversions = ('1.5','2.1','2.2','2.3');
+foreach (@python_allversions) {
+       s/^/python/;
+}
+
+# Cleaning the paths given on the command line
+foreach (@ARGV) {
+       s#/$##;
+       s#^/##;
+}
+
+# dependency types
+use constant PROGRAM   => 1;
+use constant PY_MODULE => 2;
+
+foreach my $package (@{$dh{DOPACKAGES}}) {
+       my $tmp = tmpdir($package);
+
+       delsubstvar($package, "python:Depends");
+
+       # Check for current python dependencies
+       my @dirs = ("usr/lib/site-python", "usr/lib/$package", "usr/share/$package", "usr/lib/games/$package", "usr/share/games/$package", @ARGV );
+       @dirs = grep -d, map "$tmp/$_", @dirs;
+
+       my $deps = 0;
+       my %verdeps = ();
+       foreach (@python_allversions) {
+               $verdeps{$_} = 0;
+       }
+
+       # Find scripts
+       find sub {
+               return unless -f and (-x or /\.py$/);
+               local *F;
+               return unless open F, $_;
+               if (read F, local $_, 32 and m%^#!\s*/usr/bin/(env\s+)?(python(\d+\.\d+)?)\s%) {
+                       if ( "python" eq $2 ) {
+                               $deps |= PROGRAM;
+                       } elsif(defined $verdeps{$2}) {
+                               $verdeps{$2} |= PROGRAM;
+                       }
+               }
+               close F;
+       }, $tmp;
+
+       # Look for python modules
+       my $dirlist="";
+       if (@dirs) {
+               foreach my $curdir (@dirs) {
+                       my $has_module = 0;
+                       $curdir =~ s%^$tmp/%%;
+                       find sub {
+                               return unless -f;
+                               $has_module = 1 if /\.py$/;
+                       }, "$tmp/$curdir" ;
+                       if($has_module) {
+                               $deps |= PY_MODULE;
+                               $dirlist="$dirlist /$curdir";
+                       }
+               }
+       }
+
+       # Dependencies on current python
+       my $dep_on_python = 0;
+       my $strong_dep = 0;
+       $dep_on_python = 1 if $deps;
+       $strong_dep = 1 if($deps & PY_MODULE);
+       if($package =~ /^python-/) {
+               my $pack = $package;
+               $pack =~ s/^python/python$python_version/;
+               if(grep { "$_" eq "$pack" } @{$dh{DOPACKAGES}}) {
+                       addsubstvar($package, "python:Depends", $pack);
+                       $dep_on_python = 1;
+                       $strong_dep = 1;
+               }
+       }
+       if($dep_on_python) {
+               addsubstvar($package, "python:Depends", $python, ">= $python_version");
+               if($strong_dep) {
+                       addsubstvar($package, "python:Depends", $python, "<< $python_nextversion");
+               } else {
+                       addsubstvar($package, "python:Depends", $python, "<< $python_nextmajor");
+               }
+       }
+
+       my $need_prerm = 0;
+
+       # Look for specific pythonX.Y modules
+       foreach my $pyver (@python_allversions) {
+               my $pydir="/usr/lib/$pyver/site-packages";
+               if (grep -d,"$tmp$pydir") {
+                       find sub {
+                               return unless -f;
+                               $verdeps{$pyver} |= PY_MODULE if /\.py$/;
+                       }, "$tmp$pydir";
+               }
+               
+               # Go for the dependencies
+               addsubstvar($package, "python:Depends", $pyver) if $verdeps{$pyver};
+
+               # And now, the postinst and prerm stuff
+               if($pyver eq "python$python_version") {
+                       if($verdeps{$pyver} & PY_MODULE) {
+                               $pydir = $pydir.$dirlist;
+                       } else {
+                               $pydir = $dirlist;
+                       }
+                       $verdeps{$pyver} |= PY_MODULE if($deps & PY_MODULE);
+               }
+               if($verdeps{$pyver} & PY_MODULE) {
+                       autoscript($package,"postinst","postinst-python","s%#PYVER#%$pyver%;s%#DIRLIST#%$pydir%");
+                       $need_prerm = 1;
+               }
+       }
+       if($need_prerm) {
+               autoscript($package,"prerm","prerm-python","s%#PACKAGE#%$package%");
+       }
+}
+
+=head1 SEE ALSO
+
+L<debhelper(1)>
+
+This program is a part of debhelper.
+
+=head1 AUTHOR
+
+Josselin Mouette <joss@debian.org>
+
+most ideas stolen from Brendan O'Dea <bod@debian.org>
+
+=cut
+
index 26c0481f7863f1bbecdd85584a5879e6d5796671..4f2b7aceead337c0611baa43b27b09cf4f78c289 100755 (executable)
@@ -64,6 +64,7 @@ binary-arch: build install
 #      dh_makeshlibs
        dh_installdeb
 #      dh_perl
+#      dh_python
        dh_shlibdeps
        dh_gencontrol
        dh_md5sums
index 6a01a3eb529dc618fd35951b07842530dfa49e5d..50496f940a60c612b3b5b9afef94e0e3c4e5fb06 100755 (executable)
@@ -60,6 +60,7 @@ binary-indep: build install
        dh_fixperms
        dh_installdeb
 #      dh_perl
+#      dh_python
        dh_gencontrol
        dh_md5sums
        dh_builddeb
index 9e3a448b46a4bdd191381459344562a02de085e1..17a0d348b499ad7722d68fd123db8a15991bd894 100755 (executable)
@@ -64,6 +64,7 @@ binary-indep: build install
        dh_fixperms -i
        dh_installdeb -i
 #      dh_perl -i
+#      dh_python -i
        dh_gencontrol -i
        dh_md5sums -i
        dh_builddeb -i
@@ -93,6 +94,7 @@ binary-arch: build install
 #      dh_makeshlibs -a
        dh_installdeb -a
 #      dh_perl -a
+#      dh_python -a
        dh_shlibdeps -a
        dh_gencontrol -a
        dh_md5sums -a
index 042cdd282f374ea3ac3d45fdf55d426d8ba184a0..36f921b4ea072eeac69eb75742409caf109e44a9 100755 (executable)
@@ -71,6 +71,7 @@ binary-common:
 #      dh_makeshlibs
        dh_installdeb
 #      dh_perl
+#      dh_python
        dh_shlibdeps
        dh_gencontrol
        dh_md5sums