3 #=======================================================================
5 # File ID: d9355770-f923-11dd-b366-0001805bf4b1
6 # Add new waypoints or trackpoints to the database.
9 # ©opyleft 2008– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 3 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
32 'database' => $Std{'database'},
35 'timezone' => $Std{'timezone'},
36 'type' => $Std{'type'},
44 $progname =~ s/^.*\/(.*?)$/$1/;
45 our $VERSION = "0.00";
47 Getopt
::Long
::Configure
("bundling");
50 "database|D=s" => \
$Opt{'database'},
51 "debug" => \
$Opt{'debug'},
52 "help|h" => \
$Opt{'help'},
53 "timezone|T=s" => \
$Opt{'timezone'},
54 "type|t=s" => \
$Opt{'type'},
55 "verbose|v+" => \
$Opt{'verbose'},
56 "version" => \
$Opt{'version'},
57 "waypoint|w" => \
$Opt{'waypoint'},
59 ) || die("$progname: Option error. Use -h for help.\n");
61 $Opt{'debug'} && ($Debug = 1);
62 $Opt{'help'} && usage
(0);
63 if ($Opt{'version'}) {
69 if (length($Opt{'timezone'})) {
70 if ($Opt{'timezone'} =~ /^[\+\-][0-2][0-9]{3}$/) {
71 $tz_str = $Opt{'timezone'};
72 } elsif ($Opt{'timezone'} =~ /^z$/i) {
73 $tz_str = $Opt{'timezone'};
74 } elsif ($Opt{'timezone'} =~ /^[a-z]+$/i) {
75 $tz_str = " $Opt{'timezone'}";
77 die("$progname: $Opt{'timezone'}: Invalid time zone\n");
81 for my $Currarg (@ARGV) {
82 for my $Currfile (glob($Currarg)) {
83 D
("Currfile = '$Currfile'");
84 if ($Opt{'type'} =~ /picture/) {
85 if ($Currfile =~ /\.jpg$/i) {
86 my $tz_str = length($Opt{'timezone'})
87 ?
"-T $Opt{'timezone'} "
90 "gpst-pic $tz_str$Currfile | psql -c \"COPY pictures (" .
99 ") FROM stdin\" $Opt{'database'}";
100 msg
(1, "Executing '$exec_str'...");
104 if ($Opt{'type'} =~ /track/) {
106 "gpst -o pgtab -R lat=6,lon=6 -d -rpt $Currfile | " .
107 "psql -a -c \"COPY logg (" .
116 ") FROM stdin\" $Opt{'database'}";
117 msg
(1, "Executing '$exec_str'...");
120 if ($Opt{'type'} =~ /waypoint/) {
122 "gpst -o pgwtab $Currfile | " .
123 "psql -a -c \"COPY wayp_new (" .
135 ") FROM stdin\" $Opt{'database'}";
136 msg
(1, "Executing '$exec_str'...");
143 # Print program version {{{
144 print("$progname v$VERSION\n");
149 # Send the help message to stdout {{{
152 if ($Opt{'verbose'}) {
158 Usage: $progname [options] [file [files [...]]]
163 Load into PostgreSQL database X. Default: "$Std{'database'}".
167 Prepend X as timezone to the date. Valid formats:
169 A '+' or '-' followed by a four-digit number (HHMM) which
170 indicates the offset relative to UTC. Examples:
174 Time zone abbreviation. Examples:
179 Comma-separated list of point types to extract from files:
183 Default: "$Std{'type'}".
185 Increase level of verbosity. Can be repeated.
187 Print version information.
189 Print debugging messages.
197 # Print a status message to stderr based on verbosity level {{{
198 my ($verbose_level, $Txt) = @_;
200 if ($Opt{'verbose'} >= $verbose_level) {
201 print(STDERR
"$progname: $Txt\n");
207 # Print a debugging message {{{
209 my @call_info = caller;
210 chomp(my $Txt = shift);
211 my $File = $call_info[1];
213 $File =~ s
#^.*/(.*?)$#$1#;
214 print(STDERR
"$File:$call_info[2] $$ $Txt\n");
221 # Plain Old Documentation (POD) {{{
231 [options] [file [files [...]]]
241 =item B<-h>, B<--help>
243 Print a brief help summary.
245 =item B<-v>, B<--verbose>
247 Increase level of verbosity. Can be repeated.
251 Print version information.
255 Print debugging messages.
265 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
269 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
270 This is free software; see the file F<COPYING> for legalese stuff.
274 This program is free software: you can redistribute it and/or modify it
275 under the terms of the GNU General Public License as published by the
276 Free Software Foundation, either version 3 of the License, or (at your
277 option) any later version.
279 This program is distributed in the hope that it will be useful, but
280 WITHOUT ANY WARRANTY; without even the implied warranty of
281 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
282 See the GNU General Public License for more details.
284 You should have received a copy of the GNU General Public License along
286 If not, see L<http://www.gnu.org/licenses/>.
294 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :