Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 320 lines (253 sloc) 7.721 kB
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
1 #!/usr/bin/perl
2 ##!~_~perlpath~_~
3 #
2a14b06 testing
Eric Zarko authored
4 # Interchange database updater
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
5 #
9deb526 @racke updated LINUXIA branch to 4.9 sources in order to use it as testbed a…
racke authored
6 # $Id: update.PL,v 1.7.4.1 2003-01-25 22:21:32 racke Exp $
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
7 #
9deb526 @racke updated LINUXIA branch to 4.9 sources in order to use it as testbed a…
racke authored
8 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
2a14b06 testing
Eric Zarko authored
9 #
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public
21 # License along with this program; if not, write to the Free
22 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 # MA 02111-1307 USA.
24
a30978f s:/usr/local/minivend:/usr/local/interchange:g;
Eric Zarko authored
25 use lib '/usr/local/interchange/lib';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
26 #use lib '~_~INSTALLPRIVLIB~_~';
a30978f s:/usr/local/minivend:/usr/local/interchange:g;
Eric Zarko authored
27 use lib '/usr/local/interchange';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
28 #use lib '~_~INSTALLARCHLIB~_~';
29
2a14b06 testing
Eric Zarko authored
30 use strict;
31 use Fcntl;
32 use Vend::Config;
33 use Vend::Data;
34 use Vend::Util;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
35
2a14b06 testing
Eric Zarko authored
36 BEGIN {
37 eval {
38 require 5.004;
39 require FindBin;
40 1 and $Global::VendRoot = "$FindBin::RealBin";
41 1 and $Global::VendRoot =~ s/.bin$//;
42 };
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
43 ($Global::VendRoot = $ENV{MINIVEND_ROOT})
44 if defined $ENV{MINIVEND_ROOT};
a30978f s:/usr/local/minivend:/usr/local/interchange:g;
Eric Zarko authored
45 $Global::VendRoot = $Global::VendRoot || '/usr/local/interchange';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
46 # $Global::VendRoot = $Global::VendRoot || '~_~INSTALLARCHLIB~_~';
a71f111 @perusionmike Updated to find either interchange.cfg or minivend.cfg
perusionmike authored
47
48 if(-f "$Global::VendRoot/interchange.cfg") {
49 $Global::ExeName = 'interchange';
50 $Global::ConfigFile = 'interchange.cfg';
51 }
52 elsif(-f "$Global::VendRoot/minivend.cfg") {
53 $Global::ExeName = 'minivend';
54 $Global::ConfigFile = 'minivend.cfg';
55 }
56 elsif(-f "$Global::VendRoot/interchange.cfg.dist") {
57 $Global::ExeName = 'interchange';
58 $Global::ConfigFile = 'interchange.cfg';
59 }
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
60 }
2a14b06 testing
Eric Zarko authored
61
62 ### END CONFIGURATION VARIABLES
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
63
64 sub dontwarn { $FindBin::RealBin; }
65
66 $Global::ErrorFile = "$Global::VendRoot/error.log";
67 $Vend::ExternalProgram = 1;
68
69 my $DEBUG = 0;
70
71 #select a DBM
72
73 BEGIN {
74 $Global::GDBM = $Global::DB_File = 0;
75 AUTO: {
76 last AUTO if
77 (defined $ENV{MINIVEND_DBFILE} and $Global::DB_File = 1);
78 last AUTO if
79 (defined $ENV{MINIVEND_NODBM});
80 eval {require GDBM_File and $Global::GDBM = 1};
81 eval {require DB_File and $Global::DB_File = 1};
82 }
83 if($Global::GDBM) {
84 require Vend::Table::GDBM;
85 import GDBM_File;
86 $Global::GDBM = 1;
87 $Global::Default_database = 'GDBM';
88 }
89 if($Global::DB_File) {
90 require Vend::Table::DB_File;
91 import DB_File;
92 $Global::DB_File = 1;
93 $Global::Default_database = 'DB_FILE'
94 unless defined $Global::Default_database;
95 }
96 if(! $Global::GDBM and ! $Global::DB_File) {
97 die "No DBM defined! Update not designed to work with DBI or memory databases.\n";
98 }
99 }
100
101 $Vend::Cfg = {};
102
103 my $Name = 'products';
104 my $Directory;
105
106 my $USAGE = <<EOF;
107 usage: update -c catalog [-n name] \\
108 -f field [-f field1 -f field2 ...] -k key value [value1 value2 ...]
109 or
110
111 usage: update -c catalog -i inputfile [-n name]
112
113 Options:
114
a71f111 @perusionmike Updated to find either interchange.cfg or minivend.cfg
perusionmike authored
115 -c catalog Catalog name as defined in interchange.cfg.
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
116 -f field Field name(s) in database. If multiple fields are specified,
117 multiple corresponding values must be supplied. Use '' to
118 set to the empty string.
119 -i file Input file to add entries to an existing database. (Must
120 be in same format/order as existing database.)
121 -k key Key (item code) to be updated.
122 -n name Database name as defined in catalog.cfg (default products).
123
124 If specifying a subcatalog database, make sure it is defined in the
125 subcatalog definition. If it is in the base catalog, use that catalog
126 as the parameter for the -c directive.
127 EOF
128
129 my ($Inputfile, $Key, @Fields, @Values);
130 my ($Catalog,$delimiter,$db);
131
132 GETOPT: {
133
134 if($ARGV[0] eq '-c') {
135 shift(@ARGV);
136 $Catalog = shift(@ARGV);
137 redo GETOPT;
138 }
139 elsif($ARGV[0] eq '-d') {
140 shift(@ARGV);
141 $Directory = shift(@ARGV);
142 redo GETOPT;
143 }
144 elsif($ARGV[0] eq '-n') {
145 shift(@ARGV);
146 $Name = shift(@ARGV);
147 redo GETOPT;
148 }
149 elsif($ARGV[0] eq '-k') {
150 shift(@ARGV);
151 $Key = shift(@ARGV);
152 redo GETOPT;
153 }
154 elsif($ARGV[0] eq '-i') {
155 shift(@ARGV);
156 $Inputfile = shift(@ARGV);
157 redo GETOPT;
158 }
159 elsif($ARGV[0] eq '-f') {
160 shift(@ARGV);
161 push(@Fields, shift @ARGV);
162 redo GETOPT;
163 }
164
165 } # END GETOPT
166
167 die $USAGE unless defined $Catalog;
168
169 push @Values, @ARGV;
170
171 if(@Fields and ! @Values) {
172 die $USAGE . "\n";
173 }
174 elsif (scalar(@Fields) != scalar(@Values) ) {
175 die "Number of fields and number of values don't match.\n" . $USAGE . "\n";
176 }
177 elsif ((@Fields or @Values) and defined $Inputfile) {
178 die "No field or value arguments accepted when inputting from a file.\n" .
179 $USAGE . "\n";
180 }
181 elsif (@Fields and ! $Key) {
182 die $USAGE . "\n";
183 }
184 elsif (!defined $Inputfile and ! @Fields and !@Values) {
185 die $USAGE . "\n";
186 }
187
188 my($name,$dir,$param,$subcat,$subconfig);
189 chdir $Global::VendRoot;
56f620a @perusionmike Multiple security fixes, tightening up opens with explicit "< $filena…
perusionmike authored
190 open(GLOBAL, "< $Global::ConfigFile") or
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
191 die "No global configuration file? Aborting.\n";
192 while(<GLOBAL>) {
193 next unless /^\s*(sub)?catalog\s+$Catalog\s+/i;
194 $subcat = $1 || '';
195 chomp;
196 s/^\s+//;
197 unless($subcat) {
198 (undef,$name,$dir,$param) = split /\s+/, $_, 4;
199 }
200 else {
201 (undef,$name,$subconfig,$dir,$param) = split /\s+/, $_, 5;
202 }
203 last;
204
205 }
206 close GLOBAL;
207
208 global_config();
209
210 chdir $dir or die "Couldn't change directory to $dir: $!\n";
211
9deb526 @racke updated LINUXIA branch to 4.9 sources in order to use it as testbed a…
racke authored
212 $Vend::ExternalProgram = $Vend::Quiet = 1;
213
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
214 $Vend::Cfg = config($name, $dir, "$dir/etc", ($subconfig || undef));
215 $::Variable = $Vend::Cfg->{Variable};
216
217 die "Problems with config.\n" unless defined $Vend::Cfg;
218
219 $Vend::Cfg->{ProductDir} = $Directory
220 if defined $Directory;
221
222 die "Bad data directory $Vend::Cfg->{ProductDir} -- doesn't exist.\n$USAGE\n"
223 unless -d $Vend::Cfg->{ProductDir};
224
225 open_database(1);
226
227 $Vend::WriteDatabase{$Name} = 1;
228
229 die "Bad database $Name -- doesn't exist.\n\n$USAGE\n"
230 unless $db = database_exists_ref($Name);
231
232 my $ref;
233 eval {
234 $ref = $db->ref();
235 };
236
237 die "Bad open of database $Name from catalog $Catalog ($!): $@\n"
238 unless $ref and ! $@;
239
240 unless($ref->record_exists($Key)) {
241 die "Key $Key not found in database $Name.\n";
242 }
243
244 my ($key,$field,@fields);
245
246 my $key_col = $Vend::Table::Common::KEY_IDX;
247
248 if (! defined $Inputfile ) {
249 foreach $field (@Fields) {
250 unless ( defined $ref->test_column($field) ) {
251 die "$field is not a column in the database.\n";
252 }
253 my $val = shift @Values;
254 print "setting ${Name}::${field}::$Key=$val\n";
255 $ref->set_field($Key, $field, $val);
256 }
257 }
258 else {
56f620a @perusionmike Multiple security fixes, tightening up opens with explicit "< $filena…
perusionmike authored
259 open (INPUT, "< $Inputfile") or die "Couldn't open input file $Inputfile: $!\n";
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
260 while(<INPUT>) {
261 chomp;
262 s/[\r\cZ]+//;
263 (@fields) = split /\t/, $_;
264 $key = $fields[$key_col];
265 $ref->set_row($key, @fields);
266 }
267 close INPUT;
268 }
269
270 close_database();
271
272 =head1 NAME
273
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
274 update -- command line setting of Interchange databases
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
275
276 =head1 VERSION
277
278 1.0
279
280 =head1 SYNOPSIS
281
282 update -c catalog [-f field -k key [-t table] value]
283
284 =head1 DESCRIPTION
285
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
286 Interchange's C<update> is a rudimentary method of directly setting the
287 DBM files (not the ASCII files) of a Interchange DBM database.
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
288
289 NOTE: This command DOES NOT APPLY TO SQL databases. They have their own
290 command line monitors that are more flexible.
291
292 =head1 OPTIONS
293
294 =over 4
295
296 =item -c name
297
298 Sets the catalog for which C<update> operates. It reads the
299 catalog.cfg file to retrieve database settings.
300
301 =item -f field
302
303 The name of the field to set.
304
305 =item -n name
306
307 The name of the table to set. If the table is not a DBM database the
308 C<update> program will terminate with an error.
309
310 =back
311
312 =head1 SEE ALSO
313
9deb526 @racke updated LINUXIA branch to 4.9 sources in order to use it as testbed a…
racke authored
314 http://interchange.redhat.com/
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
315
316 =head1 AUTHOR
317
9deb526 @racke updated LINUXIA branch to 4.9 sources in order to use it as testbed a…
racke authored
318 Mike Heins, <mheins@redhat.com>
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
319
Something went wrong with that request. Please try again.