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

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

1.1       yason       1: #!/usr/bin/perl
1.3     ! yason       2: # $Id: fetch.pm,v 1.2 2011/07/20 07:50:57 yason Exp $
1.1       yason       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";
1.2       yason       9: my $QUERY_P = "SELECT ID,Path,file_priority FROM upload_files WHERE Status=0 AND type_file=1";
1.1       yason      10:
                     11: my $sth;
                     12:
                     13: my @stack_ids; # stack for ID's
                     14: my @stack_paths;# stack for Path's
                     15: my $tos = 0;   # top of stack
                     16:
                     17:
                     18: sub stack_push($$)
                     19: {
                     20:     $stack_ids[$tos] = shift;
                     21:     $stack_paths[$tos] = shift;
                     22:     $tos++;
                     23: }
                     24:
                     25:
                     26: sub zayavki_list()
                     27: {
                     28:     my @dbids;
                     29:     my @dbpaths;
                     30:     my @dbpri;
                     31:     my $i = 0;
                     32:
                     33:     $sth = $db::dbh->prepare($QUERY_Z);
                     34:     $sth->execute( );
                     35:     while( ($dbids[$i], $dbpaths[$i], $dbpri[$i]) = $sth->fetchrow_array( ) )
                     36:     {
                     37:        if($dbids[$i])  # element exists (THIS CODE SHOULD BE FIXED)
                     38:        {
                     39:            #convert samba-paths to local unix paths
1.2       yason      40:            $dbpaths[$i] = substr($dbpaths[$i], 13);    # remove \\fileserver\
1.1       yason      41:            $dbpaths[$i] =~ tr/\\/\//;                  # convert each \ to /
1.2       yason      42:            $dbpaths[$i] = '/mnt/rmt_maket/' . $dbpaths[$i];
1.1       yason      43:            $dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) );
                     44:                #
                     45:                # We must not save non-existent local file in array!
                     46:                # Returning of array with bad element is deprecated,
                     47:                # So this code too weak to work correctly.
                     48:                #
                     49:                if($EXPAND_SYMLINKS && -e $dbpaths[$i])
                     50:                {
                     51:                    chomp( $_ = `dirname $dbpaths[$i] | xargs /usr/bin/readlink` );
                     52:                    chomp( $dbpaths[$i] = $_ . '/' . `basename $dbpaths[$i]` );
                     53:
                     54:                    # increment $i ONLY if local file exists, otherwise replace element in next iteration
                     55:                    $i++;
                     56:                }
                     57:                # if localfile does not exists, write result of next iteration on its place
                     58:        }
                     59:        else
                     60:        {
                     61:            next;
                     62:        }
                     63:     }
                     64:
                     65:     # strip last row in arrays by decrementing $i counter
                     66:     # SHOULD BE FIXED!
                     67:     $i--;
                     68:     $#dbids = $i;
                     69:     $#dbpaths = $i;
                     70:
                     71:     # reformat listing using file_priority database field
                     72:     for($i = 0;$i < scalar(@dbids); $i++)
                     73:     {
                     74:        stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 0);
                     75:     }
                     76:        for($i = 0;$i < scalar(@dbids); $i++)
                     77:        {
                     78:            stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 1);
                     79:        }
                     80:            for($i = 0;$i < scalar(@dbids); $i++)
                     81:            {
                     82:                stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 2);
                     83:            }
                     84:     @dbids = @stack_ids;
                     85:     @dbpaths = @stack_paths;
                     86:
                     87:     # make current files list via log::filelist()
                     88:     log::filelist(\@dbpaths);
                     89:
                     90:     # we return the list of references to @dbids and @dbpaths
                     91:     return( (\@dbids, \@dbpaths) );
                     92: }
                     93:
                     94:
                     95: sub probas_list()
                     96: {
                     97:     my @dbids;
                     98:     my @dbpaths;
                     99:     my $i = 0;
                    100:
                    101:     $sth = $db::dbh->prepare($QUERY_P);
                    102:     $sth->execute( );
                    103:     while(($dbids[$i], $dbpaths[$i]) = $sth->fetchrow_array( ) )
                    104:     {
                    105:        $dbpaths[$i] = substr($dbpaths[$i], 23);
                    106:        $dbpaths[$i] =~ tr/\\/\//;
                    107:        $dbpaths[$i] = '/WIDEPRINT/' . $dbpaths[$i];
                    108:        $dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) );
                    109:            if($EXPAND_SYMLINKS && -e $dbpaths[$i])
                    110:            {
                    111:                chomp( $_ = `dirname $dbpaths[$i] | xargs /usr/bin/readlink` );
                    112:                chomp( $dbpaths[$i] = $_ . '/' . `basename $dbpaths[$i]` );
                    113:            }
                    114:        $i++;
                    115:     }
                    116:
                    117:     $i--;
                    118:     $#dbids = $i;
                    119:     $#dbpaths = $i;
                    120:
                    121:     log::filelist(\@dbpaths);
                    122:
                    123:
                    124:     return( (\@dbids, \@dbpaths) );
                    125: }
                    126:
                    127:
                    128: return(1);

CVSweb