aboutsummaryrefslogtreecommitdiff
path: root/SBO-Lib/lib
diff options
context:
space:
mode:
Diffstat (limited to 'SBO-Lib/lib')
-rw-r--r--SBO-Lib/lib/SBO/Lib/Info.pm45
-rw-r--r--SBO-Lib/lib/SBO/Lib/Readme.pm27
-rw-r--r--SBO-Lib/lib/SBO/Lib/Repo.pm2
-rw-r--r--SBO-Lib/lib/SBO/Lib/Util.pm18
4 files changed, 78 insertions, 14 deletions
diff --git a/SBO-Lib/lib/SBO/Lib/Info.pm b/SBO-Lib/lib/SBO/Lib/Info.pm
index 3f20497..91a96e0 100644
--- a/SBO-Lib/lib/SBO/Lib/Info.pm
+++ b/SBO-Lib/lib/SBO/Lib/Info.pm
@@ -18,6 +18,7 @@ our @EXPORT_OK = qw{
get_orig_version
get_requires
get_sbo_version
+ parse_info
};
our %EXPORT_TAGS = (
@@ -132,18 +133,13 @@ sub get_from_info {
usage_error("get_from_info: could not read $args{LOCATION}/$sbo.info.") unless
defined $contents;
- $contents =~ s/("|\\\n)//g;
- my $last_key = '';
+ my %parse = parse_info($contents);
+ script_error("error when parsing $sbo.info file.") unless %parse;
+
$store = {};
$store->{LOCATION} = [$args{LOCATION}];
- 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;
- }
+ foreach my $k (keys %parse) { $store->{$k} = $parse{$k}; }
+
# allow local overrides to get away with not having quite all the fields
if (is_local($sbo)) {
for my $key (qw/DOWNLOAD_x86_64 MD5SUM_x86_64 REQUIRES/) {
@@ -205,6 +201,35 @@ sub get_sbo_version {
return $version->[0];
}
+=head2 parse_info
+
+ my %parse = parse_info($str);
+
+C<parse_info()> parses the contents of an .info file from C<$str> and returns
+a key-value list of it.
+
+=cut
+
+sub parse_info {
+ script_error('parse_info requires an argument.') unless @_ == 1;
+ my $info_str = shift;
+ my $pos = 0;
+ my %ret;
+
+ while ($info_str =~ /\G([A-Za-z0-9_]+)="([^"]*)"\n/g) {
+ my $key = $1;
+ my @val = split " ", $2;
+ @val = '' unless @val;
+ $ret{$key} = \@val;
+ $pos = pos($info_str);
+ }
+
+ return if $pos != length($info_str);
+
+ return %ret;
+
+}
+
=head1 AUTHORS
SBO::Lib was originally written by Jacob Pipkin <j@dawnrazor.net> with
diff --git a/SBO-Lib/lib/SBO/Lib/Readme.pm b/SBO-Lib/lib/SBO/Lib/Readme.pm
index b29558b..d365a8a 100644
--- a/SBO-Lib/lib/SBO/Lib/Readme.pm
+++ b/SBO-Lib/lib/SBO/Lib/Readme.pm
@@ -13,6 +13,7 @@ use Exporter 'import';
our @EXPORT_OK = qw{
ask_opts
+ ask_other_readmes
ask_user_group
get_opts
get_readme_contents
@@ -77,6 +78,31 @@ sub ask_opts {
return();
}
+=head2 ask_other_readmes
+
+ ask_other_readmes($sbo, $location);
+
+C<ask_other_readmes()> checks if there are other readmes for the C<$sbo> in
+C<$location>, and if so, asks the user if they should be displayed, and then
+displays them if the user didn't decline.
+
+=cut
+
+sub ask_other_readmes {
+ my ($sbo, $location) = @_;
+ my @readmes = sort grep { ! m!/README$! } glob "$location/README*";
+
+ return unless @readmes;
+
+ return unless prompt("\nIt looks like $sbo has additional README files. Would you like to see those too?", default => 'yes');
+
+ for my $fn (@readmes) {
+ my ($display_fn) = $fn =~ m!/(README.*)$!;
+ say "\n$display_fn:";
+ say slurp $fn;
+ }
+}
+
=head2 ask_user_group
my $bool = ask_user_group($cmds, $readme);
@@ -183,6 +209,7 @@ sub user_prompt {
my $opts = 0;
$opts = ask_opts($sbo, $readme) if get_opts($readme);
print "\n". $readme unless $opts;
+ ask_other_readmes($sbo, $location);
# we have to return something substantial if the user says no so that we
# can check the value of $cmds on the calling side. we should be able to
# assume that 'N' will never be a valid command to run.
diff --git a/SBO-Lib/lib/SBO/Lib/Repo.pm b/SBO-Lib/lib/SBO/Lib/Repo.pm
index e920b6b..1330073 100644
--- a/SBO-Lib/lib/SBO/Lib/Repo.pm
+++ b/SBO-Lib/lib/SBO/Lib/Repo.pm
@@ -242,7 +242,7 @@ sub git_sbo_tree {
} else {
chdir $config{SBO_HOME} or return 0;
remove_tree($repo_path) if -d $repo_path;
- $res = system(qw/ git clone /, $url, $repo_path) == 0;
+ $res = system(qw/ git clone --no-local /, $url, $repo_path) == 0;
}
_race::cond '$cwd could be deleted here';
return 1 if chdir $cwd and $res;
diff --git a/SBO-Lib/lib/SBO/Lib/Util.pm b/SBO-Lib/lib/SBO/Lib/Util.pm
index c4128af..6c38382 100644
--- a/SBO-Lib/lib/SBO/Lib/Util.pm
+++ b/SBO-Lib/lib/SBO/Lib/Util.pm
@@ -506,20 +506,32 @@ sub usage_error {
C<version_cmp()> will compare C<$ver1> with C<$ver2> to try to determine which
is bigger than the other, and returns 1 if C<$ver1> is bigger, -1 if C<$ver2>
is bigger, and 0 if they are just as big. Before making the comparison, it will
-strip off the version of your running kernel if it happens to be appended to
-the version string being compared.
+strip off the version of your running kernel as well as any locale information
+if it happens to be appended to the version string being compared.
=cut
# wrapper around versioncmp for checking if versions have kernel version
-# appended to them
+# or locale info appended to them
sub version_cmp {
my ($v1, $v2) = @_;
my $kv = get_kernel_version();
+ # strip off kernel version
if ($v1 =~ /(.+)_\Q$kv\E$/) { $v1 = $1 }
if ($v2 =~ /(.+)_\Q$kv\E$/) { $v2 = $1 }
+ # if $v2 doesn't end in the same thing, strip off locale info from $v1
+ if ($v1 =~ /(.*)_([a-z]{2})_([A-Z]{2})$/) {
+ my $v = $1;
+ if ($v2 !~ /_$2_$3$/) { $v1 = $v; }
+ }
+ # and vice versa...
+ if ($v2 =~ /(.*)_([a-z]{2})_([A-Z]{2})$/) {
+ my $v = $1;
+ if ($v1 !~ /_$2_$3$/) { $v2 = $v; }
+ }
+
versioncmp($v1, $v2);
}