Skip to content
This repository
tag: REL_4_8_7
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 376 lines (300 sloc) 8.834 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
my $base = $ARGV[0] || '/work/interchange';
$self = {
INSTALLARCHLIB => $base,
INSTALLBIN => "$base/bin",
INSTALLDIRS => 'perl',
INSTALLMAN1DIR => "$base/doc",
INSTALLMAN3DIR => "$base/doc",
INSTALLPRIVLIB => "$base/lib",
INSTALLSCRIPT => "$base/bin",
};

my %Special;

use Config;

eval {
require 'scripts/initp.pl';
};

if(! $MV::Self ) {
$MV::Self = $self;
$Special{perlpath} = $Config{perlpath};
$Special{perlpath} .= <<EOF;


eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
if 0; # not running under some shell
EOF
$Special{perlpath} =~ s/\s+$//;
}


sub doit {
my ($key) = @_;
my $val;
if ($MV::Self->{RPMBUILDDIR} and $val = $MV::Self->{$key}) {
$val =~ s!^$MV::Self->{RPMBUILDDIR}/!/!;
return $val;
}
return $MV::Self->{$key} unless $key =~ /[a-z]/;
return $Special{$key} if defined $Special{$key};
$Config{$key};
}

DOIT: {
local ($/);
local($_) = <<'_EoP_';
#!/usr/bin/perl
##!~_~perlpath~_~
#
# Interchange database updater
#
# $Id: update.PL,v 2.0.2.4 2003-01-24 06:51:54 jon Exp $
#
# Copyright (C) 1996-2003 Red Hat, Inc. and
# Interchange Development Group, http://www.icdevgroup.org/
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA.

use lib '/usr/local/interchange/lib';
#use lib '~_~INSTALLPRIVLIB~_~';
use lib '/usr/local/interchange';
#use lib '~_~INSTALLARCHLIB~_~';

use strict;
use Fcntl;
use Vend::Config;
use Vend::Data;
use Vend::Util;

BEGIN {
eval {
require 5.004;
require FindBin;
1 and $Global::VendRoot = "$FindBin::RealBin";
1 and $Global::VendRoot =~ s/.bin$//;
};
($Global::VendRoot = $ENV{MINIVEND_ROOT})
if defined $ENV{MINIVEND_ROOT};
$Global::VendRoot = $Global::VendRoot || '/usr/local/interchange';
# $Global::VendRoot = $Global::VendRoot || '~_~INSTALLARCHLIB~_~';

if(-f "$Global::VendRoot/interchange.cfg") {
$Global::ExeName = 'interchange';
$Global::ConfigFile = 'interchange.cfg';
}
elsif(-f "$Global::VendRoot/minivend.cfg") {
$Global::ExeName = 'minivend';
$Global::ConfigFile = 'minivend.cfg';
}
elsif(-f "$Global::VendRoot/interchange.cfg.dist") {
$Global::ExeName = 'interchange';
$Global::ConfigFile = 'interchange.cfg';
}
}

### END CONFIGURATION VARIABLES

sub dontwarn { $FindBin::RealBin; }

$Global::ErrorFile = "$Global::VendRoot/error.log";
$Vend::ExternalProgram = 1;

my $DEBUG = 0;

#select a DBM

BEGIN {
$Global::GDBM = $Global::DB_File = 0;
AUTO: {
last AUTO if
(defined $ENV{MINIVEND_DBFILE} and $Global::DB_File = 1);
last AUTO if
(defined $ENV{MINIVEND_NODBM});
eval {require GDBM_File and $Global::GDBM = 1};
eval {require DB_File and $Global::DB_File = 1};
}
if($Global::GDBM) {
require Vend::Table::GDBM;
import GDBM_File;
$Global::GDBM = 1;
$Global::Default_database = 'GDBM';
}
if($Global::DB_File) {
require Vend::Table::DB_File;
import DB_File;
$Global::DB_File = 1;
$Global::Default_database = 'DB_FILE'
unless defined $Global::Default_database;
}
if(! $Global::GDBM and ! $Global::DB_File) {
die "No DBM defined! Update not designed to work with DBI or memory databases.\n";
}
}

$Vend::Cfg = {};

my $Name = 'products';
my $Directory;

my $USAGE = <<EOF;
usage: update -c catalog [-n name] \\
-f field [-f field1 -f field2 ...] -k key value [value1 value2 ...]
or

usage: update -c catalog -i inputfile [-n name]

Options:

-c catalog Catalog name as defined in interchange.cfg.
-f field Field name(s) in database. If multiple fields are specified,
multiple corresponding values must be supplied. Use '' to
set to the empty string.
-i file Input file to add entries to an existing database. (Must
be in same format/order as existing database.)
-k key Key (item code) to be updated.
-n name Database name as defined in catalog.cfg (default products).

If specifying a subcatalog database, make sure it is defined in the
subcatalog definition. If it is in the base catalog, use that catalog
as the parameter for the -c directive.
EOF

my ($Inputfile, $Key, @Fields, @Values);
my ($Catalog,$delimiter,$db);

GETOPT: {

if($ARGV[0] eq '-c') {
shift(@ARGV);
$Catalog = shift(@ARGV);
redo GETOPT;
}
elsif($ARGV[0] eq '-d') {
shift(@ARGV);
$Directory = shift(@ARGV);
redo GETOPT;
}
elsif($ARGV[0] eq '-n') {
shift(@ARGV);
$Name = shift(@ARGV);
redo GETOPT;
}
elsif($ARGV[0] eq '-k') {
shift(@ARGV);
$Key = shift(@ARGV);
redo GETOPT;
}
elsif($ARGV[0] eq '-i') {
shift(@ARGV);
$Inputfile = shift(@ARGV);
redo GETOPT;
}
elsif($ARGV[0] eq '-f') {
shift(@ARGV);
push(@Fields, shift @ARGV);
redo GETOPT;
}

} # END GETOPT

die $USAGE unless defined $Catalog;

push @Values, @ARGV;

if(@Fields and ! @Values) {
die $USAGE . "\n";
}
elsif (scalar(@Fields) != scalar(@Values) ) {
die "Number of fields and number of values don't match.\n" . $USAGE . "\n";
}
elsif ((@Fields or @Values) and defined $Inputfile) {
die "No field or value arguments accepted when inputting from a file.\n" .
$USAGE . "\n";
}
elsif (@Fields and ! $Key) {
die $USAGE . "\n";
}
elsif (!defined $Inputfile and ! @Fields and !@Values) {
die $USAGE . "\n";
}

my($name,$dir,$param,$subcat,$subconfig);
chdir $Global::VendRoot;
open(GLOBAL, "< $Global::ConfigFile") or
die "No global configuration file? Aborting.\n";
while(<GLOBAL>) {
next unless /^\s*(sub)?catalog\s+$Catalog\s+/i;
$subcat = $1 || '';
chomp;
s/^\s+//;
unless($subcat) {
(undef,$name,$dir,$param) = split /\s+/, $_, 4;
}
else {
(undef,$name,$subconfig,$dir,$param) = split /\s+/, $_, 5;
}
last;

}
close GLOBAL;

global_config();

chdir $dir or die "Couldn't change directory to $dir: $!\n";

$Vend::ExternalProgram = $Vend::Quiet = 1;

$Vend::Cfg = config($name, $dir, "$dir/etc", ($subconfig || undef));
$::Variable = $Vend::Cfg->{Variable};

die "Problems with config.\n" unless defined $Vend::Cfg;

$Vend::Cfg->{ProductDir} = $Directory
if defined $Directory;

die "Bad data directory $Vend::Cfg->{ProductDir} -- doesn't exist.\n$USAGE\n"
unless -d $Vend::Cfg->{ProductDir};

open_database(1);

$Vend::WriteDatabase{$Name} = 1;

die "Bad database $Name -- doesn't exist.\n\n$USAGE\n"
unless $db = database_exists_ref($Name);

my $ref;
eval {
$ref = $db->ref();
};

die "Bad open of database $Name from catalog $Catalog ($!): $@\n"
unless $ref and ! $@;

unless($ref->record_exists($Key)) {
die "Key $Key not found in database $Name.\n";
}

my ($key,$field,@fields);

my $key_col = $Vend::Table::Common::KEY_IDX;

if (! defined $Inputfile ) {
foreach $field (@Fields) {
unless ( defined $ref->test_column($field) ) {
die "$field is not a column in the database.\n";
}
my $val = shift @Values;
print "setting ${Name}::${field}::$Key=$val\n";
$ref->set_field($Key, $field, $val);
}
}
else {
open (INPUT, "< $Inputfile") or die "Couldn't open input file $Inputfile: $!\n";
while(<INPUT>) {
chomp;
s/[\r\cZ]+//;
(@fields) = split /\t/, $_;
$key = $fields[$key_col];
$ref->set_row($key, @fields);
}
close INPUT;
}

close_database();

=head1 NAME

update -- command line setting of Interchange databases

=head1 VERSION

1.0

=head1 SYNOPSIS

update -c catalog [-f field -k key [-t table] value]

=head1 DESCRIPTION

Interchange's C<update> is a rudimentary method of directly setting the
DBM files (not the ASCII files) of a Interchange DBM database.

NOTE: This command DOES NOT APPLY TO SQL databases. They have their own
command line monitors that are more flexible.

=head1 OPTIONS

=over 4

=item -c name

Sets the catalog for which C<update> operates. It reads the
catalog.cfg file to retrieve database settings.

=item -f field

The name of the field to set.

=item -n name

The name of the table to set. If the table is not a DBM database the
C<update> program will terminate with an error.

=back

=head1 SEE ALSO

http://www.icdevgroup.org/

=head1 AUTHOR

Mike Heins, <mike@perusion.com>

_EoP_
s{.*\n(#(.*)~_~(\w+)~_~(.*))}{$2 . doit($3) . "$4\n$1"}eg;
my $file = $0;
$file =~ s/\.PL$//;
open(OUT, ">$file")
or die "Create $file: $!\n";
print OUT $_;
}
Something went wrong with that request. Please try again.