[BACK]Return to fetch.pm CVS log [TXT][DIR] Up to [local] / wpscripts / ztransfer

Annotation of wpscripts/ztransfer/fetch.pm, Revision 1.1

1.1     ! yason       1: #!/usr/bin/perl
        !             2: # $Id: fetch.pm,v 1.1.1.7 2006/12/06 14:45:25 init Exp $
        !             3: package fetch;
        !             4: use db;
        !             5: use log;  # bad! only for log::filelist()
        !             6: use warnings;
        !             7: my $EXPAND_SYMLINKS = 1;
        !             8: my $QUERY_Z = "SELECT ID,Path,file_priority FROM upload_files WHERE Status=0 AND type_file=0";
        !             9: my $QUERY_J = "SELECT ID,Path,file_priority FROM upload_files WHERE Status=0 AND type_file=1";
        !            10: my $QUERY_P = "SELECT ID,Path,file_priority FROM upload_files WHERE Status=0 AND type_file=2";
        !            11: my $QUERY_T = "SELECT ID,Path,file_priority FROM upload_files WHERE Status=0 AND type_file=3";
        !            12:
        !            13: my $sth;
        !            14:
        !            15: my @stack_ids; # stack for ID's
        !            16: my @stack_paths;# stack for Path's
        !            17: my $tos = 0;   # top of stack
        !            18:
        !            19:
        !            20: sub stack_push($$)
        !            21: {
        !            22:     $stack_ids[$tos] = shift;
        !            23:     $stack_paths[$tos] = shift;
        !            24:     $tos++;
        !            25: }
        !            26:
        !            27:
        !            28: sub zayavki_list()
        !            29: {
        !            30:     my @dbids;
        !            31:     my @dbpaths;
        !            32:     my @dbpri;
        !            33:     my $i = 0;
        !            34:
        !            35:     $sth = $db::dbh->prepare($QUERY_Z);
        !            36:     $sth->execute( );
        !            37:     while( ($dbids[$i], $dbpaths[$i], $dbpri[$i]) = $sth->fetchrow_array( ) )
        !            38:     {
        !            39:        if($dbids[$i])  # element exists (THIS CODE SHOULD BE FIXED)
        !            40:        {
        !            41:            #convert samba-paths to local unix paths
        !            42:            $dbpaths[$i] = substr($dbpaths[$i], 23);    # remove \\fileserver\wideprint\
        !            43:            $dbpaths[$i] =~ tr/\\/\//;                  # convert each \ to /
        !            44:            $dbpaths[$i] = '/WIDEPRINT/' . $dbpaths[$i];
        !            45:            $dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) );
        !            46:                #
        !            47:                # We must not save non-existent local file in array!
        !            48:                # Returning of array with bad element is deprecated,
        !            49:                # So this code too weak to work correctly.
        !            50:                #
        !            51:                if($EXPAND_SYMLINKS && -e $dbpaths[$i])
        !            52:                {
        !            53:                    chomp( $_ = `dirname $dbpaths[$i] | xargs /usr/bin/readlink` );
        !            54:                    chomp( $dbpaths[$i] = $_ . '/' . `basename $dbpaths[$i]` );
        !            55:
        !            56:                    # increment $i ONLY if local file exists, otherwise replace element in next iteration
        !            57:                    $i++;
        !            58:                }
        !            59:                # if localfile does not exists, write result of next iteration on its place
        !            60:        }
        !            61:        else
        !            62:        {
        !            63:            next;
        !            64:        }
        !            65:     }
        !            66:
        !            67:     # strip last row in arrays by decrementing $i counter
        !            68:     # SHOULD BE FIXED!
        !            69:     $i--;
        !            70:     $#dbids = $i;
        !            71:     $#dbpaths = $i;
        !            72:
        !            73:     # reformat listing using file_priority database field
        !            74:     for($i = 0;$i < scalar(@dbids); $i++)
        !            75:     {
        !            76:        stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 0);
        !            77:     }
        !            78:        for($i = 0;$i < scalar(@dbids); $i++)
        !            79:        {
        !            80:            stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 1);
        !            81:        }
        !            82:            for($i = 0;$i < scalar(@dbids); $i++)
        !            83:            {
        !            84:                stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 2);
        !            85:            }
        !            86:     @dbids = @stack_ids;
        !            87:     @dbpaths = @stack_paths;
        !            88:
        !            89:     # make current files list via log::filelist()
        !            90:     log::filelist(\@dbpaths);
        !            91:
        !            92:     # we return the list of references to @dbids and @dbpaths
        !            93:     return( (\@dbids, \@dbpaths) );
        !            94: }
        !            95:
        !            96:
        !            97: sub jpegs_list()
        !            98: {
        !            99:     my @dbids;
        !           100:     my @dbpaths;
        !           101:     my $i = 0;
        !           102:
        !           103:     $sth = $db::dbh->prepare($QUERY_J);
        !           104:     $sth->execute( );
        !           105:     while(($dbids[$i], $dbpaths[$i]) = $sth->fetchrow_array( ) )
        !           106:     {
        !           107:        $dbpaths[$i] = substr($dbpaths[$i], 23);
        !           108:        $dbpaths[$i] =~ tr/\\/\//;
        !           109:        $dbpaths[$i] = '/WIDEPRINT/' . $dbpaths[$i];
        !           110:        $dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) );
        !           111:            if($EXPAND_SYMLINKS && -e $dbpaths[$i])
        !           112:            {
        !           113:                chomp( $_ = `dirname $dbpaths[$i] | xargs /usr/bin/readlink` );
        !           114:                chomp( $dbpaths[$i] = $_ . '/' . `basename $dbpaths[$i]` );
        !           115:            }
        !           116:        $i++;
        !           117:     }
        !           118:
        !           119:     $i--;
        !           120:     $#dbids = $i;
        !           121:     $#dbpaths = $i;
        !           122:
        !           123:     log::filelist(\@dbpaths);
        !           124:
        !           125:     return( (\@dbids, \@dbpaths) );
        !           126: }
        !           127:
        !           128:
        !           129: sub probas_list()
        !           130: {
        !           131:     my @dbids;
        !           132:     my @dbpaths;
        !           133:     my $i = 0;
        !           134:
        !           135:     $sth = $db::dbh->prepare($QUERY_P);
        !           136:     $sth->execute( );
        !           137:     while(($dbids[$i], $dbpaths[$i]) = $sth->fetchrow_array( ) )
        !           138:     {
        !           139:        $dbpaths[$i] = substr($dbpaths[$i], 23);
        !           140:        $dbpaths[$i] =~ tr/\\/\//;
        !           141:        $dbpaths[$i] = '/WIDEPRINT/' . $dbpaths[$i];
        !           142:        $dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) );
        !           143:            if($EXPAND_SYMLINKS && -e $dbpaths[$i])
        !           144:            {
        !           145:                chomp( $_ = `dirname $dbpaths[$i] | xargs /usr/bin/readlink` );
        !           146:                chomp( $dbpaths[$i] = $_ . '/' . `basename $dbpaths[$i]` );
        !           147:            }
        !           148:        $i++;
        !           149:     }
        !           150:
        !           151:     $i--;
        !           152:     $#dbids = $i;
        !           153:     $#dbpaths = $i;
        !           154:
        !           155:     log::filelist(\@dbpaths);
        !           156:
        !           157:
        !           158:     return( (\@dbids, \@dbpaths) );
        !           159: }
        !           160:
        !           161:
        !           162: sub tpps_list()
        !           163: {
        !           164:     my @dbids;
        !           165:     my @dbpaths;
        !           166:     my $i = 0;
        !           167:
        !           168:     $sth = $db::dbh->prepare($QUERY_T);
        !           169:     $sth->execute( );
        !           170:     while(($dbids[$i], $dbpaths[$i]) = $sth->fetchrow_array( ) )
        !           171:     {
        !           172:        $dbpaths[$i] = substr($dbpaths[$i], 23);
        !           173:        $dbpaths[$i] =~ tr/\\/\//;
        !           174:        $dbpaths[$i] = '/WIDEPRINT/' . $dbpaths[$i];
        !           175:        $dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) );
        !           176:            if($EXPAND_SYMLINKS && -e $dbpaths[$i])
        !           177:            {
        !           178:                chomp( $_ = `dirname $dbpaths[$i] | xargs /usr/bin/readlink` );
        !           179:                chomp( $dbpaths[$i] = $_ . '/' . `basename $dbpaths[$i]` );
        !           180:            }
        !           181:        $i++;
        !           182:     }
        !           183:
        !           184:     $i--;
        !           185:     $#dbids = $i;
        !           186:     $#dbpaths = $i;
        !           187:
        !           188:     log::filelist(\@dbpaths);
        !           189:
        !           190:     return( (\@dbids, \@dbpaths) );
        !           191: }
        !           192:
        !           193:
        !           194: return(1);

CVSweb