| 1 |
#!/usr/bin/perl -w
|
| 2 |
|
| 3 |
=head1 NAME
|
| 4 |
|
| 5 |
dh_pysupport - use the python-support framework to handle Python modules
|
| 6 |
|
| 7 |
=cut
|
| 8 |
|
| 9 |
use strict;
|
| 10 |
use File::Find;
|
| 11 |
use Debian::Debhelper::Dh_Lib;
|
| 12 |
|
| 13 |
=head1 SYNOPSIS
|
| 14 |
|
| 15 |
B<dh_pysupport> [S<I<debhelper options>>] [-V I<X.Y>] [-n] [S<I<module dirs ...>>]
|
| 16 |
|
| 17 |
=head1 DESCRIPTION
|
| 18 |
|
| 19 |
dh_pysupport is a debhelper program that will scan your package, detect
|
| 20 |
public modules in I</usr/share/python-support> and generate appropriate
|
| 21 |
postinst/prerm scripts to byte-compile modules installed there for all
|
| 22 |
available python versions.
|
| 23 |
|
| 24 |
It will also look for private Python modules and will byte-compile them
|
| 25 |
with the current Python version. You may have to list the directories
|
| 26 |
containing private Python modules.
|
| 27 |
|
| 28 |
If a file named I<debian/pyversions> exists, it is installed in
|
| 29 |
I</usr/share/python-support/$PACKAGE/.version>.
|
| 30 |
|
| 31 |
=head1 OPTIONS
|
| 32 |
|
| 33 |
=over 4
|
| 34 |
|
| 35 |
=item I<module dirs>
|
| 36 |
|
| 37 |
If your package installs private python modules in non-standard directories, you
|
| 38 |
can make dh_pysupport check those directories by passing their names on the
|
| 39 |
command line. By default, it will check /usr/lib/$PACKAGE,
|
| 40 |
/usr/share/$PACKAGE, /usr/lib/games/$PACKAGE and /usr/share/games/$PACKAGE
|
| 41 |
|
| 42 |
=item B<-n>, B<--noscripts>
|
| 43 |
|
| 44 |
Do not modify postinst/postrm scripts.
|
| 45 |
|
| 46 |
=item B<-d>
|
| 47 |
|
| 48 |
Force generation of dependency information.
|
| 49 |
In normal operation, dh_pysupport only generates complete dependency information when no I<debian/pycompat> file is found. With this option, it will be generated regardless.
|
| 50 |
|
| 51 |
=item B<-V> I<X.Y>
|
| 52 |
|
| 53 |
Force private modules to be bytecompiled with the specific I<X.Y> python version, regardless of the default python version on the system.
|
| 54 |
|
| 55 |
=back
|
| 56 |
|
| 57 |
=head1 CONFORMS TO
|
| 58 |
|
| 59 |
Python policy as of 2006-06-10
|
| 60 |
|
| 61 |
=cut
|
| 62 |
|
| 63 |
init();
|
| 64 |
|
| 65 |
sub next_minor_version {
|
| 66 |
my $version = shift;
|
| 67 |
# Handles 2.10 -> 2.11 gracefully
|
| 68 |
my @items = split(/\./, $version);
|
| 69 |
$items[1] += 1;
|
| 70 |
$version = join(".", @items);
|
| 71 |
return $version;
|
| 72 |
}
|
| 73 |
|
| 74 |
# The current default python version
|
| 75 |
my $default=`pyversions -dv`;
|
| 76 |
chomp $default;
|
| 77 |
|
| 78 |
# All supported versions
|
| 79 |
my $allversions_string=`pyversions -sv`;
|
| 80 |
chomp $allversions_string;
|
| 81 |
my @allversions=split " ", $allversions_string;
|
| 82 |
|
| 83 |
# Use a specific version for private modules (doesn't affect public modules)
|
| 84 |
my $useversion;
|
| 85 |
if($dh{V_FLAG_SET}) {
|
| 86 |
$useversion = $dh{V_FLAG};
|
| 87 |
if (! grep { $_ eq $useversion } @allversions) {
|
| 88 |
error("Unknown python version $useversion");
|
| 89 |
}
|
| 90 |
}
|
| 91 |
|
| 92 |
# Generate dependencies if dh_python's debian/pycompat file isn't here
|
| 93 |
my $do_deps=1;
|
| 94 |
if (-f "debian/pycompat" && ! $dh{D_FLAG}) {
|
| 95 |
$do_deps=0;
|
| 96 |
}
|
| 97 |
|
| 98 |
|
| 99 |
foreach my $package (@{$dh{DOPACKAGES}}) {
|
| 100 |
my $tmp = tmpdir($package);
|
| 101 |
my $have_pydep=0; # This variable tells whether we have added some dependency
|
| 102 |
# on python one way or another.
|
| 103 |
|
| 104 |
# 1) Handle public python modules
|
| 105 |
# Move them to the python-support directories
|
| 106 |
doit (("pysupport-movemodules",$tmp));
|
| 107 |
# Then look for what the script found
|
| 108 |
foreach my $ps_dir (glob("$tmp/usr/share/python-support/*")) {
|
| 109 |
if (-d $ps_dir) {
|
| 110 |
my $verfile = "debian/pyversions";
|
| 111 |
if (-f $verfile) {
|
| 112 |
# TODO: debian/package.pyversions ?
|
| 113 |
doit("install","-p","-m644",$verfile,"$ps_dir/.version");
|
| 114 |
}
|
| 115 |
my $ext_dir=$ps_dir;
|
| 116 |
$ext_dir =~ s,/usr/share/,/usr/lib/,;
|
| 117 |
my $supported;
|
| 118 |
if (-d $ext_dir) {
|
| 119 |
if (-f "$ps_dir/.version") {
|
| 120 |
# Just ignore the .version file when there are extensions.
|
| 121 |
# The extensions dictate which versions to handle.
|
| 122 |
doit(("rm","-f","$ps_dir/.version"));
|
| 123 |
}
|
| 124 |
my @provides;
|
| 125 |
foreach my $pydir (glob("$ext_dir/python*")) {
|
| 126 |
if (-d $pydir && $pydir =~ m/python(\d+).(\d+)/) {
|
| 127 |
push @provides, "$1.$2";
|
| 128 |
}
|
| 129 |
}
|
| 130 |
my $a=join ",",@provides;
|
| 131 |
$supported=`echo $a | pysupport-parseversions --minmax`;
|
| 132 |
} elsif (! -f "$ps_dir/.version") {
|
| 133 |
my $doko_versions=`pysupport-parseversions --raw --pycentral debian/control`;
|
| 134 |
chomp $doko_versions;
|
| 135 |
if ($doko_versions !~ /not found/) {
|
| 136 |
print "Compatibility mode: using detected XS-Python-Version.\n";
|
| 137 |
complex_doit("echo $doko_versions > $ps_dir/.version");
|
| 138 |
}
|
| 139 |
}
|
| 140 |
if (-f "$ps_dir/.version") {
|
| 141 |
$supported=`pysupport-parseversions --minmax $ps_dir/.version`;
|
| 142 |
}
|
| 143 |
if ($do_deps && defined $supported) {
|
| 144 |
# Generate the provides field
|
| 145 |
my @ar=split "\n",$supported;
|
| 146 |
my @provides=split " ",$ar[0];
|
| 147 |
if ($package =~ /^python-/) {
|
| 148 |
foreach my $pyversion (@provides) {
|
| 149 |
my $virtual = $package;
|
| 150 |
$virtual =~ s/^python-/python$pyversion-/;
|
| 151 |
addsubstvar($package, "python:Provides", $virtual);
|
| 152 |
}
|
| 153 |
}
|
| 154 |
my @minmax=split " ",$ar[1];
|
| 155 |
my $minversion=$minmax[0];
|
| 156 |
if ( grep { $_ eq $default } @provides ) {
|
| 157 |
# The default version is in the supported versions
|
| 158 |
if ($minversion ne "None") {
|
| 159 |
addsubstvar($package, "python:Depends", "python (>= $minversion)");
|
| 160 |
}
|
| 161 |
} elsif ($minversion ne "None") {
|
| 162 |
# The default version is less than all supported versions
|
| 163 |
addsubstvar($package, "python:Depends", "python (>= $minversion) | python$minversion");
|
| 164 |
} else {
|
| 165 |
error("The default python version is greater than all supported versions");
|
| 166 |
}
|
| 167 |
my $maxversion=$minmax[1];
|
| 168 |
if ($maxversion ne "None") {
|
| 169 |
$maxversion = next_minor_version($maxversion);
|
| 170 |
addsubstvar($package, "python:Depends", "python (<< $maxversion)");
|
| 171 |
}
|
| 172 |
$have_pydep=1;
|
| 173 |
}
|
| 174 |
$ps_dir =~ s/^$tmp//;
|
| 175 |
if (! $dh{NOSCRIPTS}) {
|
| 176 |
autoscript($package, "postinst", "postinst-python-support", "s,#OPTIONS#,-i,;s,#DIRS#,$ps_dir,");
|
| 177 |
autoscript($package, "prerm", "prerm-python-support", "s,#OPTIONS#,-i,;s,#DIRS#,$ps_dir,");
|
| 178 |
}
|
| 179 |
}
|
| 180 |
}
|
| 181 |
|
| 182 |
# 2) Look for private python modules
|
| 183 |
my @dirs = ("/usr/lib/$package", "/usr/share/$package",
|
| 184 |
"/usr/lib/games/$package", "/usr/share/games/$package", @ARGV );
|
| 185 |
@dirs = grep -d, map "$tmp$_", @dirs;
|
| 186 |
my @dirlist;
|
| 187 |
my $have_pyversion=0;
|
| 188 |
my $need_pydep=0;
|
| 189 |
my %need_verdep = ();
|
| 190 |
foreach (@allversions) {
|
| 191 |
$need_verdep{$_} = 0;
|
| 192 |
}
|
| 193 |
if (@dirs) {
|
| 194 |
foreach my $curdir (@dirs) {
|
| 195 |
my $has_module = 0;
|
| 196 |
find sub {
|
| 197 |
return unless -f;
|
| 198 |
if (/.py$/) {
|
| 199 |
$has_module=1;
|
| 200 |
doit(("rm","-f",$_."c",$_."o"));
|
| 201 |
}
|
| 202 |
}, $curdir ;
|
| 203 |
if ( $has_module and not grep { $_ eq "$curdir" } @dirlist ) {
|
| 204 |
# Create .pyversion to tell update-python-modules for which
|
| 205 |
# version to compile
|
| 206 |
if ( $useversion ) {
|
| 207 |
open(VERFILE, "> $curdir/.pyversion") ||
|
| 208 |
error("Can't create $curdir/.pyversion: $!");
|
| 209 |
print VERFILE "$useversion\n";
|
| 210 |
close(VERFILE);
|
| 211 |
$have_pyversion=1;
|
| 212 |
$need_verdep{$useversion}=1;
|
| 213 |
} else {
|
| 214 |
$need_pydep=1;
|
| 215 |
}
|
| 216 |
$curdir =~ s%^$tmp%%;
|
| 217 |
push @dirlist, "$curdir";
|
| 218 |
}
|
| 219 |
}
|
| 220 |
}
|
| 221 |
if (@dirlist) {
|
| 222 |
# We have private python modules
|
| 223 |
# Use python-support to ensure that they are always
|
| 224 |
# byte-compiled for the current version
|
| 225 |
mkdir("$tmp/usr/share/python-support");
|
| 226 |
open(DIRLIST, "> $tmp/usr/share/python-support/$package.dirs") ||
|
| 227 |
error("Can't create $tmp/usr/share/python-support/$package.dirs: $!");
|
| 228 |
print DIRLIST map "$_\n", @dirlist;
|
| 229 |
close(DIRLIST);
|
| 230 |
autoscript($package, "postinst", "postinst-python-support", "s,#OPTIONS#,-b,;s,#DIRS#,$package.dirs,");
|
| 231 |
autoscript($package, "prerm", "prerm-python-support", "s,#OPTIONS#,-b,;s,#DIRS#,$package.dirs,");
|
| 232 |
}
|
| 233 |
|
| 234 |
# 3) Add python-support dependency depending on what we found
|
| 235 |
if (-d "$tmp/usr/share/python-support") {
|
| 236 |
if ( $have_pyversion ) {
|
| 237 |
# .pyversion introduced in 0.4
|
| 238 |
addsubstvar($package, "python:Depends", "python-support (>= 0.4) ");
|
| 239 |
} elsif (-d "$tmp/usr/lib/python-support") {
|
| 240 |
# /usr/lib split introduced in 0.3
|
| 241 |
addsubstvar($package, "python:Depends", "python-support (>= 0.3.4) ");
|
| 242 |
} else {
|
| 243 |
# stateless stuff introduced in 0.2
|
| 244 |
addsubstvar($package, "python:Depends", "python-support (>= 0.2) ");
|
| 245 |
}
|
| 246 |
}
|
| 247 |
|
| 248 |
# 4) Look for python scripts
|
| 249 |
if ($do_deps) {
|
| 250 |
find sub {
|
| 251 |
return unless -f and -x;
|
| 252 |
local *F;
|
| 253 |
return unless open F, $_;
|
| 254 |
if (read F, local $_, 32 and m%^#!\s*/usr/bin/(env\s+)?(python(\d+\.\d+)?)\s%) {
|
| 255 |
if ( "python" eq $2 ) {
|
| 256 |
$need_pydep=1;
|
| 257 |
} elsif (defined $need_verdep{$3}) {
|
| 258 |
$need_verdep{$3}=1;
|
| 259 |
}
|
| 260 |
}
|
| 261 |
close F;
|
| 262 |
}, $tmp;
|
| 263 |
}
|
| 264 |
|
| 265 |
# 5) Generate remaining dependencies
|
| 266 |
if ($do_deps) {
|
| 267 |
foreach (@allversions) {
|
| 268 |
if ($need_verdep{$_}) {
|
| 269 |
addsubstvar($package, "python:Depends", "python$_");
|
| 270 |
}
|
| 271 |
}
|
| 272 |
if ($need_pydep and not $have_pydep and -f "debian/pyversions") {
|
| 273 |
my $supported=`pysupport-parseversions --minmax debian/pyversions`;
|
| 274 |
my @ar=split "\n",$supported;
|
| 275 |
my @minmax=split " ",$ar[1];
|
| 276 |
my $minversion=$minmax[0];
|
| 277 |
if ($minversion ne "None") {
|
| 278 |
addsubstvar($package, "python:Depends", "python (>= $minversion)");
|
| 279 |
$have_pydep=1;
|
| 280 |
}
|
| 281 |
my $maxversion=$minmax[1];
|
| 282 |
if ($maxversion ne "None") {
|
| 283 |
$maxversion = next_minor_version($maxversion);
|
| 284 |
addsubstvar($package, "python:Depends", "python (<< $maxversion)");
|
| 285 |
$have_pydep=1;
|
| 286 |
}
|
| 287 |
}
|
| 288 |
if ($need_pydep and not $have_pydep and not -d "$tmp/usr/share/python-support") {
|
| 289 |
# Nothing else depends on python but we need it
|
| 290 |
addsubstvar($package, "python:Depends", "python");
|
| 291 |
}
|
| 292 |
}
|
| 293 |
}
|
| 294 |
|
| 295 |
=head1 SEE ALSO
|
| 296 |
|
| 297 |
L<debhelper(7)>
|
| 298 |
|
| 299 |
This program is a part of python-support but is made to work with debhelper.
|
| 300 |
|
| 301 |
=head1 AUTHORS
|
| 302 |
|
| 303 |
Josselin Mouette <joss@debian.org>,
|
| 304 |
Raphael Hertzog <hertzog@debian.org>
|
| 305 |
|
| 306 |
=cut
|