From fd1dfe6db4a898d7e96a577c68599fc992238326 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 22 Jul 2009 15:40:56 +0100 Subject: [PATCH 1/1] WIP update processor, generating outgoing email --- pctb/commod-update-receiver | 47 +++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/pctb/commod-update-receiver b/pctb/commod-update-receiver index ff28fbb..2c409f4 100755 --- a/pctb/commod-update-receiver +++ b/pctb/commod-update-receiver @@ -32,7 +32,7 @@ # clientname "ypp-sc-tools" # clientversion 2.1-g2e06a26 [from git-describe --tags HEAD] # clientfixes "lastpage" [space separated list] -# deduped.tsv.gz output of ypp-commodities --tsv +# data filename=deduped.tsv.gz output of ypp-commodities --tsv use strict (qw(vars)); use POSIX; @@ -68,13 +68,15 @@ sub must_param ($$) { } my $clientname= must_param('clientname',$re_any); -my $client= $clients{$clientname}; +my $clientinfo= $clients{$clientname}; fail('unknown client') unless defined $client; -my $clientfixes= must_param('clientfixes', $re_any); -foreach my $bug (@$client) { +my $clientfixes= must_param('clientfixes', "^([-0-9a-z ]*)\$"); +my @clientfixes= sort grep { m/./ } split /\s+/, $clientfixes; +$clientfixes= "@clientfixes"; +foreach my $bug (@$clientinfo) { fail("client out of date - missing bugfix \`$bug'") - unless grep { $_ eq $bug } split /\s+/, $clientfixes; + unless grep { $_ eq $bug } @clientfixes; } my $cversion= must_param('clientversion', "^(\\d[-+._0-9a-zA-Z]+)\$"); @@ -94,6 +96,41 @@ foreach my $islands (values %$arches) { } fail("unknown island") unless $island_found; +die if $ocean =~ m/\=/; +die if $island =~ m/\=/; + +$datafile= must_param('data',"^(deduped\\.tsv\\.gz)\$"); +$indatafh= upload('data'); fail("data is not a file") unless defined $datafh; + +our %done; + +my $content= MIME::Entity->build(Type => 'multipart/mixed', + Boundary => '=', + Charset => 'utf-8'); + +my $clientspec= "$clientname $clientversion $clientfixes"; +foreach $vn (qw(ocean island + clientspec + clientname clientversion clientfixes)) { + +while (<$datafh>) { + !m/\P{IsPrint}/ or die bad_data('nonprinting char(s)'); + my @v= split /\t/; + @v==6 or bad_data('wrong number of fields'); + my ($commod,$stall) = @v; + defined $commods{$commod} or bad_data("unknown commodity \`$commod'"); + $stall =~ m/^\p{IsUpper}/ or bad_data("stall not capitalised"); + !exists $done{$commod,$stall} or bad_data("repeated data"); + $done{$commod,$stall}= 1; + foreach my $f (@v[2..5]) { + $f =~ m/^(0|[1-9][0-9]{0,5}|\>1000)$/ or bad_data("bad field"); + ($v % 1) or ($v !~ m/\>/) or bad_data("> in price"); + } +} + + + + #foreach my $commod (sort keys %commods) { # print "$commod\n"; #} -- 2.30.2