|
From: Chris W. <la...@us...> - 2001-11-26 13:44:47
|
Update of /cvsroot/openinteract/OpenInteract/pkg/base_page/script
In directory usw-pr-cvs1:/tmp/cvs-serv15258/script
Modified Files:
scan_for_new.pl
Log Message:
works now
Index: scan_for_new.pl
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract/pkg/base_page/script/scan_for_new.pl,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** scan_for_new.pl 2001/11/26 06:55:39 1.2
--- scan_for_new.pl 2001/11/26 13:44:45 1.3
***************
*** 8,17 ****
use OpenInteract::Startup;
! use constant DEBUG => 1;
my $NOW = now;
my $DATE_PATTERN = '%Y-%m-%d';
my $DEFAULT_ACTIVE_DAYS = 365;
!
my ( %EXISTING, %NEW );
my ( @OPT_skip );
--- 8,17 ----
use OpenInteract::Startup;
! use constant DEBUG => 0;
my $NOW = now;
my $DATE_PATTERN = '%Y-%m-%d';
my $DEFAULT_ACTIVE_DAYS = 365;
! my @ALWAYS_SKIP = ( "~\$", 'pod2', 'tmp', 'bak', 'old', '^/images', '^/oi_docs' );
my ( %EXISTING, %NEW );
my ( @OPT_skip );
***************
*** 26,36 ****
$OPT_root ||= $R->CONFIG->get_dir( 'html' );
! unless ( $OPT_root =~ m|/$| ) { $OPT_root = "$OPT_root/" }
$OPT_active_days ||= $DEFAULT_ACTIVE_DAYS;
$OPT_debug ||= DEBUG;
%EXISTING = map { $_ => 1 }
@{ $R->page->db_select({ select => [ 'location' ],
return => 'single-list' }) };
find( \&descend, $OPT_root );
--- 26,39 ----
$OPT_root ||= $R->CONFIG->get_dir( 'html' );
! $OPT_root =~ s|/$||;
$OPT_active_days ||= $DEFAULT_ACTIVE_DAYS;
$OPT_debug ||= DEBUG;
+ push @OPT_skip, @ALWAYS_SKIP;
+
%EXISTING = map { $_ => 1 }
@{ $R->page->db_select({ select => [ 'location' ],
+ from => [ $R->page->table_name ],
return => 'single-list' }) };
find( \&descend, $OPT_root );
***************
*** 47,55 ****
sub descend {
my $filename = $_;
my $full_dir = $File::Find::dir;
$full_dir =~ s/^$OPT_root//;
! for ( @OPT_skip ) { return if ( $full_dir =~ /$_/ ) }
! my $location = '/' . join( '/', $full_dir, $filename );
return if ( $EXISTING{ $location } );
$NEW{ $location }++;
}
--- 50,66 ----
sub descend {
my $filename = $_;
+ return if ( $filename =~ /^\.+$/ );
+ return unless ( -f $filename );
my $full_dir = $File::Find::dir;
$full_dir =~ s/^$OPT_root//;
! $full_dir =~ s|/$||;
!
! foreach my $pattern ( @OPT_skip ) {
! return if ( $full_dir =~ /$pattern/ );
! }
! my $location = join( '/', $full_dir, $filename );
! $location = "/$location" unless ( $location =~ m|^/| );
return if ( $EXISTING{ $location } );
+ $OPT_debug && warn "--Adding ($location) as new file\n";
$NEW{ $location }++;
}
***************
*** 58,65 ****
sub get_page_info {
my ( $R, $location ) = @_;
! my %info = ();
! my $full_filename = join( '/', $OPT_root, $location );
! open( FILE, $full_filename ) || die "Cannot open ($full_filename): $!";
while ( <FILE> ) {
$info{title} = $1 if ( m|<title>(.*?)</title>| );
--- 69,81 ----
sub get_page_info {
my ( $R, $location ) = @_;
! my $full_filename = join( '', $OPT_root, $location );
! my $mime_type = $R->page->mime_type_file( $full_filename ) ||
! 'text/html';
! my %info = ( mime_type => $mime_type,
! size => (stat $full_filename)[7] );
! $OPT_debug && warn "--MIME type found for ($location): $mime_type\n";
! return %info unless ( $mime_type eq 'text/html' );
+ open( FILE, $full_filename ) || die "Cannot open ($full_filename): $!";
while ( <FILE> ) {
$info{title} = $1 if ( m|<title>(.*?)</title>| );
***************
*** 73,85 ****
my ( $R, $location, $page_info ) = @_;
my $expire_date = $NOW + "${OPT_active_days}D";
- my $full_filename = join( '/', $OPT_root, $location );
- my $mime_type = $R->page->mime_type_file( $full_filename ) ||
- 'text/html'
$R->page->new({ location => $location,
! mime_type => $mime_type,
title => $page_info->{title},
is_active => 'yes',
active_on => $NOW->strftime( $DATE_PATTERN ),
! expires_on => $expire_date->strftime( $DATE_PATTERN ) })
->save();
}
--- 89,100 ----
my ( $R, $location, $page_info ) = @_;
my $expire_date = $NOW + "${OPT_active_days}D";
$R->page->new({ location => $location,
! mime_type => $page_info->{mime_type},
title => $page_info->{title},
is_active => 'yes',
active_on => $NOW->strftime( $DATE_PATTERN ),
! expires_on => $expire_date->strftime( $DATE_PATTERN ),
! size => $page_info->{size},
! storage => 'file' })
->save();
}
|