added dbexport & dxqsl_import/export cmds
authorDirk Koopman <djk@tobit.co.uk>
Sat, 23 Oct 2010 22:39:19 +0000 (23:39 +0100)
committerDirk Koopman <djk@tobit.co.uk>
Sat, 23 Oct 2010 22:39:19 +0000 (23:39 +0100)
Changes
cmd/Commands_en.hlp
cmd/dbexport.pl [new file with mode: 0644]
cmd/dbimport.pl
cmd/dbshow.pl
cmd/dxqsl_export.pl [new file with mode: 0644]
cmd/dxqsl_import.pl [new file with mode: 0644]
perl/Messages
perl/QSL.pm
perl/Version.pm

diff --git a/Changes b/Changes
index f7e858f3a56a4965b44df6b8aa67197637f7e0c0..8680fcb658562f8114357be41b7ac49d915aebd9 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,8 @@
+23Oct10=======================================================================
+1. add dbexport command to allow the export of ak1a style databases to a
+file.
+2. add dxqsl_import and dxqsl_export commands to allow the import and export
+of sh/dxsql qsl manager data extracted from spots as they pass through.
 04Oct10=======================================================================
 1. add CTY-2007 prefix list
 04Oct10=======================================================================
index 8f798b80bc860e0f7ac581fc48524ec01a3c0afd..5145d631439bfe3d3c00d85dd434ef57d3d51ea1 100644 (file)
@@ -500,8 +500,23 @@ You also use one of these databases in a chain. This may be useful
 locally. 
 
 See DBIMPORT for the importing of existing AK1A format data to databases.
+See DXEXPORT for how to export an AK1A data in a form able to be imported.
 See DBSHOW for generic database enquiry
+
+
+=== 9^DBEXPORT <dbname> <filename>^Export an AK1A data to a file
+Sometimes one needs to export the data from an existing database file,
+maybe for a backup or to send to another node.
+
+  DBEXPORT oblast /tmp/OBLAST.FUL
+
+will export the OBLAST database to /tmp/OBLAST.FUL
+
+There is no protection, it is up to you not to overwrite a file that
+is important to you.
+
+See DBIMPORT for the importing of existing AK1A format data to databases.
+
 === 9^DBIMPORT <dbname> <filename>^Import AK1A data into a database
 If you want to import or update data in bulk to a database you can use
 this command. It will either create or update entries into an existing
@@ -512,6 +527,8 @@ database. For example:-
 will import the standard OBLAST database that comes with AK1A into the
 oblast database held locally.
 
+See DBEXPORT for how to export an AK1A database
+
 === 9^DBREMOVE <dbname>^Delete a database
 DBREMOVE will completely remove a database entry and also delete any data
 file that is associated with it. 
@@ -618,6 +635,41 @@ You can credit someone else by saying:-
 The <freq> is compared against the available bands set up in the 
 cluster.  See SHOW/BANDS for more information.
 
+=== 9^DXQSL_IMPORT <filename>^Import SH/DXSQL information from a file
+The SHOW/DXQSL command shows any QSL managers that have been extracted
+from comments on a DX spot.
+
+Use this command to export the current state of the information to
+a CSV style text file. For example:
+
+   DXQSL_EXPORT /tmp/qsl.csv
+
+NOTE: this command will overwrite any file that you have write
+permission for.
+
+See also DXQSL_IMPORT to import one of these files.
+
+=== 9^DXQSL_IMPORT <filename>^Import SH/DXSQL information from a file
+The SHOW/DXQSL command shows any QSL managers that have been extracted
+from comments on a DX spot.
+
+Use this command to restore a file created by the DXSQL_EXPORT command.
+For example:
+
+   DXQSL_IMPORT /tmp/qsl.csv
+
+The data in this file will UPDATE any information that may already be
+present. This may not be what you want. To make the data the same as
+the import file then you must:
+
+* stop the node
+* remove /spider/data/qsl.v1
+* restart the node
+* login as sysop
+* do the import
+
+Preferably before too many DX spots with qsl manager info come in.
+
 === 0^ECHO <line>^Echo the line to the output
 This command is useful in scripts and so forth for printing the
 line that you give to the command to the output. You can use this
diff --git a/cmd/dbexport.pl b/cmd/dbexport.pl
new file mode 100644 (file)
index 0000000..27482e0
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/perl
+#
+# Database export routine
+#
+# Copyright (c) 2010 Dirk Koopman G1TLH
+#
+my ($self, $line) = @_;
+my ($name, $fn) = split /\s+/, $line;
+return (1, $self->msg('e5')) if $self->priv < 9;
+return (1, "dbexport: <database name> <pathname to export to>") unless $name && $fn;
+
+my @out;
+
+my $db = DXDb::getdesc($name);
+return (1, $self->msg('db3', $name)) unless $db;
+return (1, $self->msg('db1', $db->remote )) if $db->remote;
+my $of = IO::File->new(">$fn") or return(1, $self->msg('e30', $fn));
+
+$db->open;                                             # make sure we are open
+my ($r, $k, $v, $flg, $count);
+for ($flg = R_FIRST; !$db->{db}->seq($k, $v, $flg); $flg = R_NEXT) {
+       $of->print("$k\n$v\&\&\n");
+       ++$count;
+}
+$of->close;
+return(0, $self->msg("db13", $count, $name, $fn));
+
+
+
index 797805eaee2d7513246b81d88b303ad4430c94a0..a08e169346c83a55cd92b92bc55e52f0b6772828 100644 (file)
@@ -22,8 +22,7 @@ my $count;
 
 open(IMP, $fn) or return (1, "Cannot open $fn $!");
 while (<IMP>) {
-       chomp;
-       s/\r//g;
+       s/[\r\n]+$//g;
        if ($state == 0) {
                if (/^\&\&/) {
                        $state = 0;
@@ -50,5 +49,5 @@ while (<IMP>) {
 }
 close (IMP);
 
-push @out, $self->msg('db10', $count, $db->name);
+push @out, $self->msg('db10', $count, $fn, $db->name);
 return (1, @out);
index 6290dd3a5abc3c1d52aa2447eedff3edcef66171..e6e138c2b414ab75f05e3443a9976091b26f30ff 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 #
-# Database update routine
+# Database enquiry routine
 #
 # Copyright (c) 1999 Dirk Koopman G1TLH
 #
diff --git a/cmd/dxqsl_export.pl b/cmd/dxqsl_export.pl
new file mode 100644 (file)
index 0000000..036edc7
--- /dev/null
@@ -0,0 +1,32 @@
+#
+# Export QSL information from the local database
+#
+# Copyright (c) 2010 Dirk Koopman G1TLH
+#
+
+my ($self, $line) = @_;
+my ($fn) = $line;
+return (1, $self->msg('e5')) if $self->priv < 9;
+return (1, "export_dxqsl: <pathname to export to>") unless $fn;
+
+#$DB::single=1;
+
+return (1, $self->msg('db3', 'QSL')) unless $QSL::dbm;
+
+my $of = IO::File->new(">$fn") or return(1, $self->msg('e30', $fn));
+$of->print(q{"call","manager","spots","unix timet","last spotter"}."\n");
+
+my ($r, $k, $v, $flg, $count, $q);
+for ($flg = R_FIRST; !$QSL::dbm->seq($k, $v, $flg); $flg = R_NEXT) {
+       next unless $k;
+
+       $q = QSL::get($k);
+       if ($q) {
+               for (@{$q->[1]}) {
+                       $of->print(join(',', $k, $_->[0], $_->[1], $_->[2], $_->[3]). "\n");
+                       ++$count;
+               }
+       }
+}
+$of->close;
+return(0, $self->msg("db13", $count, 'dxqsl', $fn));
diff --git a/cmd/dxqsl_import.pl b/cmd/dxqsl_import.pl
new file mode 100644 (file)
index 0000000..a5face5
--- /dev/null
@@ -0,0 +1,42 @@
+#
+# Import QSL information to the local database
+#
+# Copyright (c) 2010 Dirk Koopman G1TLH
+#
+
+my ($self, $line) = @_;
+my ($fn) = $line;
+return (1, $self->msg('e5')) if $self->priv < 9;
+return (1, "import_dxqsl: <pathname to import from>") unless $fn;
+
+#$DB::single=1;
+
+return (1, $self->msg('db3', 'QSL')) unless $QSL::dbm;
+
+my $if = IO::File->new("$fn") or return(1, $self->msg('e30', $fn));
+my $count;
+while (<$if>) {
+       next if /^\s+"/;
+       chomp;
+       my ($call, $manager, $c, $t, $by) = split /\s*,\s*/;
+       if ($call && $by) {
+               my $q = QSL::get($call) || QSL->new($call);
+               my ($r) = grep {$_->[0] eq $manager} @{$q->[1]};
+               if ($r) {
+                       $r->[1] += $c;
+                       if ($t > $r->[2]) {
+                               $r->[2] = $t;
+                               $r->[3] = $by;
+                       }
+               } else {
+                       $r = [$manager, $by, $t, $by];
+                       unshift @{$q->[1]}, $r;
+               }
+               $q->put;
+               ++$count;
+       }
+}
+
+$if->close;
+
+return(0, $self->msg("db10", $count, $fn, 'dxqsl'));
index a68712c4b1a1c67317a8ac9dc23b781dc3678008..911f7c89f61d4b49f3d82b455ecd9e9191a717cb 100644 (file)
@@ -52,9 +52,10 @@ package DXM;
                                db7 => 'Database $_[0] created for remote node $_[1]',
                                db8 => 'Database $_[0] created locally',
                                db9 => 'Database $_[0] removed',
-                               db10 => '$_[0] records imported into $_[1]',
+                               db10 => '$_[0] records imported from $_[1] to $_[2]',
                                db11 => 'Sending your request(s) to $_[0], please stand by...',
                                db12 => 'DB Name          Location   Cmd             Chain',
+                               db13 => '$_[0] records exported from $_[1] to $_[2]',
                                dfreq1 => 'Invalid freq $_[0] need: eg 0/30000 or hf or hf/cw', 
                                dir1 => 'No messages found',
                                disc1 => 'Disconnected by $_[0]',
index 9ed00f30d1c37ec2049d89d63d662db1fac7dffa..20d5c6143f139e656ab3a4c325fa7a1872fa78da 100644 (file)
@@ -56,7 +56,7 @@ sub new
        return bless [uc $call, []], $pkg;
 }
 
-# the format of each entry is [manager, times found, last time]
+# the format of each entry is [manager, times found, last time, last reporter]
 sub update
 {
        return unless $dbm;
index 8e5e212d7022dfe760383a794959a365c6613512..19fd6b91c44a54b1d696f739f7f5e72cc62144bb 100644 (file)
@@ -11,7 +11,7 @@ use vars qw($version $subversion $build $gitversion);
 
 $version = '1.55';
 $subversion = '0';
-$build = '74';
-$gitversion = '2a187a4';
+$build = '75';
+$gitversion = '059fb24';
 
 1;