File: [local] / wpscripts / ztransfer / fetch.pm (download)
Revision 1.1.1.1 (vendor branch), Fri Jun 3 09:28:47 2011 UTC (12 years, 11 months ago) by yason
Branch: yason
CVS Tags: import Changes since 1.1: +0 -0 lines
import scripts for fullprint
|
#!/usr/bin/perl
# $Id: fetch.pm,v 1.1.1.1 2011/06/03 09:28:47 yason Exp $
package fetch;
use db;
use log; # bad! only for log::filelist()
use warnings;
my $EXPAND_SYMLINKS = 1;
my $QUERY_Z = "SELECT ID,Path,file_priority FROM upload_files WHERE Status=0 AND type_file=0";
my $QUERY_J = "SELECT ID,Path,file_priority FROM upload_files WHERE Status=0 AND type_file=1";
my $QUERY_P = "SELECT ID,Path,file_priority FROM upload_files WHERE Status=0 AND type_file=2";
my $QUERY_T = "SELECT ID,Path,file_priority FROM upload_files WHERE Status=0 AND type_file=3";
my $sth;
my @stack_ids; # stack for ID's
my @stack_paths;# stack for Path's
my $tos = 0; # top of stack
sub stack_push($$)
{
$stack_ids[$tos] = shift;
$stack_paths[$tos] = shift;
$tos++;
}
sub zayavki_list()
{
my @dbids;
my @dbpaths;
my @dbpri;
my $i = 0;
$sth = $db::dbh->prepare($QUERY_Z);
$sth->execute( );
while( ($dbids[$i], $dbpaths[$i], $dbpri[$i]) = $sth->fetchrow_array( ) )
{
if($dbids[$i]) # element exists (THIS CODE SHOULD BE FIXED)
{
#convert samba-paths to local unix paths
$dbpaths[$i] = substr($dbpaths[$i], 23); # remove \\fileserver\wideprint\
$dbpaths[$i] =~ tr/\\/\//; # convert each \ to /
$dbpaths[$i] = '/WIDEPRINT/' . $dbpaths[$i];
$dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) );
#
# We must not save non-existent local file in array!
# Returning of array with bad element is deprecated,
# So this code too weak to work correctly.
#
if($EXPAND_SYMLINKS && -e $dbpaths[$i])
{
chomp( $_ = `dirname $dbpaths[$i] | xargs /usr/bin/readlink` );
chomp( $dbpaths[$i] = $_ . '/' . `basename $dbpaths[$i]` );
# increment $i ONLY if local file exists, otherwise replace element in next iteration
$i++;
}
# if localfile does not exists, write result of next iteration on its place
}
else
{
next;
}
}
# strip last row in arrays by decrementing $i counter
# SHOULD BE FIXED!
$i--;
$#dbids = $i;
$#dbpaths = $i;
# reformat listing using file_priority database field
for($i = 0;$i < scalar(@dbids); $i++)
{
stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 0);
}
for($i = 0;$i < scalar(@dbids); $i++)
{
stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 1);
}
for($i = 0;$i < scalar(@dbids); $i++)
{
stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 2);
}
@dbids = @stack_ids;
@dbpaths = @stack_paths;
# make current files list via log::filelist()
log::filelist(\@dbpaths);
# we return the list of references to @dbids and @dbpaths
return( (\@dbids, \@dbpaths) );
}
sub jpegs_list()
{
my @dbids;
my @dbpaths;
my $i = 0;
$sth = $db::dbh->prepare($QUERY_J);
$sth->execute( );
while(($dbids[$i], $dbpaths[$i]) = $sth->fetchrow_array( ) )
{
$dbpaths[$i] = substr($dbpaths[$i], 23);
$dbpaths[$i] =~ tr/\\/\//;
$dbpaths[$i] = '/WIDEPRINT/' . $dbpaths[$i];
$dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) );
if($EXPAND_SYMLINKS && -e $dbpaths[$i])
{
chomp( $_ = `dirname $dbpaths[$i] | xargs /usr/bin/readlink` );
chomp( $dbpaths[$i] = $_ . '/' . `basename $dbpaths[$i]` );
}
$i++;
}
$i--;
$#dbids = $i;
$#dbpaths = $i;
log::filelist(\@dbpaths);
return( (\@dbids, \@dbpaths) );
}
sub probas_list()
{
my @dbids;
my @dbpaths;
my $i = 0;
$sth = $db::dbh->prepare($QUERY_P);
$sth->execute( );
while(($dbids[$i], $dbpaths[$i]) = $sth->fetchrow_array( ) )
{
$dbpaths[$i] = substr($dbpaths[$i], 23);
$dbpaths[$i] =~ tr/\\/\//;
$dbpaths[$i] = '/WIDEPRINT/' . $dbpaths[$i];
$dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) );
if($EXPAND_SYMLINKS && -e $dbpaths[$i])
{
chomp( $_ = `dirname $dbpaths[$i] | xargs /usr/bin/readlink` );
chomp( $dbpaths[$i] = $_ . '/' . `basename $dbpaths[$i]` );
}
$i++;
}
$i--;
$#dbids = $i;
$#dbpaths = $i;
log::filelist(\@dbpaths);
return( (\@dbids, \@dbpaths) );
}
sub tpps_list()
{
my @dbids;
my @dbpaths;
my $i = 0;
$sth = $db::dbh->prepare($QUERY_T);
$sth->execute( );
while(($dbids[$i], $dbpaths[$i]) = $sth->fetchrow_array( ) )
{
$dbpaths[$i] = substr($dbpaths[$i], 23);
$dbpaths[$i] =~ tr/\\/\//;
$dbpaths[$i] = '/WIDEPRINT/' . $dbpaths[$i];
$dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) );
if($EXPAND_SYMLINKS && -e $dbpaths[$i])
{
chomp( $_ = `dirname $dbpaths[$i] | xargs /usr/bin/readlink` );
chomp( $dbpaths[$i] = $_ . '/' . `basename $dbpaths[$i]` );
}
$i++;
}
$i--;
$#dbids = $i;
$#dbpaths = $i;
log::filelist(\@dbpaths);
return( (\@dbids, \@dbpaths) );
}
return(1);