make export_user much more robust
authorminima <minima>
Thu, 11 Jul 2002 16:47:36 +0000 (16:47 +0000)
committerminima <minima>
Thu, 11 Jul 2002 16:47:36 +0000 (16:47 +0000)
Changes
perl/DXUser.pm

diff --git a/Changes b/Changes
index bb156973f6dbd0e427c9af90935e7ea31ea0af1f..eb908dada05ab192fef5191e4a6ea607e4fa3ed3 100644 (file)
--- a/Changes
+++ b/Changes
@@ -3,6 +3,10 @@
 Digest::SHA1 and any dependant packages to run this release. HOWEVER tempted
 you are, please don't set/newprotocol on any nodes. It won't work.
 2. Make the cluster node registered on from startup (from Mark HB9DBM).
+3. Make the 'export_users' process *MUCH* more robust. It should now accept
+funny characters and not rely on an absolutely 'perfect' user file to work.
+Errors are displayed (and logged if done from the cluster) and then ignored.
+Invalid callsigns are removed. 
 09Jul02=======================================================================
 1. make the is_qra more accurate (from Mark HB9DBM).
 04Jul02=======================================================================
index 1e06cd3c9d87fa05a243e85ac14b2c896761171b..84a569497171c9a0cc1584333130e59e8cc321ed 100644 (file)
@@ -14,6 +14,7 @@ use Data::Dumper;
 use Fcntl;
 use IO::File;
 use DXDebug;
+use DXUtil;
 
 use strict;
 
@@ -325,10 +326,11 @@ sub export
         rename "$fn", "$fn.o" if -e "$fn";
 
        my $count = 0;
+       my $err = 0;
        my $fh = new IO::File ">$fn" or return "cannot open $fn ($!)";
        if ($fh) {
-               my $ref = 0;
                my $key = 0;
+               my $val = undef;
                my $action;
                my $t = scalar localtime;
                print $fh q{#!/usr/bin/perl
@@ -376,19 +378,46 @@ if (@ARGV) {
 
 DXUser->del_file($main::userfn);
 DXUser->init($main::userfn, 1);
-
-%u = (
-  };
-
-        for ($action = R_FIRST; !$dbm->seq($key, $ref, $action); $action = R_NEXT) {
-                       print $fh "'$key' => q{$ref},\n";
-                       ++$count;
+%u = ();
+my $count = 0;
+my $err = 0;
+while (<DATA>) {
+       chomp;
+       my @f = split /\t/;
+       my $ref = decode($f[1]);
+       if ($ref) {
+               $ref->put();
+               $count++;
+       } else {
+               print "# Error: $f[0]\t$f[1]\n";
+               $err++
+       }
+}
+DXUser->sync; DXUser->finish;
+print "There are $count user records and $err errors\n";
+};
+               print $fh "__DATA__\n";
+
+        for ($action = R_FIRST; !$dbm->seq($key, $val, $action); $action = R_NEXT) {
+                       if (!is_callsign($key) || $key =~ /^0/) {
+                               Log('DXCommand', "Export Error: $key\t$val");
+                               $dbm->del($key);
+                               ++$err;
+                               next;
+                       }
+                       my $ref = decode($val);
+                       if ($ref) {
+                               print $fh "$key\t" . $ref->encode . "\n";
+                               ++$count;
+                       } else {
+                               Log('DXCommand', "Export Error: $key\t$val");
+                               $dbm->del($key);
+                               ++$err;
+                       }
                } 
-        print $fh ");\n#\nprint \"there were $count records\\n\";\n#\n";
-        print $fh "DXUser->sync; DXUser->finish;\n#\n";
         $fh->close;
     } 
-       return $count;
+       return "$count Users $err Errors ('sh/log Export' for details)";
 }
 
 #