summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphaël Hertzog <hertzog@debian.org>2010-02-19 19:45:40 +0100
committerRaphaël Hertzog <hertzog@debian.org>2010-02-20 22:28:18 +0100
commitaba76e6de21438ada3d6df542021d341fb499dcc (patch)
tree048a5fae301bc58cebb123db5c5c82d7386a15eb
parent93f179a39dfd081e2a50dd258a322025004f6023 (diff)
downloaddpkg-aba76e6de21438ada3d6df542021d341fb499dcc.tar.gz
Update Dpkg::Substvars to use Dpkg::Interface::Storable
The parse() function is replaced by load() for most users.
-rw-r--r--scripts/Dpkg/Substvars.pm67
-rwxr-xr-xscripts/dpkg-genchanges.pl2
-rwxr-xr-xscripts/dpkg-gencontrol.pl2
-rwxr-xr-xscripts/dpkg-source.pl2
-rw-r--r--scripts/t/750_Dpkg_Substvars.t2
5 files changed, 53 insertions, 22 deletions
diff --git a/scripts/Dpkg/Substvars.pm b/scripts/Dpkg/Substvars.pm
index 0ec04ba56..8ef3158bb 100644
--- a/scripts/Dpkg/Substvars.pm
+++ b/scripts/Dpkg/Substvars.pm
@@ -1,4 +1,4 @@
-# Copyright © 2007,2009 Raphaël Hertzog <hertzog@debian.org>
+# Copyright © 2007-2010 Raphaël Hertzog <hertzog@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -25,6 +25,8 @@ use Dpkg::Gettext;
use POSIX qw(:errno_h);
+use base qw(Dpkg::Interface::Storable);
+
my $maxsubsts = 50;
=head1 NAME
@@ -71,7 +73,7 @@ sub new {
bless $self, $class;
$self->no_warn($_) foreach keys %{$self->{'vars'}};
if ($arg) {
- $self->parse($arg);
+ $self->load($arg) if -e $arg;
}
return $self;
}
@@ -122,28 +124,27 @@ sub no_warn {
$self->{'used'}{$key}++;
}
-=item $s->parse($file)
+=item $s->load($file)
Add new substitutions read from $file.
+=item $s->parse($fh, $desc)
+
+Add new substitutions read from the filehandle. $desc is used to identify
+the filehandle in error messages.
+
=cut
sub parse {
- my ($self, $varlistfile) = @_;
- $varlistfile = "./$varlistfile" if $varlistfile =~ m/\s/;
- if (open(SV, "<", $varlistfile)) {
- binmode(SV);
- while (<SV>) {
- next if m/^\s*\#/ || !m/\S/;
- s/\s*\n$//;
- m/^(\w[-:0-9A-Za-z]*)\=(.*)$/ ||
- error(_g("bad line in substvars file %s at line %d"),
- $varlistfile, $.);
- $self->{'vars'}{$1} = $2;
- }
- close(SV);
- } elsif ($! != ENOENT) {
- error(_g("unable to open substvars file %s: %s"), $varlistfile, $!);
+ my ($self, $fh, $varlistfile) = @_;
+ binmode($fh);
+ while (<$fh>) {
+ next if m/^\s*\#/ || !m/\S/;
+ s/\s*\n$//;
+ m/^(\w[-:0-9A-Za-z]*)\=(.*)$/ ||
+ error(_g("bad line in substvars file %s at line %d"),
+ $varlistfile, $.);
+ $self->{'vars'}{$1} = $2;
}
}
@@ -238,6 +239,36 @@ sub warn_about_unused {
}
}
+=item $s->save($file)
+
+Store all substitutions variables except the automatic ones in the
+indicated file.
+
+=item "$s"
+
+Return a string representation of all substitutions variables except the
+automatic ones.
+
+=item $str = $s->output($fh)
+
+Print all substitutions variables except the automatic ones in the
+filehandle and return the content written.
+
+=cut
+
+sub output {
+ my ($self, $fh) = @_;
+ my $str = "";
+ # Store all non-automatic substitutions only
+ foreach my $vn (sort keys %{$self->{'vars'}}) {
+ next if /^(?:(?:dpkg|source|binary):(?:Source-)?Version|Space|Tab|Newline|Arch|Source-Version|F:.+)$/;
+ my $line = "$vn=" . $self->{vars}{$vn} . "\n";
+ print $fh $line if defined $fh;
+ $str .= $line;
+ }
+ return $str;
+}
+
=back
=head1 AUTHOR
diff --git a/scripts/dpkg-genchanges.pl b/scripts/dpkg-genchanges.pl
index df5557641..5493a9591 100755
--- a/scripts/dpkg-genchanges.pl
+++ b/scripts/dpkg-genchanges.pl
@@ -210,7 +210,7 @@ my $control = Dpkg::Control::Info->new($controlfile);
my $fields = Dpkg::Control->new(type => CTRL_FILE_CHANGES);
$substvars->set_version_substvars($changelog->{"Version"});
$substvars->set_arch_substvars();
-$substvars->parse($varlistfile) if -e $varlistfile;
+$substvars->load($varlistfile) if -e $varlistfile;
if (defined($prev_changelog) and
version_compare_relation($changelog->{"Version"}, REL_LT,
diff --git a/scripts/dpkg-gencontrol.pl b/scripts/dpkg-gencontrol.pl
index f135036ac..605fe84df 100755
--- a/scripts/dpkg-gencontrol.pl
+++ b/scripts/dpkg-gencontrol.pl
@@ -138,7 +138,7 @@ $options{"changelogformat"} = $changelogformat if $changelogformat;
my $changelog = changelog_parse(%options);
$substvars->set_version_substvars($changelog->{"Version"});
$substvars->set_arch_substvars();
-$substvars->parse($varlistfile) if -e $varlistfile;
+$substvars->load($varlistfile) if -e $varlistfile;
$substvars->set("binary:Version", $forceversion) if defined $forceversion;
my $control = Dpkg::Control::Info->new($controlfile);
my $fields = Dpkg::Control->new(type => CTRL_PKG_DEB);
diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl
index 7a7517abc..1c0151133 100755
--- a/scripts/dpkg-source.pl
+++ b/scripts/dpkg-source.pl
@@ -325,7 +325,7 @@ if ($options{'opmode'} =~ /^(-b|--print-format)$/) {
# Write the .dsc
my $dscname = $srcpkg->get_basename(1) . ".dsc";
info(_g("building %s in %s"), $sourcepackage, $dscname);
- $substvars->parse($varlistfile) if $varlistfile && -e $varlistfile;
+ $substvars->load($varlistfile) if $varlistfile && -e $varlistfile;
$srcpkg->write_dsc(filename => $dscname,
remove => \%remove,
override => \%override,
diff --git a/scripts/t/750_Dpkg_Substvars.t b/scripts/t/750_Dpkg_Substvars.t
index ae4609f5c..f7e03a56f 100644
--- a/scripts/t/750_Dpkg_Substvars.t
+++ b/scripts/t/750_Dpkg_Substvars.t
@@ -28,7 +28,7 @@ my $datadir = $srcdir . '/t/750_Dpkg_Substvars';
my $s = Dpkg::Substvars->new();
-$s->parse("$datadir/substvars1");
+$s->load("$datadir/substvars1");
# simple value tests
is($s->get('var1'), 'Some value', 'var1');