![]() ![]() |
![]() |
File: [Development] / JSOC / base / util / scripts / dsview
(download)
Revision: 1.6, Tue Nov 19 19:52:19 2013 UTC (9 years, 6 months ago) by arta Branch: MAIN CVS Tags: Ver_LATEST, Ver_DRMSLATEST, Ver_9-5, Ver_9-41, Ver_9-4, Ver_9-3, Ver_9-2, Ver_9-1, Ver_9-0, Ver_8-8, Ver_8-7, Ver_8-6, Ver_8-5, Ver_8-4, Ver_8-3, Ver_8-2, Ver_8-12, Ver_8-11, Ver_8-10, NetDRMS_Ver_LATEST, NetDRMS_Ver_9-5, NetDRMS_Ver_9-41, NetDRMS_Ver_9-4, NetDRMS_Ver_9-3, NetDRMS_Ver_9-2, NetDRMS_Ver_9-1, NetDRMS_Ver_9-0, NetDRMS_Ver_8-8, NetDRMS_Ver_8-7, NetDRMS_Ver_8-6, NetDRMS_Ver_8-5, NetDRMS_Ver_8-4, NetDRMS_Ver_8-3, NetDRMS_Ver_8-2, NetDRMS_Ver_8-12, NetDRMS_Ver_8-11, NetDRMS_Ver_8-10, HEAD Changes since 1.5: +6 -3 lines Mods so that these scripts will use the localized parameters for the database hosts/names/etc. |
eval 'exec /home/jsoc/bin/$JSOC_MACHINE/perl -S $0 "$@"' if 0; # #/home/jim/cvs/JSOC/base/util/scripts/dsview #Perl/Tk gui to view DRMS series tables. # # #use lib ("/usr/lib/perl5/site_perl/5.8.5","/home/jim/perl_tk_800.023.xim/lib/perl5/site_perl/5.8.5"); #use lib ("/home/jim/perl_tk_800.023.xim/lib/perl5/site_perl/5.8.5"); use Tk; use DBI; use FindBin qw($RealBin); use lib "$RealBin/../../../localization"; use drmsparams; #use Config; #$archname = $Config{'archname'}; #print "arch = $archname\n"; sub usage { exit; } $DEFAULTDB = drmsparams::DBNAME; #default DB $DBSUMS = $DEFAULTDB . "_sums"; $HOSTDB = drmsparams::SUMS_DB_HOST; #host where DB runs $PGPORT = 5434; #for connection with jsoc_sum db $IMGDIR = "/home/jsoc/gallery"; #dir with the .gif files $INLOG = 0; #use default tape_svc log $nsel = 200; #number of records at a time to fetch $pid0 = 0; $ldate = &labeldate(); $user = $ENV{'USER'}; while ($ARGV[0] =~ /^-/) { $_ = shift; if (/^-l(.*)/) { $INLOG = $1; } elsif (/^-p(.*)/) { $playback = 1; } elsif (/^-h(.*)/) { $helpflg = 1; } elsif (/^-i(.*)/) { $interactive = 1; } else { &usage; } } if($#ARGV == 0) { $DB = $ARGV[0]; } else { $DB = $DEFAULTDB; } if($helpflg) { &usage; } $hostdb = $HOSTDB; #host where Postgres runs $UID = $<; #get real user id #$runtag = "/tmp/t120view_$UID.tag"; #if(-e $runtag) { #this user already running # print "Already found a $runtag\n"; # print "Only one instance of t120view allowed for a user\n"; # print "If not so do: /bin/rm $runtag\n"; # exit(1); #} $ext = "$user"."_$ldate"; #$log = "/usr/local/logs/SUM/dsview_$ext.log"; $log = "/tmp/dsview_$ext.log"; open(LOG, ">$log") || die "Can't open $log: $!\n"; select(LOG); $| = 1; select(STDOUT); #make unbuffered print LOG "$ldate $log\n\n"; my(@pl) = qw/-side top -anchor nw/; my(@pl1) = qw/-side left/; my(@pl2) = qw/-side top -pady 1.0m/; #First connect to database $dbh = DBI->connect("dbi:Pg:dbname=$DB;host=$hostdb", "$user", "$password"); if ( !defined $dbh ) { die "Cannot do \$dbh->connect: $DBI::errstr\n"; } #system "touch $runtag"; #offically started running now $date = &get_effdate; #print "effdate = $date\n"; $mw = MainWindow->new; #$mw->geometry("780x470+1+1"); $mw->geometry("780x570+1+1"); $mw->title("dsview"); $tframe = $mw->Frame(-borderwidth => 1)->pack(-side => 'top'); $image = $tframe->Photo(-file => "$IMGDIR/SDO_Badge.gif"); $tframe->Label(-image => $image)->pack(-side => 'left'); $tframe->Label(-text => "DRMS Series Viewer (dsview)\ndatabase=$DB", -font => 'arial 18 bold', -padx => 100)->pack(-side => 'left'); $b = $tframe->Button( -text => 'Exit', -background => 'red', -command => \&Exit_sub, ); $b->pack(-side=> 'left', -pady => 0); $tframe1 = $mw->Frame(-borderwidth => 1)->pack(-side => 'top'); $tframe1->Label(-text => 'Note: you must have a $HOME/.pgpass file', -font => 'arial 18 italic')->pack(-side => 'top'); $image = $tframe1->Photo(-file => "$IMGDIR/GRAD_BLUE_LINE.gif"); $tframe1->Label(-image => $image)->pack(-side => 'top'); $tframe1->Label(-text => 'Select DRMS Series:', -font => 'arial 14 bold', -pady => 10)->pack(-side => 'top'); #$sqlcmd = "select seriesname from drms_series"; $sqlcmd = "select seriesname from drms_series() where seriesname not like 'dsds.%' order by seriesname"; #print "sqlcmd is: $sqlcmd\n\n"; #!!TEMP $sth = $dbh->prepare($sqlcmd); if ( !defined $sth ) { print "Cannot prepare statement: $DBI::errstr\n"; #system "/bin/rm $runtag"; exit; } # Execute the statement at the database level $sth->execute; @listbox_items = (); while($result = $sth->fetchrow()) { #get row from the DB push(@listbox_items, $result); } $showb = $tframe1->Button(-text => "Show 'dsds.'\nnamespace", -command => \&Show_dsds,) ->pack(-side=> 'left'); $lb = $tframe1->Scrolled("Listbox", -scrollbars => "w", -width => 40, -font => 'arial 14 bold', -height => 400, -selectmode => "single")->pack(-side => 'top', -pady => 10); $lb->insert('end', @listbox_items); $lb->bind('<Button-1>', \&lb_sub); $sth->finish(); # $bsubmit = $tframe1->Button( # -text => 'Submit', # -background => 'grey', # -command => \&dtable_sub, # ); # $bsubmit->pack(-side=> 'top'); MainLoop; ########################################################################### sub lb_sub { if(Exists($dtabf)) { $dtabf->destroy(); } if(Exists($queryf)) { $queryf->destroy(); } $ds = $lb->get($lb->curselection( )); @schema = `echo "\\d $ds" | psql -h $hostdb $DB`; $queryf = $mw->Toplevel(); #$queryf->geometry("500x330+5+500"); $queryf->geometry("500x330+5+601"); $queryf->title("dsview - $ds"); # my $yf = $queryf->Frame(-borderwidth => 0) # ->pack(-fill => 'both', -side => 'top'); $queryf->Label(-text => "Previous Next First Last") ->pack(-side => 'top'); # $yf->Label(-text => " Next ")->pack(@pl1); # $yf->Label(-text => " First ")->pack(@pl1); # $yf->Label(-text => " Last")->pack(@pl1); $xyf = $queryf->Frame(-borderwidth => 0) ->pack(-fill => 'both', -side => 'top'); $xyf->Label(-text => " Fetch next n:", -anchor => 'e', -justify => 'right')->pack(-side=> 'left', -padx => 4); $image = $xyf->Photo(-file => "$IMGDIR/arrow04.gif"); $xyf->Button(-command => \&Previous, -image => $image) ->pack(-side=> 'left', -padx => 10); $image = $xyf->Photo(-file => "$IMGDIR/arrow05.gif"); $xyf->Button(-command => \&Next, -image => $image) ->pack(-side=> 'left', -padx => 10); $image = $xyf->Photo(-file => "$IMGDIR/arrow06.gif"); $xyf->Button(-command => \&First, -image => $image) ->pack(-side=> 'left', -padx => 10); $image = $xyf->Photo(-file => "$IMGDIR/arrow03.gif"); $xyf->Button(-command => \&Last, -image => $image) ->pack(-side=> 'left', -padx => 10); $yyf = $queryf->Frame(-borderwidth => 0) ->pack(-fill => 'both', -side => 'top', -pady => 20); $yyf->Label(-text => 'Fetch n records at a time:') ->pack(-side => 'left'); $yyf->Entry(-textvariable => \$nsel, -width => 6, -font=>'arial 12 bold') ->pack(-side=>'left'); $yyf->Label(-text => 'Goto recnum:') ->pack(-side => 'left', -padx => 5); $yyf->Entry(-textvariable => \$gotorecnum,-width => 8,-font=>'arial 12 bold') ->pack(-side=>'left'); $yyf->Button(-text => "Go", -command => \&Recnum_go,) ->pack(-side=> 'left'); $zyf = $queryf->Frame(-borderwidth => 0) ->pack(-fill => 'both', -side => 'top', -pady => 10); $zyf->Label(-text => 'SQL or psql cmd (\h shows sql cmds, \? shows psql)') ->pack(-side => 'top'); $zyf->Label(-text => 'NOTE: a ";" will terminate the cmd and execute, or use Execute button') ->pack(-side => 'top'); $zyf->Entry(-textvariable => \$sqlc, -width => 60, -font=>'arial 12 bold', -validate => 'key', -validatecommand => \&Sql_ck) ->pack(-side=>'top'); $ayf = $queryf->Frame(-borderwidth => 0) ->pack(-fill => 'both', -side => 'top', -pady => 5); $ayf->Button(-text => "Execute", -command => \&Execute,) ->pack(-side=> 'left'); $byf = $queryf->Frame(-borderwidth => 0) ->pack(-fill => 'both', -side => 'top', -pady => 5); $byf->Label(-text => 'Query sum_main for sunum =') ->pack(-side => 'left'); $byf->Entry(-textvariable => \$summainc, -width => 10, -font=>'arial 12 bold', -validate => 'key', -validatecommand => \&Sum_ck) ->pack(-side=>'left'); $byf->Button(-text => "Go", -command => \&Sum_go,) ->pack(-side=> 'left'); $queryf->bind('all', '<Control-c>' => \&exit); $dtabf = $mw->Toplevel(); $dtabf->geometry("700x560+540+140"); $dtabf->title("dsview - $ds"); $text = $dtabf->Scrolled("Text", -scrollbars => "w", -height => 20) ->pack(-side => 'top', -fill => 'both'); while(my $x = shift(@schema)) { $text->insert('end', $x); } $sqlcmd = "select min(recnum) from $ds"; $sth = $dbh->prepare($sqlcmd); if ( !defined $sth ) { print "Cannot prepare statement: $DBI::errstr\n"; #system "/bin/rm $runtag"; exit; } # Execute the statement at the database level $sth->execute; $first = $sth->fetchrow_array(); if(!$first) { $first = 1; } $sqlcmd = "select * from $ds where recnum >= $first and recnum < $first+$nsel"; #$sqlcmd = "select * from $ds where recnum >= 1 and recnum <= $nsel"; $nselnext = ($first+$nsel) - 1; $nselprev = $first-1; #print "sqlcmd is: $sqlcmd\n\n"; #!!TEMP $text1 = $dtabf->Scrolled("Text", -height => 20, -wrap => 'none') ->pack(-side => 'top', -fill => 'both'); @schema = `echo "$sqlcmd" | psql -h $hostdb $DB`; while(my $x = shift(@schema)) { $text1->insert('end', $x); $none = 0; } $sth->finish(); } sub Text1_sub { $tline = $text1->get($lb->curselection( )); print "tline = $tline\n"; } sub Sql_ck { if($_[1] eq ';') { &Execute; } return(1); } sub Sum_ck { if($_[1] eq ';') { &Sum_go; } return(1); } sub Recnum_go { $nselnext = ($gotorecnum - 1); &Next; return(1); } sub Show_dsds { $sqlcmd = "select seriesname from drms_series() where seriesname like 'dsds.%' order by seriesname"; $sth = $dbh->prepare($sqlcmd); if ( !defined $sth ) { print "Cannot prepare statement: $DBI::errstr\n"; #system "/bin/rm $runtag"; exit; } # Execute the statement at the database level $sth->execute; @listbox_items = (); while($result = $sth->fetchrow()) { #get row from the DB push(@listbox_items, $result); } $showb->configure(-text => "Show non 'dsds.'\nnamespace", -command => \&Show_non_dsds,); $lb->delete(0, 'end'); $lb->insert('end', @listbox_items); $lb->bind('<Button-1>', \&lb_sub); $sth->finish(); return(1); } sub Show_non_dsds { $sqlcmd = "select seriesname from drms_series() where seriesname not like 'dsds.%' order by seriesname"; $sth = $dbh->prepare($sqlcmd); if ( !defined $sth ) { print "Cannot prepare statement: $DBI::errstr\n"; #system "/bin/rm $runtag"; exit; } # Execute the statement at the database level $sth->execute; @listbox_items = (); while($result = $sth->fetchrow()) { #get row from the DB push(@listbox_items, $result); } $showb->configure(-text => "Show 'dsds.'\nnamespace", -command => \&Show_dsds,); $lb->delete(0, 'end'); $lb->insert('end', @listbox_items); $lb->bind('<Button-1>', \&lb_sub); $sth->finish(); return(1); } sub Sum_go { if(Exists($dtabg)) { $dtabg->destroy(); } $sumsql = "select * from sum_main where ds_index=$summainc"; #print "sumsql = $sumsql\n"; @schema = `echo "$sumsql" | psql -h $hostdb -p $PGPORT $DBSUMS`; $dtabg = $mw->Toplevel(); $dtabg->geometry("700x100+540+726"); $dtabg->title("dsview - $ds"); $text2 = $dtabg->Scrolled("Text", -height => 10, -wrap => 'none') ->pack(-side => 'top', -fill => 'both'); while(my $x = shift(@schema)) { $text2->insert('end', $x); if($x =~ /\/SUM/) { ($dir, $y) = split(/\|/, $x); if(Exists($cyf)) { $cyf->destroy(); } $cyf = $queryf->Frame(-borderwidth => 0) ->pack(-fill => 'both', -side => 'top', -pady => 5); #$cyf->Label(-text => "dir is $dir") ->pack(-side => 'left'); $cyf->Button(-text => "ls -lR $dir", -command => \&List_go,) ->pack(-side=> 'left'); } } } sub List_go { $dtabh = $mw->Toplevel(); $dtabh->geometry("600x250+590+118"); $dtabh->title("dsview - $dir"); $text3 = $dtabh->Scrolled("Text", -height => 50, -wrap => 'none', -background => 'white') ->pack(-side => 'top', -fill => 'both'); @list = `ls -lR $dir`; while($x = shift(@list)) { $text3->insert('end', $x); } } sub Execute { #print "sqlcmd = $sqlc\n"; @schema = `echo "$sqlc" | psql -h $hostdb $DB`; $text1->delete("1.0", 'end'); while(my $x = shift(@schema)) { $text1->insert('end', $x); } } sub Previous { my $next = $nselprev-$nsel; if($next < 1) { $next = 0; } $sqlcmd = "select * from $ds where recnum > $next and recnum <= $next+$nsel"; $nselnext = $next + $nsel; $nselprev = $next; @schema = `echo "$sqlcmd" | psql -h $hostdb $DB`; $text1->delete("1.0", 'end'); while(my $x = shift(@schema)) { $text1->insert('end', $x); } } sub Next { $sqlcmd = "select * from $ds where recnum > $nselnext and recnum <= $nselnext+$nsel"; $nselprev = $nselnext; $nselnext = $nselnext + $nsel; @schema = `echo "$sqlcmd" | psql -h $hostdb $DB`; $text1->delete("1.0", 'end'); while(my $x = shift(@schema)) { $text1->insert('end', $x); } } sub First { $sqlcmd = "select min(recnum) from $ds"; $sth = $dbh->prepare($sqlcmd); if ( !defined $sth ) { print "Cannot prepare statement: $DBI::errstr\n"; #system "/bin/rm $runtag"; exit; } # Execute the statement at the database level $sth->execute; $first = $sth->fetchrow_array(); if(!$first) { $first = 1; } $sqlcmd = "select * from $ds where recnum >= $first and recnum < $first+$nsel"; $nselnext = ($first+$nsel) - 1; $nselprev = $first-1; @schema = `echo "$sqlcmd" | psql -h $hostdb $DB`; $text1->delete("1.0", 'end'); while(my $x = shift(@schema)) { $text1->insert('end', $x); } $sth->finish(); } sub Last { $sqlcmd = "select max(recnum) from $ds"; $sth = $dbh->prepare($sqlcmd); if ( !defined $sth ) { print "Cannot prepare statement: $DBI::errstr\n"; #system "/bin/rm $runtag"; exit; } # Execute the statement at the database level $sth->execute; $last = $sth->fetchrow_array(); if(!$last) { $last = 1; } #print "last = $last\n"; $sqlcmd = "select * from $ds where recnum > $last-$nsel and recnum <= $last"; #print "sqlcmd = $sqlcmd\n"; $nselnext = $last; $nselprev = $last-$nsel; @schema = `echo "$sqlcmd" | psql -h $hostdb $DB`; $text1->delete("1.0", 'end'); while(my $x = shift(@schema)) { $text1->insert('end', $x); } $sth->finish(); } #Return effective date of now as yyyymmddhhmm sub get_effdate { local($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$date,$sec2,$min2,$hour2,$mday2); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $min2 = sprintf("%02d", $min); $hour2 = sprintf("%02d", $hour); $mday2 = sprintf("%02d", $mday); $mon2 = sprintf("%02d", $mon+1); $year4 = sprintf("%04d", $year+1900); $date = "$year4"."$mon2"."$mday2"."$hour2"."$min2"; return($date); } #Return date in form for a label e.g. 1998.01.07_14:42:00 sub labeldate { local($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$date,$sec2,$min2,$hour2,$mday2); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $sec2 = sprintf("%02d", $sec); $min2 = sprintf("%02d", $min); $hour2 = sprintf("%02d", $hour); $mday2 = sprintf("%02d", $mday); $mon2 = sprintf("%02d", $mon+1); $year4 = sprintf("%04d", $year+1900); $date = $year4.".".$mon2.".".$mday2._.$hour2.":".$min2.":".$sec2; return($date); } #Return time in form for a label e.g. 14:42:00 sub labeltime { my $d = &labeldate; my $pos = index($d, '_'); my $t = substr($d, $pos+1); return($t); } sub Exit_sub { $dbh->disconnect(); if($pid0) { #kill off our child `kill $pid0`; } #system "/bin/rm $runtag"; exit; } sub commify { my $text = reverse $_[0]; $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; return scalar reverse $text; }
Karen Tian |
Powered by ViewCVS 0.9.4 |