2006-12-05 22:58:38 +03:00
|
|
|
#
|
|
|
|
# Config object for release automation
|
|
|
|
#
|
|
|
|
|
|
|
|
package Bootstrap::Config;
|
|
|
|
|
|
|
|
use strict;
|
2007-05-09 06:02:33 +04:00
|
|
|
|
2006-12-05 22:58:38 +03:00
|
|
|
# shared static config
|
|
|
|
my %config;
|
|
|
|
|
|
|
|
# single shared instance
|
|
|
|
my $singleton = undef;
|
|
|
|
|
|
|
|
sub new {
|
|
|
|
my $proto = shift;
|
|
|
|
my $class = ref($proto) || $proto;
|
|
|
|
|
|
|
|
return $singleton if defined $singleton;
|
|
|
|
|
|
|
|
my $this = {};
|
|
|
|
bless($this, $class);
|
|
|
|
$this->Parse();
|
|
|
|
$singleton = $this;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub Parse {
|
|
|
|
my $this = shift;
|
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
open (CONFIG, "< bootstrap.cfg")
|
2007-02-08 01:14:24 +03:00
|
|
|
|| die("Can't open config file bootstrap.cfg");
|
2006-12-05 22:58:38 +03:00
|
|
|
|
|
|
|
while (<CONFIG>) {
|
2007-03-23 02:01:14 +03:00
|
|
|
chomp; # no newline
|
|
|
|
s/#.*//; # no comments
|
2006-12-05 22:58:38 +03:00
|
|
|
s/^\s+//; # no leading white
|
|
|
|
s/\s+$//; # no trailing white
|
2007-03-23 02:01:14 +03:00
|
|
|
next unless length; # anything left?
|
2006-12-05 22:58:38 +03:00
|
|
|
my ($var, $value) = split(/\s*=\s*/, $_, 2);
|
2007-03-23 02:01:14 +03:00
|
|
|
$config{$var} = $value;
|
2006-12-05 22:58:38 +03:00
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
close CONFIG;
|
2006-12-05 22:58:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
sub Get {
|
|
|
|
my $this = shift;
|
|
|
|
|
|
|
|
my %args = @_;
|
|
|
|
my $var = $args{'var'};
|
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
die "ASSERT: Bootstep::Config::Get(): null var requested" if (not
|
|
|
|
defined($args{'var'}));
|
2007-03-26 03:54:25 +04:00
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
if ($this->Exists(var => $var)) {
|
2006-12-05 22:58:38 +03:00
|
|
|
return $config{$var};
|
|
|
|
} else {
|
2007-03-23 02:01:14 +03:00
|
|
|
die("No such config variable: $var\n");
|
2008-01-08 20:39:11 +03:00
|
|
|
}
|
2008-04-28 17:48:27 +04:00
|
|
|
}
|
|
|
|
|
2007-02-09 04:23:34 +03:00
|
|
|
sub Exists {
|
|
|
|
my $this = shift;
|
|
|
|
my %args = @_;
|
2007-03-26 03:54:25 +04:00
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
die "ASSERT: Bootstep::Config::Exists(): null var requested" if (not
|
|
|
|
defined($args{'var'}));
|
2007-03-10 00:20:05 +03:00
|
|
|
|
2007-02-09 04:23:34 +03:00
|
|
|
my $var = $args{'var'};
|
2007-03-23 02:01:14 +03:00
|
|
|
return exists($config{$var});
|
2007-04-18 02:49:31 +04:00
|
|
|
}
|
|
|
|
|
2006-12-05 22:58:38 +03:00
|
|
|
1;
|