From 6686e2c66cd9bd3153b770f1cea103f29a938dec Mon Sep 17 00:00:00 2001 From: Steve McIntyre <93sam@debian.org> Date: Tue, 5 Jun 2012 13:56:51 +0000 Subject: [PATCH] Clean up handling of environment variable handling in perl tools. --- debian/changelog | 1 + tools/link.pl | 17 +++++++-- tools/make_disc_trees.pl | 74 +++++++++++----------------------------- tools/sort_deps | 33 +++++++++++++----- tools/sort_deps_edu | 29 +++++++++++----- 5 files changed, 79 insertions(+), 75 deletions(-) diff --git a/debian/changelog b/debian/changelog index ba61d390..a693b8df 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,7 @@ debian-cd (3.1.9) UNRELEASED; urgency=low * Add dependency on xorriso. Closes: #673656 * Describe discs appropriately depending on the kernel used. Closes: #673975 + * Clean up handling of environment variable handling in perl tools. -- Steve McIntyre <93sam@debian.org> Tue, 29 May 2012 06:20:20 +0800 diff --git a/tools/link.pl b/tools/link.pl index d0494dd5..e7b18111 100644 --- a/tools/link.pl +++ b/tools/link.pl @@ -1,6 +1,17 @@ -my $symlink_farm = $ENV{'SYMLINK'} || 0; -my $link_verbose = $ENV{'VERBOSE'} || 0; -my $link_copy = $ENV{'COPYLINK'} || 0; +my $symlink_farm = read_env('SYMLINK', 0); +my $link_verbose = read_env('VERBOSE', 0); +my $link_copy = read_env('COPYLINK', 0); + +sub read_env { + my $env_var = shift; + my $default = shift; + + if (exists($ENV{$env_var})) { + return $ENV{$env_var}; + } + # else + return $default; +} sub good_link ($$) { my ($src, $dest) = @_; diff --git a/tools/make_disc_trees.pl b/tools/make_disc_trees.pl index ab667758..f3db91fb 100755 --- a/tools/make_disc_trees.pl +++ b/tools/make_disc_trees.pl @@ -37,46 +37,31 @@ $archlist = shift; $mkisofs = shift; $mkisofs_base_opts = shift; -my $security = $ENV{'SECURITY'} || $mirror; -my $localdebs = $ENV{'LOCALDEBS'} || $mirror; my $iso_blksize = 2048; my $log_opened = 0; my $old_split = $/; -my $symlink_farm = $ENV{'SYMLINK'} || 0; -my $link_verbose = $ENV{'VERBOSE'} || 0; -my $link_copy = $ENV{'COPYLINK'} || 0; +my $security = read_env('SECURITY', $mirror); +my $localdebs = read_env('LOCALDEBS', $mirror); +my $symlink_farm = read_env('SYMLINK', 0); +my $link_verbose = read_env('VERBOSE', 0); +my $link_copy = read_env('COPYLINK', 0); require "$basedir/tools/link.pl"; -$maxcds = 9999; - # MAXCDS is the hard limit on the MAXIMUM number of images to # make. MAXJIGDOS and MAXISOS can only make this number smaller; we # will use the higher of those 2 numbers as the last image to go to, # if they're set +$maxcds = read_env('MAXCDS', 9999); -if (defined($ENV{'MAXCDS'})) { - $maxcds = $ENV{'MAXCDS'}; -} else { - $maxcds = 9999; +$maxisos = read_env('MAXISOS', 9999); +if ($maxisos =~ 'ALL' || $maxisos =~ 'all') { + $maxisos = 9999; } -if (defined($ENV{'MAXISOS'})) { - $maxisos = $ENV{'MAXISOS'}; - if ($maxisos =~ 'ALL' || $maxisos =~ 'all') { - $maxisos = 9999; - } -} else { - $maxisos = 9999; -} - -if (defined($ENV{'MAXJIGDOS'})) { - $maxjigdos = $ENV{'MAXJIGDOS'}; - if ($maxjigdos =~ 'ALL' || $maxjigdos =~ 'all') { - $maxjigdos = 9999; - } -} else { - $maxjigdos = 9999; +$maxjigdos = read_env('MAXJIGDOS', 9999); +if ($maxjigdos =~ 'ALL' || $maxjigdos =~ 'all') { + $maxjigdos = 9999; } if ($maxisos > $maxjigdos) { @@ -91,26 +76,10 @@ if ($maxisos < $maxcds) { $maxcds = $maxisos; } -if (defined($ENV{'EXTRANONFREE'})) { - $extranonfree = $ENV{'EXTRANONFREE'}; -} else { - $extranonfree = 0; -} -if (defined($ENV{'NONFREE'})) { - $nonfree = $ENV{'NONFREE'}; -} else { - $nonfree = 0; -} -if (defined($ENV{'CONTRIB'})) { - $contrib = $ENV{'CONTRIB'}; -} else { - $contrib = 0; -} -if (defined($ENV{'LOCAL'})) { - $use_local = $ENV{'LOCAL'}; -} else { - $use_local = 0; -} +$extranonfree = read_env('EXTRANONFREE', 0); +$nonfree = read_env('NONFREE', 0); +$contrib = read_env('CONTRIB', 0); +$use_local = read_env('LOCAL', 0); my $list = "$tdir/list"; my $bdir = "$tdir/$codename"; @@ -173,10 +142,7 @@ my $size = 0; my $guess_size = 0; my @overflowpkg; my $mkisofs_check = "$mkisofs $mkisofs_base_opts -r -print-size -quiet"; -my $debootstrap_script = ""; -if (defined ($ENV{'DEBOOTSTRAP_SCRIPT'})) { - $debootstrap_script = $ENV{'DEBOOTSTRAP_SCRIPT'}; -} +my $debootstrap_script = read_env('DEBOOTSTRAP_SCRIPT', ""); chdir $bdir; @@ -685,7 +651,7 @@ sub get_disc_size { } # See if we've been asked to switch sizes for the whole set - $disk_size_hack = $ENV{'FORCE_CD_SIZE'} || ""; + $disk_size_hack = read_env('FORCE_CD_SIZE', ""); if ($disk_size_hack) { print LOG "HACK HACK HACK: FORCE_CD_SIZE found:\n"; print LOG " forcing use of a $disk_size_hack disk instead of $chosen_disk\n"; @@ -693,7 +659,7 @@ sub get_disc_size { } # If we're asked to do a specific size for *this* disknum, over-ride again - $disk_size_hack = $ENV{"FORCE_CD_SIZE$disknum"} || ""; + $disk_size_hack = read_env("FORCE_CD_SIZE$disknum", ""); if ($disk_size_hack) { print LOG "HACK HACK HACK: FORCE_CD_SIZE$disknum found:\n"; print LOG " forcing use of a $disk_size_hack disk instead of $chosen_disk\n"; @@ -740,7 +706,7 @@ sub get_disc_size { $maxdiskblocks = int(8 * $GB / $blocksize) - $reserved; $diskdesc = "8GB STICK"; } elsif ($chosen_disk eq "CUSTOM") { - $maxdiskblocks = $ENV{'CUSTOMSIZE'} - $reserved || + $maxdiskblocks = $ENV{'CUSTOMSIZE'} - $reserved || die "Need to specify a custom size for the CUSTOM disktype\n"; $diskdesc = "User-supplied size"; } diff --git a/tools/sort_deps b/tools/sort_deps index 3ae92663..b94aae5b 100755 --- a/tools/sort_deps +++ b/tools/sort_deps @@ -16,20 +16,20 @@ use strict; my $list = shift; -my $nonfree = $ENV{'NONFREE'} || 0; -my $extranonfree = $ENV{'EXTRANONFREE'} || 0; -my $force_firmware = $ENV{'FORCE_FIRMWARE'} || 0; -my $local = $ENV{'LOCAL'} || 0; -my $complete = $ENV{'COMPLETE'} || 0; -my $norecommends = $ENV{'NORECOMMENDS'} || 1; -my $nosuggests = $ENV{'NOSUGGESTS'} || 1; +my $nonfree = read_env('NONFREE', 0); +my $extranonfree = read_env('EXTRANONFREE', 0); +my $force_firmware = read_env('FORCE_FIRMWARE', 0); +my $local = read_env('LOCAL', 0); +my $complete = read_env('COMPLETE', 0); +my $norecommends = read_env('NORECOMMENDS', 1); +my $nosuggests = read_env('NOSUGGESTS', 1); +my $verbose = read_env('VERBOSE', 0); +my $max_pkg_size = read_env('MAX_PKG_SIZE', 9999999999999); my $apt = "$ENV{'BASEDIR'}/tools/apt-selection"; my $adir = "$ENV{'APTTMP'}/$ENV{'CODENAME'}-$ENV{'ARCH'}"; my $arch = "$ENV{'ARCH'}"; my $dir = "$ENV{'TDIR'}/$ENV{'CODENAME'}"; -my $verbose = $ENV{'VERBOSE'} || 0; -my $max_pkg_size = $ENV{'MAX_PKG_SIZE'} || 9999999999999; my @output; @@ -38,6 +38,17 @@ $| = 1; # Autoflush for debugging open(LOG, ">$dir/sort_deps.$arch.log") || die "Can't write in $dir/sort_deps.$arch.log !\n"; +sub read_env { + my $env_var = shift; + my $default = shift; + + if (exists($ENV{$env_var})) { + return $ENV{$env_var}; + } + # else + return $default; +} + sub msg { my $level = shift; if ($verbose >= $level) { @@ -63,6 +74,10 @@ msg(1, "Include non-free packages: "); msg(1, yesno($nonfree)."\n"); msg(1, "Force inclusion of firmware packages: "); msg(1, yesno($force_firmware)."\n"); +msg(1, "Ignore Recommends: "); +msg(1, yesno($norecommends)."\n"); +msg(1, "Ignore Suggests: "); +msg(1, yesno($nosuggests)."\n"); msg(1, "====================================================================== "); diff --git a/tools/sort_deps_edu b/tools/sort_deps_edu index c218a7bb..8c232be2 100755 --- a/tools/sort_deps_edu +++ b/tools/sort_deps_edu @@ -20,20 +20,20 @@ use strict; my $list = shift; -my $nonfree = $ENV{'NONFREE'} || 0; -my $extranonfree = $ENV{'EXTRANONFREE'} || 0; -my $force_firmware = $ENV{'FORCE_FIRMWARE'} || 0; -my $local = $ENV{'LOCAL'} || 0; -my $complete = $ENV{'COMPLETE'} || 0; -my $norecommends = (defined $ENV{'NORECOMMENDS'} ? $ENV{'NORECOMMENDS'} : 1); -my $nosuggests = $ENV{'NOSUGGESTS'} || 1; +my $nonfree = read_env('NONFREE', 0); +my $extranonfree = read_env('EXTRANONFREE', 0); +my $force_firmware = read_env('FORCE_FIRMWARE', 0); +my $local = read_env('LOCAL', 0); +my $complete = read_env('COMPLETE', 0); +my $norecommends = read_env('NORECOMMENDS', 1); +my $nosuggests = read_env('NOSUGGESTS', 1); +my $verbose = read_env('VERBOSE', 0); +my $max_pkg_size = read_env('MAX_PKG_SIZE', 9999999999999); my $apt = "$ENV{'BASEDIR'}/tools/apt-selection"; my $adir = "$ENV{'APTTMP'}/$ENV{'CODENAME'}-$ENV{'ARCH'}"; my $arch = "$ENV{'ARCH'}"; my $dir = "$ENV{'TDIR'}/$ENV{'CODENAME'}"; -my $verbose = $ENV{'VERBOSE'} || 0; -my $max_pkg_size = $ENV{'MAX_PKG_SIZE'} || 9999999999999; my @output; @@ -42,6 +42,17 @@ $| = 1; # Autoflush for debugging open(LOG, ">$dir/sort_deps.$arch.log") || die "Can't write in $dir/sort_deps.$arch.log !\n"; +sub read_env { + my $env_var = shift; + my $default = shift; + + if (exists($ENV{$env_var})) { + return $ENV{$env_var}; + } + # else + return $default; +} + sub msg { my $level = shift; if ($verbose >= $level) {