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 #=======================================================================
31 'database' => $Std{'database'},
34 'timezone' => $Std{'timezone'},
35 'type' => $Std{'type'},
43 $progname =~ s/^.*\/(.*?)$/$1/;
44 our $VERSION = "0.00";
46 Getopt
::Long
::Configure
("bundling");
49 "database|D=s" => \
$Opt{'database'},
50 "debug" => \
$Opt{'debug'},
51 "help|h" => \
$Opt{'help'},
52 "timezone|T=s" => \
$Opt{'timezone'},
53 "type|t=s" => \
$Opt{'type'},
54 "verbose|v+" => \
$Opt{'verbose'},
55 "version" => \
$Opt{'version'},
56 "waypoint|w" => \
$Opt{'waypoint'},
58 ) || die("$progname: Option error. Use -h for help.\n");
60 $Opt{'debug'} && ($Debug = 1);
61 $Opt{'help'} && usage
(0);
62 if ($Opt{'version'}) {
68 if (length($Opt{'timezone'})) {
69 if ($Opt{'timezone'} =~ /^[\+\-][0-2][0-9]{3}$/) {
70 $tz_str = $Opt{'timezone'};
71 } elsif ($Opt{'timezone'} =~ /^z$/i) {
72 $tz_str = $Opt{'timezone'};
73 } elsif ($Opt{'timezone'} =~ /^[a-z]+$/i) {
74 $tz_str = " $Opt{'timezone'}";
76 die("$progname: $Opt{'timezone'}: Invalid time zone\n");
80 for my $Currarg (@ARGV) {
81 for my $Currfile (glob($Currarg)) {
82 D
("Currfile = '$Currfile'");
83 if ($Opt{'type'} =~ /picture/) {
84 if ($Currfile =~ /\.jpg$/i) {
85 my $tz_str = length($Opt{'timezone'})
86 ?
"-T $Opt{'timezone'} "
89 "gpst-pic $tz_str$Currfile | psql -c \"COPY pictures (" .
98 ") FROM stdin\" $Opt{'database'}";
99 msg
(1, "Executing '$exec_str'...");
103 if ($Opt{'type'} =~ /track/) {
105 "gpst -o pgtab -R lat=6,lon=6 -d -rpt $Currfile | " .
106 "psql -a -c \"COPY logg (" .
115 ") FROM stdin\" $Opt{'database'}";
116 msg
(1, "Executing '$exec_str'...");
119 if ($Opt{'type'} =~ /waypoint/) {
121 "gpst -o pgwtab $Currfile | " .
122 "psql -a -c \"COPY wayp_new (" .
134 ") FROM stdin\" $Opt{'database'}";
135 msg
(1, "Executing '$exec_str'...");
142 # Print program version {{{
143 print("$progname v$VERSION\n");
148 # Send the help message to stdout {{{
151 if ($Opt{'verbose'}) {
157 Usage: $progname [options] [file [files [...]]]
162 Load into PostgreSQL database X. Default: "$Std{'database'}".
166 Prepend X as timezone to the date. Valid formats:
168 A '+' or '-' followed by a four-digit number (HHMM) which
169 indicates the offset relative to UTC. Examples:
173 Time zone abbreviation. Examples:
178 Comma-separated list of point types to extract from files:
182 Default: "$Std{'type'}".
184 Increase level of verbosity. Can be repeated.
186 Print version information.
188 Print debugging messages.
196 # Print a status message to stderr based on verbosity level {{{
197 my ($verbose_level, $Txt) = @_;
199 if ($Opt{'verbose'} >= $verbose_level) {
200 print(STDERR
"$progname: $Txt\n");
206 # Print a debugging message {{{
208 my @call_info = caller;
209 chomp(my $Txt = shift);
210 my $File = $call_info[1];
212 $File =~ s
#^.*/(.*?)$#$1#;
213 print(STDERR
"$File:$call_info[2] $$ $Txt\n");
220 # Plain Old Documentation (POD) {{{
230 [options] [file [files [...]]]
240 =item B<-h>, B<--help>
242 Print a brief help summary.
244 =item B<-v>, B<--verbose>
246 Increase level of verbosity. Can be repeated.
250 Print version information.
254 Print debugging messages.
264 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
268 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
269 This is free software; see the file F<COPYING> for legalese stuff.
273 This program is free software: you can redistribute it and/or modify it
274 under the terms of the GNU General Public License as published by the
275 Free Software Foundation, either version 3 of the License, or (at your
276 option) any later version.
278 This program is distributed in the hope that it will be useful, but
279 WITHOUT ANY WARRANTY; without even the implied warranty of
280 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
281 See the GNU General Public License for more details.
283 You should have received a copy of the GNU General Public License along
285 If not, see L<http://www.gnu.org/licenses/>.
293 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :