From 75987f0dbcbba4fc2bb5a378d14e2fbdb2e30e34 Mon Sep 17 00:00:00 2001 From: Dirk Koopman Date: Sat, 23 Oct 2010 23:39:19 +0100 Subject: [PATCH] added dbexport & dxqsl_import/export cmds --- Changes | 5 +++++ cmd/Commands_en.hlp | 54 ++++++++++++++++++++++++++++++++++++++++++++- cmd/dbexport.pl | 29 ++++++++++++++++++++++++ cmd/dbimport.pl | 5 ++--- cmd/dbshow.pl | 2 +- cmd/dxqsl_export.pl | 32 +++++++++++++++++++++++++++ cmd/dxqsl_import.pl | 42 +++++++++++++++++++++++++++++++++++ perl/Messages | 3 ++- perl/QSL.pm | 2 +- perl/Version.pm | 4 ++-- 10 files changed, 169 insertions(+), 9 deletions(-) create mode 100644 cmd/dbexport.pl create mode 100644 cmd/dxqsl_export.pl create mode 100644 cmd/dxqsl_import.pl diff --git a/Changes b/Changes index f7e858f3..8680fcb6 100644 --- 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======================================================================= diff --git a/cmd/Commands_en.hlp b/cmd/Commands_en.hlp index 8f798b80..5145d631 100644 --- a/cmd/Commands_en.hlp +++ b/cmd/Commands_en.hlp @@ -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 ^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 ^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 ^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 is compared against the available bands set up in the cluster. See SHOW/BANDS for more information. +=== 9^DXQSL_IMPORT ^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 ^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 ^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 index 00000000..27482e05 --- /dev/null +++ b/cmd/dbexport.pl @@ -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: ") 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)); + + + diff --git a/cmd/dbimport.pl b/cmd/dbimport.pl index 797805ea..a08e1693 100644 --- a/cmd/dbimport.pl +++ b/cmd/dbimport.pl @@ -22,8 +22,7 @@ my $count; open(IMP, $fn) or return (1, "Cannot open $fn $!"); while () { - chomp; - s/\r//g; + s/[\r\n]+$//g; if ($state == 0) { if (/^\&\&/) { $state = 0; @@ -50,5 +49,5 @@ while () { } close (IMP); -push @out, $self->msg('db10', $count, $db->name); +push @out, $self->msg('db10', $count, $fn, $db->name); return (1, @out); diff --git a/cmd/dbshow.pl b/cmd/dbshow.pl index 6290dd3a..e6e138c2 100644 --- a/cmd/dbshow.pl +++ b/cmd/dbshow.pl @@ -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 index 00000000..036edc79 --- /dev/null +++ b/cmd/dxqsl_export.pl @@ -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: ") 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 index 00000000..a5face5f --- /dev/null +++ b/cmd/dxqsl_import.pl @@ -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: ") 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')); diff --git a/perl/Messages b/perl/Messages index a68712c4..911f7c89 100644 --- a/perl/Messages +++ b/perl/Messages @@ -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]', diff --git a/perl/QSL.pm b/perl/QSL.pm index 9ed00f30..20d5c614 100644 --- a/perl/QSL.pm +++ b/perl/QSL.pm @@ -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; diff --git a/perl/Version.pm b/perl/Version.pm index 8e5e212d..19fd6b91 100644 --- a/perl/Version.pm +++ b/perl/Version.pm @@ -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; -- 2.34.1