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

Annotation of wpscripts/zlist/zlist, Revision 1.1

1.1     ! yason       1: #!/usr/bin/perl
        !             2: # $Id: zlist.pl,v 1.3 2005/12/12 12:57:05 init Exp $
        !             3: use DBI;
        !             4: use Term::ANSIColor qw(:constants);
        !             5: use Time::HiRes qw(gettimeofday tv_interval);
        !             6:
        !             7: $| = 1;
        !             8:
        !             9: # database
        !            10: our $server = "MSSQL";
        !            11: our $user = "it_men";
        !            12: our $pass = "itmen712";
        !            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: {
        !            49:        if( -e "/var/log/ztransfer/FILE" && -e "/var/log/ztransfer/ACTION")
        !            50:        {
        !            51:            open(CURRENT, "/var/log/ztransfer/FILE");
        !            52:            my $file = <CURRENT>;
        !            53:            close(CURRENT);
        !            54:
        !            55:            open(CURRENT, "/var/log/ztransfer/ACTION");
        !            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 jpegs
        !            83:     db_fetch(1);
        !            84:
        !            85: #    print "****** jpegs ($#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:        # fetch probas
        !            98:        db_fetch(2);
        !            99:
        !           100: #      print "****** probas ($#numcard) ******\n";
        !           101:        print BOLD WHITE ON_BLUE "Очередь цветопроб". RESET . " ($#numcard штук) :\n";
        !           102:        $i = 0;
        !           103:        while( ($numcard[$i]) )
        !           104:        {
        !           105:            print "$numcard[$i]\t[ оформлено $time[$i],  приоритет=$pri[$i],  файл=$path[$i] (размер=$size[$i]) ]\n";
        !           106:            $i++;
        !           107:            $total++;
        !           108:        }
        !           109:        print "\n";
        !           110:
        !           111:
        !           112: # print summary information
        !           113: print BOLD WHITE . "Всего: " . RESET . "$total файлов в очереди на копирование в Заборье.\n";
        !           114:
        !           115: # close connection
        !           116: db_disconnect();
        !           117:
        !           118:
        !           119: ### database functions
        !           120:
        !           121: sub db_connect()
        !           122: {
        !           123:     $dbh = DBI->connect($dsn, $user, $pass) or die "unable to connect to server $DBI::errstr";
        !           124: }
        !           125:
        !           126:
        !           127: sub db_select()
        !           128: {
        !           129:     $dbh->do("use Manager");
        !           130: }
        !           131:
        !           132:
        !           133: sub db_fetch($)
        !           134: {
        !           135:     my $type_file = shift;
        !           136:     my $i = 0;
        !           137:     my $searchpath;
        !           138:
        !           139:     $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";
        !           140:     $sth->execute( ) or die "unable to execute query $query   error $DBI::errstr";
        !           141:
        !           142:     # zero elements
        !           143:     $#numcard = $#path = $#time = $#pri = $#tx_count = 0;
        !           144:
        !           145:     while( ($numcard[$i], $path[$i], $time[$i], $pri[$i], $tx_count[$i]) = $sth->fetchrow_array())
        !           146:     {
        !           147:        # truncate spaces
        !           148:        do
        !           149:        {
        !           150:            chop($path[$i]);
        !           151:        }
        !           152:        while( index($path[$i], ' ', 0) != -1 );
        !           153:
        !           154:        $searchpath = substr($path[$i], 23);
        !           155:
        !           156:        # hardcoded
        !           157:        $path[$i] = substr($path[$i], 30) if ($type_file == 0);
        !           158:        $path[$i] = substr($path[$i], 34) if ($type_file == 1);
        !           159:        $path[$i] = substr($path[$i], 34) if ($type_file == 2);
        !           160:
        !           161:            # make local file path
        !           162:            $searchpath =~ tr/\\/\//; $searchpath = '/WIDEPRINT/' . $searchpath;
        !           163:
        !           164:            # follow symlink to achieve real path
        !           165:            chomp( $_ = `dirname $searchpath | xargs /usr/bin/readlink` ); chomp( $searchpath = $_ . '/' . `basename $searchpath` );
        !           166:
        !           167:            # finally, get file size
        !           168:            $size[$i] = -s $searchpath;
        !           169:            $size[$i] = ($size[$i] > 1048576 ? int($size[$i] / 1024 / 1024) . " MB" : int($size[$i] / 1024) . " KB");
        !           170:
        !           171:            # this should work fine
        !           172:            $size[$i] = WHITE ON_RED . "файл не найден" . RESET if (! -e $searchpath);
        !           173:     $i++;
        !           174:     }
        !           175:
        !           176:     $sth->finish();
        !           177:
        !           178: }
        !           179:
        !           180:
        !           181: sub db_disconnect()
        !           182: {
        !           183:     $dbh->disconnect();
        !           184: }

CVSweb