[interchange-cvs] interchange - heins modified 3 files
interchange-core@icdevgroup.org
interchange-core@icdevgroup.org
Sat Jul 20 21:16:01 2002
User: heins
Date: 2002-07-21 01:15:02 GMT
Modified: scripts interchange.PL
Modified: lib/Vend Config.pm Error.pm
Log:
* Change cron facility to:
-- Use $Vend::Cfg->{Cron} for setup
-- Now emails either to command line address or $Vend::Cfg->{Cron}{email}.
-- Now logs to $Vend::Cfg->{Cron}{log}.
-- Can add session dump when $Vend::Cfg->{Cron}{add_session}.
-- Base directory set by $Vend::Cfg->{Cron}{base_directory}, defaults
to etc/cron.
* TODO: Think about adding "disable" param to block execution.
Revision Changes Path
2.42 +111 -78 interchange/scripts/interchange.PL
rev 2.42, prev_rev 2.41
Index: interchange.PL
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /anon_cvs/repository/interchange/scripts/interchange.PL,v
retrieving revision 2.41
retrieving revision 2.42
diff -u -r2.41 -r2.42
--- interchange.PL 19 Jul 2002 05:13:16 -0000 2.41
+++ interchange.PL 21 Jul 2002 01:15:02 -0000 2.42
@@ -3,7 +3,7 @@
#
# Interchange version 4.9.1
#
-# $Id: interchange.PL,v 2.41 2002/07/19 05:13:16 mheins Exp $
+# $Id: interchange.PL,v 2.42 2002/07/21 01:15:02 mheins Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
@@ -1447,35 +1447,42 @@
}
=20
sub run_in_catalog {
- my ($cat_name, $directory, $itl) =3D @_;
+ my ($cat, $job, $itl) =3D @_;
my ($g,$c);
=20
-#::logGlobal("running job in cat=3D$cat_name");
- $g =3D $Global::Catalog{$cat_name};
+#::logGlobal("running job in cat=3D$cat");
+ $g =3D $Global::Catalog{$cat};
unless (defined $g) {
- logGlobal( "Can't find catalog '%s'" , $cat_name );
+ logGlobal( "Can't find catalog '%s'" , $cat );
return undef;
}
=20
#$Vend::Log_suppress =3D 1;
=20
unless ($Vend::Quiet) {
- logGlobal("Run cron group=3D%s", $directory || 'INTERNAL');
+ logGlobal("Run catalog '%s' cron group=3D%s", $cat, $job || 'INTERNAL');
}
#undef $Vend::Log_suppress;
=20
- open_cat($cat_name);
+ open_cat($cat);
+
+ logError("Run cron group=3D%s", $job || 'INTERNAL');
+
+ my $croncfg =3D $Vend::Cfg->{Cron};
=20
my $dir;
my @itl;
- if($directory) {
- my $ct =3D $Vend::Cfg->{TemplateDir} || [];
- my $gt =3D $Global::TemplateDir || [];
-
- for my $d ($Vend::Cfg->{PageDir}, @$ct, @$gt) {
-#::logGlobal("check directory=3D$d for $directory");
- $dir =3D "$d/$directory"
- if -d "$d/$directory";
+ if($job) {
+ my $ct =3D $croncfg->{base_directory} || 'etc/cron';
+ my $gt =3D '';
+ $gt =3D "$Global::ConfDir/$ct" if $croncfg->{use_global};
+
+ for my $d ($ct, $gt) {
+#::logGlobal("check directory=3D$d for $job");
+ next unless $d;
+ next unless -d "$d/$job";
+ $dir =3D "$d/$job";
+ last;
}
if($dir) {
my @f =3D glob("$dir/*");
@@ -1492,20 +1499,56 @@
push @itl, ["Passed ITL", $itl];
}
=20
- if(! @itl) {
- logGlobal("Empty cron job=3D%s", $directory);
- }
-
my @out;
- for(@itl) {
- logError("Running cron task=3D%s", $_->[0]);
- push @out, interpolate_html($_->[1]);
- }
=20
- close_cat();
+ if(@itl) {
+ # Run once at beginning
+ run_macro($croncfg->{initialize});
+
+ # initialize or autoload can create session
+ # but must handle all aspects
+ init_session() unless $Vend::Session;
+
+ $CGI::remote_addr ||=3D 'none';
+ $CGI::useragent ||=3D 'commandline';
+
+ for(@itl) {
+ # Run once at beginning of each job
+ run_macro($croncfg->{autoload});
+
+ push @out, interpolate_html($_->[1]);
+ }
+ }
+ else {
+ logGlobal("Empty cron job=3D%s", $job);
+ }
my $out =3D join "", @out;
$out =3D~ s/^\s+//;
$out =3D~ s/\s+$/\n/;
+ $out .=3D full_dump() if $croncfg->{add_session};=20
+
+ close_cat();
+ if(my $addr =3D $Vend::CronEmail || $croncfg->{email}) {
+ my $subject =3D $croncfg->{subject} || 'Interchange cron results for job=
: %s';
+ $subject =3D errmsg($subject, $job);
+ my $from =3D $croncfg->{from} || $Vend::Cfg->{MailOrderTo};
+ Vend::Interpolate::tag_mail($addr,
+ {
+ from =3D> $from,
+ to =3D> $addr,
+ subject =3D> $subject,
+ reply_to =3D> $croncfg->{reply_to},
+ mailer =3D> "Interchange $::VERSION",
+ extra =3D> $croncfg->{extra_headers},
+ },
+ $out,
+ );
+ }
+
+ if($croncfg->{log}) {
+ logData($croncfg->{log}, $out);
+ }
+
return $out;
}
=20
@@ -1925,21 +1968,52 @@
close_database();
}
=20
+sub run_macro {
+ my $macro =3D shift
+ or return;
+
+ my @mac;
+ if(ref $macro eq 'ARRAY') {
+ @mac =3D @$macro;
+ }
+ elsif ($macro =3D~ /^[-\s\w,]+$/) {
+ @mac =3D grep /\S/, split /[\s,]+/, $macro;
+ }
+ else {
+ push @mac, $macro;
+ }
+
+ for my $m (@mac) {
+ if ($m =3D~ /^\w+$/) {
+ my $sub =3D $Vend::Cfg->{Sub}{$m} || $Global::GlobalSub->{$m}
+ or do {
+ logError("Unknown Autoload macro '%s'.", $macro);
+ next;
+ };
+ $sub->();
+ }
+ elsif($m =3D~ /^\w+-\w+$/) {
+ Vend::Interpolate::tag_profile($m);
+ }
+ else {
+ interpolate_html($m);
+ }
+ }
+}
+
sub dispatch {
my($http) =3D @_;
$H =3D $http;
=20
adjust_cgi();
=20
- my($sessionid, $seed);
- my(@path);
- my($g, $action);
-
open_cat();
=20
$CGI::user =3D Vend::Util::check_authorization($CGI::authorization)
if defined $CGI::authorization;
=20
+ my($sessionid, $seed);
+
$sessionid =3D $CGI::values{mv_session_id} || undef;
$sessionid =3D~ s/\0.*//s;
=20
@@ -2210,62 +2284,21 @@
}
# END LEGACY
=20
- my $macro;
- if ($macro =3D $Vend::Cfg->{Autoload}) {
- if($macro =3D~ /\[\w+/) {
- interpolate_html($macro);
- }
- elsif ($macro =3D~ /^\w+$/) {
- my $sub =3D $Vend::Cfg->{Sub}{$macro} || $Global::GlobalSub->{$macro};
- $sub->();
- }
+ run_macro($Vend::Cfg->{Autoload});
#show_times("end global Autoload macro") if $Global::ShowTimes;
- }
=20
- if ($macro =3D $Vend::Cfg->{Filter}) {
- for(keys %$macro) {
- Vend::Interpolate::input_filter_do($_, { 'op' =3D> $macro->{$_} } );
+ for my $macro ( $Vend::Cfg->{Filter}, $Vend::Session->{Filter}) {
+ next unless $macro;
+ if (ref($macro) ne 'HASH') {
+ logError("Bad CGI filter '%s'", $macro);
}
- }
-
- if (
- defined $Vend::Session->{Filter} and
- $macro =3D $Vend::Session->{Filter}
- )
- {
for(keys %$macro) {
- Vend::Interpolate::input_filter_do($_, $macro->{$_});
+ Vend::Interpolate::input_filter_do($_, { op =3D> $macro->{$_} } );
}
}
=20
- if (
- defined $Vend::Session->{Autoload} and
- $macro =3D $Vend::Session->{Autoload}
- )
- {
- if(ref $macro) {
- for (@$macro) {
- if ($macro =3D~ /^\w+$/) {
- my $sub =3D $Vend::Cfg->{Sub}{$macro} || $Global::GlobalSub->{$macro};
- $sub->();
- }
- elsif(/^\w+-\w+$/) {
- Vend::Interpolate::tag_profile($_);
- }
- else {
- interpolate_html($_);
- }
- }
- }
- elsif ($macro =3D~ /^\w+$/) {
- my $sub =3D $Vend::Cfg->{Sub}{$macro} || $Global::GlobalSub->{$macro};
- $sub->();
- }
- else {
- interpolate_html($macro);
- }
+ run_macro($Vend::Session->{Autoload});
#show_times("end session Autoload macro") if $Global::ShowTimes;
- }
=20
# If the cgi-bin program was invoked with no extra path info,
# just display the catalog page.
@@ -2325,7 +2358,7 @@
#::logDebug("path=3D$Vend::FinalPath");
=20
DOACTION: {
- @path =3D split('/', $Vend::FinalPath, 2);
+ my @path =3D split('/', $Vend::FinalPath, 2);
if (defined $CGI::values{mv_action}) {
$CGI::values{mv_todo} =3D $CGI::values{mv_action}
if ! defined $CGI::values{mv_todo}
@@ -2349,7 +2382,7 @@
}
=20
#::logGlobal("action=3D$Vend::Action path=3D$Vend::FinalPath");
- my ($sub, $status);
+ my ($sub, $status, $action);
if(defined $Vend::Cfg->{ActionMap}{$Vend::Action}) {
$sub =3D $Vend::Cfg->{ActionMap}{$Vend::Action};
$CGI::values{mv_nextpage} =3D $Vend::FinalPath
2.56 +3 -2 interchange/lib/Vend/Config.pm
rev 2.56, prev_rev 2.55
Index: Config.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /anon_cvs/repository/interchange/lib/Vend/Config.pm,v
retrieving revision 2.55
retrieving revision 2.56
diff -u -r2.55 -r2.56
--- Config.pm 19 Jul 2002 19:53:19 -0000 2.55
+++ Config.pm 21 Jul 2002 01:15:02 -0000 2.56
@@ -1,6 +1,6 @@
# Vend::Config - Configure Interchange
#
-# $Id: Config.pm,v 2.55 2002/07/19 19:53:19 jon Exp $
+# $Id: Config.pm,v 2.56 2002/07/21 01:15:02 mheins Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
@@ -44,7 +44,7 @@
use Vend::Parse;
use Vend::Util;
=20
-$VERSION =3D substr(q$Revision: 2.55 $, 10);
+$VERSION =3D substr(q$Revision: 2.56 $, 10);
=20
my %CDname;
=20
@@ -489,6 +489,7 @@
['DescriptionField', undef, 'description'],
['PriceDefault', undef, 'price'],
['PriceField', undef, 'price'],
+ ['Cron', 'hash', ''],
['Shipping', 'locale', ''],
['Accounting', 'locale', ''],
['Levies', 'array', ''],
2.4 +9 -7 interchange/lib/Vend/Error.pm
rev 2.4, prev_rev 2.3
Index: Error.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /anon_cvs/repository/interchange/lib/Vend/Error.pm,v
retrieving revision 2.3
retrieving revision 2.4
diff -u -r2.3 -r2.4
--- Error.pm 17 Jun 2002 22:24:07 -0000 2.3
+++ Error.pm 21 Jul 2002 01:15:02 -0000 2.4
@@ -1,6 +1,6 @@
# Vend::Error - Handle Interchange error pages and messages
#=20
-# $Id: Error.pm,v 2.3 2002/06/17 22:24:07 jon Exp $
+# $Id: Error.pm,v 2.4 2002/07/21 01:15:02 mheins Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
@@ -37,7 +37,7 @@
=20
use vars qw/$VERSION/;
=20
-$VERSION =3D substr(q$Revision: 2.3 $, 10);
+$VERSION =3D substr(q$Revision: 2.4 $, 10);
=20
sub get_locale_message {
my ($code, $message, @arg) =3D @_;
@@ -120,11 +120,14 @@
=20
$out =3D minidump();
local($Data::Dumper::Indent) =3D 2;
- unless(caller() eq 'Vend::SOAP') {
- $out .=3D "###### ENVIRONMENT #####\n";
- $out .=3D ::uneval(::http()->{env});
- $out .=3D "\n###### END ENVIRONMENT #####\n";
+ $out .=3D "###### ENVIRONMENT #####\n";
+ if(my $h =3D ::http()) {
+ $out .=3D ::uneval($h->{env});
}
+ else {
+ $out .=3D ::uneval(\%ENV);
+ }
+ $out .=3D "\n###### END ENVIRONMENT #####\n";
$out .=3D "###### CGI VALUES #####\n";
$out .=3D ::uneval(\%CGI::values);
$out .=3D "\n###### END CGI VALUES #####\n";
@@ -134,7 +137,6 @@
$out =3D~ s/\0/\\0/g;
return $out;
}
-
=20
sub do_lockout {
my ($cmd);