X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXUtil.pm;h=b58a4528d5649bc60df8dbcd23e892e58bde30b5;hb=c94ff1bf2cbe16ed59c5b273c7f6730fd7314cab;hp=4e442140b82e9394422492bc639f5d3fd6ed8903;hpb=68fa2f8ae34d78464cb196851a7ce09ebef61b1b;p=spider.git diff --git a/perl/DXUtil.pm b/perl/DXUtil.pm index 4e442140..b58a4528 100644 --- a/perl/DXUtil.pm +++ b/perl/DXUtil.pm @@ -8,11 +8,13 @@ package DXUtil; + use Date::Parse; use IO::File; use File::Copy; use Data::Dumper; + use strict; use vars qw(@month %patmap $pi $d2r $r2d @ISA @EXPORT); @@ -24,7 +26,7 @@ require Exporter; filecopy ptimelist print_all_fields cltounix unpad is_callsign is_long_callsign is_latlong is_qra is_freq is_digits is_pctext is_pcflag insertitem deleteitem - is_prefix dd is_ipaddr $pi $d2r $r2d + is_prefix dd is_ipaddr $pi $d2r $r2d localdata localdata_mv ); @@ -472,3 +474,33 @@ sub deleteitem return $n - @$list; } +# find the correct local_data directory +# basically, if there is a local_data directory with this filename and it is younger than the +# equivalent one in the (system) data directory then return that name rather than the system one +sub localdata +{ + my $ifn = shift; + my $ofn = "$main::data/$ifn"; + my $tfn; + + if (-e "$main::local_data") { + $tfn = "main::local_data/$ifn"; + if (-e $tfn && -M $tfn < -M $ofn) { + $ofn = $tfn; + } + } + + return $ofn; +} + +# move a file or a directory from data -> local_data if isn't there already +sub localdata_mv +{ + my $ifn = shift; + if (-e "$main::data/$ifn" ) { + unless (-e "$main::local_data/$ifn") { + move("$main::data/$ifn", "$main::local_data/$ifn") or die "localdata_mv: cannot move $ifn from '$main::data' -> '$main::local_data' $!\n"; + } + } +} +