aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Guldstrand <andreas.guldstrand@gmail.com>2015-11-19 15:59:08 +0100
committerAndreas Guldstrand <andreas.guldstrand@gmail.com>2015-11-19 15:59:08 +0100
commit815a350b74918bc72c60d799d3a856952bd1683d (patch)
treeb975dda5a3fe1bad32e05e64702f940b1ae9faa2
parent712ea0ac188aa2a22df1c3aca4cf4f17adf6b69e (diff)
downloadsbotools2-815a350b74918bc72c60d799d3a856952bd1683d.tar.xz
Fixed .info file parsing
This fixes #5 Also added tests for #5
-rw-r--r--SBO-Lib/lib/SBO/Lib.pm25
-rw-r--r--t/sbo/multimedia/mpv/mpv.info12
-rwxr-xr-xt/test.t9
3 files changed, 33 insertions, 13 deletions
diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm
index 4bf7394..ec9f4de 100644
--- a/SBO-Lib/lib/SBO/Lib.pm
+++ b/SBO-Lib/lib/SBO/Lib.pm
@@ -364,25 +364,24 @@ sub get_from_info {
}
state $store = {PRGNAM => ['']};
my $sbo = get_sbo_from_loc($args{LOCATION});
- return $$store{$args{GET}} if $$store{PRGNAM}[0] eq $sbo;
+ return $store->{$args{GET}} if $store->{PRGNAM}[0] eq $sbo;
# if we're here, we haven't read in the .info file yet.
my ($fh, $exit) = open_read("$args{LOCATION}/$sbo.info");
return() if $exit;
# suck it all in, clean it all up, stuff it all in $store.
my $contents = do {local $/; <$fh>};
$contents =~ s/("|\\\n)//g;
- $store = {$contents =~ /^(\w+)=(.*)$/mg};
- # fill the hash with array refs - even for single values,
- # since consistency here is a lot easier than sorting it out later
- for my $key (keys %$store) {
- if ($$store{$key} =~ /\s/) {
- my @array = split ' ', $$store{$key};
- $$store{$key} = \@array;
- } else {
- $$store{$key} = [$$store{$key}];
- }
- }
- return exists $$store{$args{GET}} ? $$store{$args{GET}} : undef;
+ my $last_key = '';
+ $store = {};
+ foreach my $line (split /\n/, $contents) {
+ my ($key, $val) = $last_key;
+ if ($line =~ /^([^=\s]+)=(.*)$/) { $key = $1; $val = $2; }
+ elsif ($line =~ /^\s+([^\s].+)$/) { $val = $1; }
+ else { script_error("error when parsing $sbo.info file. Line: $line") }
+ push @{ $store->{$key} }, ($val ? split(' ', $val) : $val);
+ $last_key = $key;
+ }
+ return $store->{$args{GET}};
}
# find the version in the tree for a given sbo (provided a location)
diff --git a/t/sbo/multimedia/mpv/mpv.info b/t/sbo/multimedia/mpv/mpv.info
new file mode 100644
index 0000000..a84d236
--- /dev/null
+++ b/t/sbo/multimedia/mpv/mpv.info
@@ -0,0 +1,12 @@
+PRGNAM="mpv"
+VERSION="0.10.0"
+HOMEPAGE="http://mpv.io"
+DOWNLOAD="https://github.com/mpv-player/mpv/archive/v0.10.0.tar.gz
+ http://www.freehackers.org/~tnagy/release/waf-1.8.12"
+MD5SUM="e81a975e4fa17f500dc2e7ea3d3ecf25
+ cef4ee82206b1843db082d0b0506bf71"
+DOWNLOAD_x86_64=""
+MD5SUM_x86_64=""
+REQUIRES="ffmpeg libass docutils"
+MAINTAINER="John Vogel"
+EMAIL="jvogel4@stny.rr.com"
diff --git a/t/test.t b/t/test.t
index 8b5eeb4..f2031e7 100755
--- a/t/test.t
+++ b/t/test.t
@@ -159,6 +159,15 @@ my $downloads = get_sbo_downloads(LOCATION => "$sbo_home/system/ifuse");
$link = 'http://www.libimobiledevice.org/downloads/ifuse-1.1.1.tar.bz2';
is($$downloads{$link}, '8d528a79de024b91f12f8ac67965c37c',
'get_sbo_downloads test 03 good.');
+$downloads = get_sbo_downloads(LOCATION => "$sbo_home/multimedia/mpv");
+my @links = qw'
+ https://github.com/mpv-player/mpv/archive/v0.10.0.tar.gz
+ http://www.freehackers.org/~tnagy/release/waf-1.8.12
+';
+is ($$downloads{$links[0]}, 'e81a975e4fa17f500dc2e7ea3d3ecf25',
+ 'get_sbo_downloads test 04 good.');
+is ($$downloads{$links[1]}, 'cef4ee82206b1843db082d0b0506bf71',
+ 'get_sbo_downloads test 05 good.');
# get_filename_from_link test
is(get_filename_from_link(