chiark / gitweb /
Merge branch 'master' of ijackson@chiark.greenend.org.uk:things/ypp-sc-tools.pctb...
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 8 Aug 2009 14:16:11 +0000 (15:16 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 8 Aug 2009 14:16:11 +0000 (15:16 +0100)
yarrg/Commods.pm
yarrg/commod-results-processor
yarrg/convert.c

index b670f58..5003037 100644 (file)
@@ -23,6 +23,7 @@
 package Commods;
 use IO::File;
 use HTTP::Request::Common ();
+use POSIX;
 
 use strict;
 use warnings;
@@ -32,7 +33,7 @@ BEGIN {
     our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
     $VERSION     = 1.00;
     @ISA         = qw(Exporter);
-    @EXPORT      = qw(&parse_info_clientside
+    @EXPORT      = qw(&parse_info_clientside &fetch_with_rsync
                      &parse_info_serverside &parse_info_serverside_ocean
                      %oceans %commods %clients %routes %route_mysteries
                      &parse_pctb_commodmap %pctb_commodmap @pctb_commodmap
@@ -144,7 +145,12 @@ sub parse_info_clientside () {
     return unless $yarrg;
     my $master= fetch_with_rsync('info');
     parse_info1($master,'s');
-    parse_info1('_local-info.txt','s');
+    my $local= '_local-info.txt';
+    if (stat $local) {
+       parse_info1($local,'s');
+    } else {
+       die "$local $!" unless $! == &ENOENT;
+    }
 }
 
 sub fetch_with_rsync ($) {
@@ -160,6 +166,7 @@ sub fetch_with_rsync ($) {
        $!=0; system 'rsync','-Lt','--',$remote,$local;
        die "$? $!" if $! or $?;
     }
+    return $local;
 }
 
 sub parse_info_maproutes ($$$) {
@@ -256,7 +263,8 @@ sub yarrgpostform ($$) {
     my ($ua, $form) = @_;
     my $dest= $ENV{'YPPSC_YARRG_YARRG'};
     get_our_version($form, 'client');
-    return cgipostform($ua, "$dest/commod-update-receiver", $form);
+    die unless $dest =~ m,/$,;
+    return cgipostform($ua, "${dest}commod-update-receiver", $form);
 }    
 
 sub cgipostform ($$$) {
@@ -290,7 +298,7 @@ sub cgipostform ($$$) {
        $out =~ m,^Content-Type: text/plain.*\n\n, or die "$out ?";
        return $';
     } else {
-       my $resp= $ua->request($url,$req);
+       my $resp= $ua->request($req);
        die $resp->status_line unless $resp->is_success;
        return $resp->content();
     }
index e53bbb5..f9fdedf 100755 (executable)
@@ -135,10 +135,12 @@ sub main__arbitrage () {
            sub arb_subtract_qty (\@) {
                my ($verbs) = @_;
                my $verb= shift @$verbs;
+               my $vqty= $verb->{Qty};
+               $vqty =~ s/^\>//;
                unshift @$verbs, {
                     Stall => $verb->{Stall},
                     Price => $verb->{Price},
-                    Qty => $verb->{Qty} - $qty
+                    Qty => $vqty - $qty
                };
            }
            arb_subtract_qty(@buys);
index 49fc3ed..adccb1c 100644 (file)
@@ -117,9 +117,9 @@ static void run_analysis(void) {
     }
 
     waitpid_check_exitstatus(processor, "output processor/uploader", 0);
-    fclose(tf);
   }
   
+  fclose(tf);
   progress_log("all complete.");
 }
 
@@ -336,8 +336,8 @@ int main(int argc, char **argv) {
             o_serv_pctb,        o_flags & ff_use_pctb);
             
   set_server("YPPSC_YARRG_DICT_UPDATE",
-            "rsync://",         "rsync.yarrg.chiark.net/pctb",
-                                "rsync.yarrg.chiark.net/pctb/test",
+            "rsync://",         "rsync.yarrg.chiark.net/yarrg",
+                                "rsync.yarrg.chiark.net/yarrg/test",
             o_serv_dict_fetch,   o_flags & ff_dict_fetch);
 
   set_server("YPPSC_YARRG_DICT_SUBMIT",