[BACK]Return to zlist CVS log [TXT][DIR] Up to [local] / wpscripts / zlist

Annotation of wpscripts/zlist/zlist, Revision 1.2

1.1       yason       1: #!/usr/bin/perl
1.2     ! yason       2: # $Id: zlist,v 1.1.1.1 2011/06/03 09:28:47 yason Exp $
1.1       yason       3: use DBI;
                      4: use Term::ANSIColor qw(:constants);
                      5: use Time::HiRes qw(gettimeofday tv_interval);
                      6:
                      7: $| = 1;
                      8:
                      9: # database
1.2     ! yason      10: our $server = "pdc";
        !            11: our $user = "sa";
        !            12: our $pass = "aekghbynflvby";
1.1       yason      13: our $dsn = "DBI:Sybase:server=$server";
                     14: our $sth;
                     15:
                     16: # response handlers
                     17: our @numcard;
                     18: our @time;
                     19: our @pri;
                     20: our @path;
                     21: our @size;
                     22: our @tx_count;
                     23:
                     24: my $i; # counter
                     25: my $total = 0; # total files
                     26:
                     27: ###
                     28: my $time1 = [gettimeofday];
                     29:
                     30: # connect to database server
                     31: db_connect();
                     32:
                     33: # select database
                     34: db_select();
                     35:
                     36: # fetch zayavki
                     37: db_fetch(0);
                     38:
                     39: my $time2 = [gettimeofday];
                     40:
                     41: print GREEN "Время отклика от базы данных: " . tv_interval($time1, $time2) . " секунд\n". RESET;
                     42:
                     43: if( ! -e "/var/run/ztransfer.lock")
                     44: {
                     45:        print YELLOW "ztransfer сейчас не запущен\n" . RESET;
                     46: }
                     47: else
                     48: {
1.2     ! yason      49:        if( -e "/var/log/wpscripts/ztransfer/FILE" && -e "/var/log/ztransfer/ACTION")
1.1       yason      50:        {
1.2     ! yason      51:            open(CURRENT, "/var/log/wpscripts/ztransfer/FILE");
1.1       yason      52:            my $file = <CURRENT>;
                     53:            close(CURRENT);
                     54:
1.2     ! yason      55:            open(CURRENT, "/var/log/wpscripts/ztransfer/ACTION");
1.1       yason      56:            my $action = <CURRENT>;
                     57:            close(CURRENT);
                     58:
                     59:
                     60:            print "DEBUG: $file $action\n";
                     61:
                     62:            print YELLOW "ztransfer выполняется [ " . ($action eq 'rar' ? "сжимается " : "копируется ") . "$file ]\n" . RESET;
                     63:        }
                     64:        else
                     65:        {
                     66:            print YELLOW "ztransfer выполняется\n" . RESET;
                     67:        }
                     68: }
                     69:
                     70: # print out zayavki info
                     71: print BOLD WHITE ON_BLUE "Очередь заявок". RESET . " ($#numcard штук) :\n";
                     72:     $i = 0;
                     73:     while( ($numcard[$i]) )
                     74:     {
                     75:        print "$numcard[$i]\t[ оформлено $time[$i],  приоритет=$pri[$i],  файл=$path[$i] (размер=$size[$i]), счётчик передач=$tx_count[$i] ]\n";
                     76:        $i++;
                     77:        $total++;
                     78:     }
                     79: print "\n";
                     80:
                     81:
                     82:        # fetch probas
                     83:        db_fetch(2);
                     84:
                     85: #      print "****** probas ($#numcard) ******\n";
                     86:        print BOLD WHITE ON_BLUE "Очередь цветопроб". RESET . " ($#numcard штук) :\n";
                     87:        $i = 0;
                     88:        while( ($numcard[$i]) )
                     89:        {
                     90:            print "$numcard[$i]\t[ оформлено $time[$i],  приоритет=$pri[$i],  файл=$path[$i] (размер=$size[$i]) ]\n";
                     91:            $i++;
                     92:            $total++;
                     93:        }
                     94:        print "\n";
                     95:
                     96:
                     97: # print summary information
                     98: print BOLD WHITE . "Всего: " . RESET . "$total файлов в очереди на копирование в Заборье.\n";
                     99:
                    100: # close connection
                    101: db_disconnect();
                    102:
                    103:
                    104: ### database functions
                    105:
                    106: sub db_connect()
                    107: {
                    108:     $dbh = DBI->connect($dsn, $user, $pass) or die "unable to connect to server $DBI::errstr";
                    109: }
                    110:
                    111:
                    112: sub db_select()
                    113: {
1.2     ! yason     114:     $dbh->do("use full_print");
1.1       yason     115: }
                    116:
                    117:
                    118: sub db_fetch($)
                    119: {
                    120:     my $type_file = shift;
                    121:     my $i = 0;
                    122:     my $searchpath;
                    123:
1.2     ! yason     124:     $sth = $dbh->prepare ("SELECT numcard,path,time_file,file_priority,tx_count FROM upload_files WHERE status=0 AND type_file=$type_file") or die "SQL prepare failed\n";
1.1       yason     125:     $sth->execute( ) or die "unable to execute query $query   error $DBI::errstr";
                    126:
                    127:     # zero elements
                    128:     $#numcard = $#path = $#time = $#pri = $#tx_count = 0;
                    129:
                    130:     while( ($numcard[$i], $path[$i], $time[$i], $pri[$i], $tx_count[$i]) = $sth->fetchrow_array())
                    131:     {
                    132:        # truncate spaces
                    133:        do
                    134:        {
                    135:            chop($path[$i]);
                    136:        }
                    137:        while( index($path[$i], ' ', 0) != -1 );
                    138:
                    139:        $searchpath = substr($path[$i], 23);
                    140:
                    141:        # hardcoded
                    142:        $path[$i] = substr($path[$i], 30) if ($type_file == 0);
                    143:        $path[$i] = substr($path[$i], 34) if ($type_file == 1);
                    144:        $path[$i] = substr($path[$i], 34) if ($type_file == 2);
                    145:
                    146:            # make local file path
                    147:            $searchpath =~ tr/\\/\//; $searchpath = '/WIDEPRINT/' . $searchpath;
                    148:
1.2     ! yason     149: #          # follow symlink to achieve real path
        !           150: #          chomp( $_ = `dirname $searchpath | xargs /usr/bin/readlink` ); chomp( $searchpath = $_ . '/' . `basename $searchpath` );
1.1       yason     151:
                    152:            # finally, get file size
                    153:            $size[$i] = -s $searchpath;
                    154:            $size[$i] = ($size[$i] > 1048576 ? int($size[$i] / 1024 / 1024) . " MB" : int($size[$i] / 1024) . " KB");
                    155:
                    156:            # this should work fine
                    157:            $size[$i] = WHITE ON_RED . "файл не найден" . RESET if (! -e $searchpath);
                    158:     $i++;
                    159:     }
                    160:
                    161:     $sth->finish();
                    162:
                    163: }
                    164:
                    165:
                    166: sub db_disconnect()
                    167: {
                    168:     $dbh->disconnect();
                    169: }

CVSweb