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