Annotation of wpscripts/zlist/zlist, Revision 1.8
1.1 yason 1: #!/usr/bin/perl
1.8 ! yason 2: # $Id: zlist,v 1.7 2011/08/04 12:48:31 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:
1.7 yason 41: print GREEN "DB response time: " . tv_interval($time1, $time2) . " seconds\n". RESET;
1.1 yason 42:
43: if( ! -e "/var/run/ztransfer.lock")
44: {
1.7 yason 45: print YELLOW "ztransfer is not running\n" . RESET;
1.1 yason 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:
1.7 yason 62: print YELLOW "ztransfer is running [ " . ($action eq 'rar' ? "compressing " : "copying ") . "$file ]\n" . RESET;
1.1 yason 63: }
64: else
65: {
1.7 yason 66: print YELLOW "ztransfer is running\n" . RESET;
1.1 yason 67: }
68: }
69:
70: # print out zayavki info
1.7 yason 71: print BOLD WHITE ON_BLUE "Zayavki queue". RESET . " ($#numcard pcs.) :\n";
1.1 yason 72: $i = 0;
73: while( ($numcard[$i]) )
74: {
1.7 yason 75: print "$numcard[$i]\t[ executed $time[$i], priority=$pri[$i], file=$path[$i] (size=$size[$i]), transfer counter=$tx_count[$i] ]\n";
1.1 yason 76: $i++;
77: $total++;
78: }
79: print "\n";
80:
81:
1.8 ! yason 82: # fetch probas
! 83: db_fetch(1);
1.1 yason 84:
1.8 ! yason 85: #print "****** probas ($#numcard) ******\n";
! 86: print BOLD WHITE ON_BLUE "Probas queue". RESET . " ($#numcard pcs.) :\n";
1.1 yason 87: $i = 0;
88: while( ($numcard[$i]) )
89: {
1.7 yason 90: print "$numcard[$i]\t[ executed $time[$i], priority=$pri[$i], file=$path[$i] (size=$size[$i]) ]\n";
1.1 yason 91: $i++;
92: $total++;
93: }
1.8 ! yason 94: print "\n";
! 95:
! 96: # fetch TT
! 97: db_fetch(2);
! 98:
! 99: print BOLD WHITE ON_BLUE "TT queue". RESET . " ($#numcard pcs.) :\n";
! 100: $i = 0;
! 101: while( ($numcard[$i]) )
! 102: {
! 103: print "$numcard[$i]\t[ executed $time[$i], priority=$pri[$i], file=$path[$i] (size=$size[$i]) ]\n";
! 104: $i++;
! 105: $total++;
! 106: }
! 107: print "\n";
! 108:
! 109: # fetch jpeg
! 110: db_fetch(3);
! 111:
! 112: print BOLD WHITE ON_BLUE "jpeg queue". RESET . " ($#numcard pcs.) :\n";
! 113: $i = 0;
! 114: while( ($numcard[$i]) )
! 115: {
! 116: print "$numcard[$i]\t[ executed $time[$i], priority=$pri[$i], file=$path[$i] (size=$size[$i]) ]\n";
! 117: $i++;
! 118: $total++;
! 119: }
! 120: print "\n";
1.1 yason 121:
122:
123: # print summary information
1.7 yason 124: print BOLD WHITE . "Total: " . RESET . "$total files in queue.\n";
1.1 yason 125:
126: # close connection
127: db_disconnect();
128:
129:
130: ### database functions
131:
132: sub db_connect()
133: {
134: $dbh = DBI->connect($dsn, $user, $pass) or die "unable to connect to server $DBI::errstr";
135: }
136:
137:
138: sub db_select()
139: {
1.2 yason 140: $dbh->do("use full_print");
1.1 yason 141: }
142:
143:
144: sub db_fetch($)
145: {
146: my $type_file = shift;
147: my $i = 0;
148: my $searchpath;
149:
1.2 yason 150: $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 151: $sth->execute( ) or die "unable to execute query $query error $DBI::errstr";
152:
153: # zero elements
154: $#numcard = $#path = $#time = $#pri = $#tx_count = 0;
155:
156: while( ($numcard[$i], $path[$i], $time[$i], $pri[$i], $tx_count[$i]) = $sth->fetchrow_array())
157: {
158: # truncate spaces
159: do
160: {
161: chop($path[$i]);
162: }
163: while( index($path[$i], ' ', 0) != -1 );
164:
1.3 yason 165: # remove first 13 symbols in SMB path (\\fileserver\)
166: $searchpath = substr($path[$i], 13);
1.1 yason 167:
168: # hardcoded
1.6 yason 169: # remove first symbols to get only filename (i.e. \\fileserver\zayavki\ - 21 symbols)
170: $path[$i] = substr($path[$i], 21) if ($type_file == 0); #zayavki
171: $path[$i] = substr($path[$i], 19) if ($type_file == 1); #proba
1.8 ! yason 172: $path[$i] = substr($path[$i], 16) if ($type_file == 2); #TT
! 173: $path[$i] = substr($path[$i], 18) if ($type_file == 2); #jpeg
1.1 yason 174:
175: # make local file path
1.3 yason 176: $searchpath =~ tr/\\/\//;
1.4 yason 177: $searchpath = '/mnt/maket/' . $searchpath;
1.3 yason 178:
179:
1.1 yason 180: # finally, get file size
181: $size[$i] = -s $searchpath;
182: $size[$i] = ($size[$i] > 1048576 ? int($size[$i] / 1024 / 1024) . " MB" : int($size[$i] / 1024) . " KB");
183:
184: # this should work fine
1.7 yason 185: $size[$i] = WHITE ON_RED . "File not found" . RESET if (! -e $searchpath);
1.1 yason 186: $i++;
187: }
188:
189: $sth->finish();
190:
191: }
192:
193:
194: sub db_disconnect()
195: {
196: $dbh->disconnect();
197: }
CVSweb