Commit bfc517c0 authored by Dietmar Maurer's avatar Dietmar Maurer

APLInfo: split out code into read_aplinfo_from_fh

So that we can call the parser for any $fh. Add new type 'lxc'.
parent 2b2502c0
...@@ -48,82 +48,86 @@ sub logmsg { ...@@ -48,82 +48,86 @@ sub logmsg {
} }
} }
sub read_aplinfo { sub read_aplinfo_from_fh {
my ($filename, $list, $source, $update) = @_; my ($fh, $list, $source, $update) = @_;
my $fh = IO::File->new("<$filename") ||
die "unable to open file '$filename' - $!\n";
local $/ = ""; local $/ = "";
eval { while (my $rec = <$fh>) {
while (my $rec = <$fh>) { chomp $rec;
chomp $rec;
my $res = {}; my $res = {};
while ($rec) { while ($rec) {
if ($rec =~ s/^Description:\s*([^\n]*)(\n\s+.*)*$//si) { if ($rec =~ s/^Description:\s*([^\n]*)(\n\s+.*)*$//si) {
$res->{headline} = $1; $res->{headline} = $1;
my $long = $2; my $long = $2;
$long =~ s/\n\s+/ /g; $long =~ s/\n\s+/ /g;
$long =~ s/^\s+//g; $long =~ s/^\s+//g;
$long =~ s/\s+$//g; $long =~ s/\s+$//g;
$res->{description} = $long; $res->{description} = $long;
} elsif ($rec =~ s/^Version:\s*(.*\S)\s*\n//i) { } elsif ($rec =~ s/^Version:\s*(.*\S)\s*\n//i) {
my $version = $1; my $version = $1;
if ($version =~ m/^(\d[a-zA-Z0-9\.\+\-\:\~]*)-(\d+)$/) { if ($version =~ m/^(\d[a-zA-Z0-9\.\+\-\:\~]*)-(\d+)$/) {
$res->{version} = $version; $res->{version} = $version;
} else {
my $msg = "unable to parse appliance record: version = '$version'\n";
$update ? die $msg : warn $msg;
}
} elsif ($rec =~ s/^Type:\s*(.*\S)\s*\n//i) {
my $type = $1;
if ($type =~ m/^(openvz)$/) {
$res->{type} = $type;
} else {
my $msg = "unable to parse appliance record: unknown type '$type'\n";
$update ? die $msg : warn $msg;
}
} elsif ($rec =~ s/^([^:]+):\s*(.*\S)\s*\n//) {
$res->{lc $1} = $2;
} else { } else {
my $msg = "unable to parse appliance record: $rec\n"; my $msg = "unable to parse appliance record: version = '$version'\n";
$update ? die $msg : warn $msg; $update ? die $msg : warn $msg;
$res = {};
last;
} }
} } elsif ($rec =~ s/^Type:\s*(.*\S)\s*\n//i) {
my $type = $1;
if ($res->{'package'} eq 'pve-web-news' && $res->{description}) { if ($type =~ m/^(openvz|lxc)$/) {
$list->{'all'}->{$res->{'package'}} = $res; $res->{type} = $type;
next;
}
$res->{section} = 'unknown' if !$res->{section};
if ($res->{'package'} && $res->{type} && $res->{os} && $res->{version} &&
$res->{infopage}) {
my $template;
if ($res->{location}) {
$template = $res->{location};
$template =~ s|.*/([^/]+.tar.gz)|$1|;
} else { } else {
$template = "$res->{os}-$res->{package}_$res->{version}_i386.tar.gz"; my $msg = "unable to parse appliance record: unknown type '$type'\n";
$template =~ s/$res->{os}-$res->{os}-/$res->{os}-/; $update ? die $msg : warn $msg;
} }
$res->{source} = $source; } elsif ($rec =~ s/^([^:]+):\s*(.*\S)\s*\n//) {
$res->{template} = $template; $res->{lc $1} = $2;
$list->{$res->{section}}->{$template} = $res;
$list->{'all'}->{$template} = $res;
} else { } else {
my $msg = "found incomplete appliance records\n"; my $msg = "unable to parse appliance record: $rec\n";
$update ? die $msg : warn $msg; $update ? die $msg : warn $msg;
$res = {};
last;
} }
} }
};
if ($res->{'package'} eq 'pve-web-news' && $res->{description}) {
$list->{'all'}->{$res->{'package'}} = $res;
next;
}
$res->{section} = 'unknown' if !$res->{section};
if ($res->{'package'} && $res->{type} && $res->{os} && $res->{version} &&
$res->{infopage}) {
my $template;
if ($res->{location}) {
$template = $res->{location};
$template =~ s|.*/([^/]+.tar.gz)|$1|;
} else {
$template = "$res->{os}-$res->{package}_$res->{version}_i386.tar.gz";
$template =~ s/$res->{os}-$res->{os}-/$res->{os}-/;
}
$res->{source} = $source;
$res->{template} = $template;
$list->{$res->{section}}->{$template} = $res;
$list->{'all'}->{$template} = $res;
} else {
my $msg = "found incomplete appliance records\n";
$update ? die $msg : warn $msg;
}
}
}
sub read_aplinfo {
my ($filename, $list, $source, $update) = @_;
my $fh = IO::File->new("<$filename") ||
die "unable to open file '$filename' - $!\n";
eval { read_aplinfo_from_fh($fh, $list, $source, $update); };
my $err = $@; my $err = $@;
close($fh); close($fh);
......
...@@ -27,7 +27,7 @@ Package, Section, Version, Maintainer, Description ...@@ -27,7 +27,7 @@ Package, Section, Version, Maintainer, Description
Additionally we define the following fields: Additionally we define the following fields:
Type: openvz | qemu Type: openvz | qemu | lxc
OS: Operating system type OS: Operating system type
Location: download url Location: download url
Infopage: url to additional info Infopage: url to additional info
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment