Package: debhelper

The following patch adds python-central support in debhelper.  The
current behaviour is unchanged, so it doesn't break existing packages.

  Matthias


--- dh_python~  2006-04-24 20:09:12.000000000 +0000
+++ dh_python   2006-06-07 00:27:35.217891000 +0000
@@ -13,6 +13,7 @@
 =head1 SYNOPSIS
 
 B<dh_python> [S<I<debhelper options>>] [B<-n>] [B<-V> I<version>] [S<I<module 
dirs ...>>]
+B<dh_python> [S<I<debhelper options>>] [B<-n>] [B<-add-provides>] [B<-no-move>]
 
 =head1 DESCRIPTION
 
@@ -32,10 +33,20 @@
 
 If you use this program, your package should build-depend on python.
 
+In pycentral mode (see below), the program will additionally generate
+the ${python:Versions} and (optionally) ${python:Provides} substitutions
+and move the files to the pycentral location for modules which are
+shared across python versions. If you use this mode, your package must
+build-depend on python-central.
+
 =head1 OPTIONS
 
 =over 4
 
+Some options are ignored when the control file has an XS-Python-Version
+attribute in the Source section and an XB-Python-Version attribute in
+the package section (pycentral mode).
+
 =item I<module dirs>
 
 If your package installs python modules in non-standard directories, you
@@ -47,12 +58,27 @@
 Note: only /usr/lib/site-python, /usr/lib/python?.?/site-packages and the
 extra names on the command line are searched for binary (.so) modules.
 
+Module directories are ignored in pycentral mode.
+
 =item B<-V> I<version>
 
 If the .py files your package ships are meant to be used by a specific
 pythonX.Y version, you can use this option to specify the desired version,
 such as 2.3. Do not use if you ship modules in /usr/lib/site-python.
 
+This option is ignored in pycentral mode.
+
+=item B<--add-provides>
+
+Add a substitution variable "${python:Provides}". Additional provides
+information is needed for packages depending on on a module or extension
+for a python version, which is not the default python version.
+
+=item B<--no-move>
+
+Do not move files from /usr/lib/python2.X to the pycentral area for
+files shared across python versions (pycentral mode only).
+
 =item B<-n>, B<--noscripts>
 
 Do not modify postinst/postrm scripts.
@@ -69,6 +95,88 @@
 
 init();
 
+my %version_fields;
+sub readpyversions {
+       my $type=shift;
+
+       %version_fields=();
+       
+       $type="" if ! defined $type;
+       
+       # Look up the build arch if we need to.
+       my $buildarch='';
+       if ($type eq 'same') {
+               $buildarch=buildarch();
+       }
+
+       my $package="";
+       my $arch="";
+       my $pv_info="";
+       my @list=();
+       my %seen;
+       open (CONTROL, 'debian/control') ||
+               error("cannot read debian/control: $!\n");
+       while (<CONTROL>) {
+               chomp;
+               s/\s+$//;
+               if (/^Source:\s*(.*)/) {
+                       $package="Source";
+               }
+               if (/^Package:\s*(.*)/) {
+                       $package=$1;
+                       # Detect duplicate package names in the same control 
file.
+                       if (! $seen{$package}) {
+                               $seen{$package}=1;
+                       }
+                       else {
+                               error("debian/control has a duplicate entry for 
$package");
+                       }
+               }
+               if (/^Architecture:\s*(.*)/) {
+                       $arch=$1;
+               }
+               if (/^X.*S.*-Python-Version:\s*(.*)/) {
+                       if ($package ne 'Source') {
+                               error("debian/control: XS-Python-Version field 
in binary package");
+                       }
+                       $pv_info=$1;
+               }
+               if (/^X.*B.*-Python-Version:\s*(.*)/) {
+                       if ($package eq 'Source') {
+                               error("debian/control: XB-Python-Version field 
in source package");
+                       }
+                       $pv_info=$1;
+               }
+
+               if (!$_ or eof) { # end of stanza.
+                       if ($package) {
+                               $version_fields{$package}=$pv_info;
+                       }
+                       if ($package eq 'Source' && $pv_info eq '') {
+                               error("missing XS-PythonVersion for source 
package");
+                       }
+                       if ($package &&
+                           (($type eq 'indep' && $arch eq 'all') ||
+                            ($type eq 'arch' && $arch ne 'all') ||
+                            ($type eq 'same' && ($arch eq 'any' || $arch =~ 
/(^|\s)$buildarch(\s|$)/)) ||
+                            ! $type)) {
+                               #if ($pv_info eq '') {
+                               #       error("missing XB-PythonVersion for 
`$package' package");
+                               #}
+                               push @list, $package;
+                               $package="";
+                               $arch="";
+                               $pv_info="";
+                       }
+               }
+       }
+       close CONTROL;
+
+       return @list;
+}
+
+my @pypackages = readpyversions();
+
 my $python = 'python';
 
 # The current python major version
@@ -88,7 +196,7 @@
 my $python_nextversion = $python_version + 0.1;
 my $python_nextmajor = $python_major + 1;
 
-my @python_allversions = ('1.5','2.1','2.2','2.3','2.4');
+my @python_allversions = ('1.5','2.1','2.2','2.3','2.4', '2.5');
 foreach (@python_allversions) {
        s/^/python/;
 }
@@ -120,6 +228,8 @@
        my $tmp = tmpdir($package);
 
        delsubstvar($package, "python:Depends");
+       delsubstvar($package, "python:Provides");
+       delsubstvar($package, "python:Versions");
 
        my @dirs = ("usr/lib/site-python", "usr/lib/$package", 
"usr/share/$package", "usr/lib/games/$package", "usr/share/games/$package", 
@ARGV );
        my @dirs_so = ("usr/lib/site-python", @ARGV );
@@ -128,6 +238,42 @@
        my $strong_dep = 0;
        my $look_for_pythonXY = 1;
 
+       if ($version_fields{$package}) {
+               if (!$version_fields{"Source"}) {
+                       error("XS-Python-Version attribute missing in source 
package");
+               }
+               if (! -x "/usr/bin/pycentral") {
+                       error("python-central misssing, please install");
+               }
+               my $pycmd = "pycentral debhelper --stdout";
+               if ($dh{ONLYSCRIPTS}) {
+                       $pycmd = "$pycmd --no-act";
+               }
+               #if ($dh{ADD_PROVIDES}) {
+               #       $pycmd = "$pycmd --provides";
+               #}
+               #if ($dh{NO_MOVE}) {
+               #       $pycmd = "$pycmd --no-move";
+               #}
+               $pycmd = "$pycmd $package";
+               verbose_print("$pycmd");
+               open(PYCENTRAL, "$pycmd |") or die "cannot start pycentral";
+               while (<PYCENTRAL>) {
+                       chomp;
+                       if (/^([^=]+)=(.*)/) {
+                               addsubstvar($package, "$1", $2);
+                       } else {
+                               error("internal pycentral error: $_");
+                       }
+               }
+               close(PYCENTRAL) || exit $?;
+
+               if (! $dh{NOSCRIPTS}) {
+                       
autoscript($package,"postinst","postinst-pycentral","s%#PACKAGE#%$package%");
+                       
autoscript($package,"prerm","prerm-pycentral","s%#PACKAGE#%$package%");
+               }
+       } else {
+  # current behaviour of dh_python
        # First, the case of python-foo and pythonX.Y-foo
        if ($package =~ /^python-/) {
                $dep_on_python = 1;
@@ -261,6 +407,7 @@
        if ($need_prerm && ! $dh{NOSCRIPTS}) {
                
autoscript($package,"prerm","prerm-python","s%#PACKAGE#%$package%");
        }
+  }# current behaviour of dh_python
 }
 
 =head1 SEE ALSO


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to