From: Tim Pope Date: Tue, 28 Feb 2006 20:00:03 +0000 (+0000) Subject: New hostnames X-Git-Url: http://git.tpope.net/?p=tpope-extra.git;a=commitdiff_plain;h=9a364f4fe90ef0f1a521ec4ab73132428d97bcfd New hostnames --- diff --git a/perl/away-tpope b/perl/away-tpope index 38ce70d..c5bf12c 100755 --- a/perl/away-tpope +++ b/perl/away-tpope @@ -4,7 +4,7 @@ use strict; use vars qw(%state @ssh $last $pipe $arg $slow); -@ssh=("ssh","-a","-x","-oBatchmode=yes","-oSetupTimeOut=20"); +@ssh=("ssh","-a","-x","-oBatchmode=yes","-oSetupTimeOut=20","-qq"); $pipe = "/tmp/.away-tpope"; $arg=shift || ""; @@ -107,6 +107,7 @@ sub cycle { do_phone(); $slow=0; } + eval_chat(); do_schedule(); do_decision(); save(); @@ -138,13 +139,16 @@ sub do_schedule { next unless /(\d\d):(\d\d)-(\d\d):(\d\d) (.*)/; my ($hs,$ms,$he,$me,$ev) = ($1, $2, $3, $4, $5); $ev =~ s/ *\[.*$//; - $begin = $hs*60+$ms-25; + $begin = $hs*60+$ms-10; $maxend = $he*60+$me+10; - $end = ($begin+25)*3/4+($maxend-10)/4; + $end = ($begin+10)*3/4+($maxend-10)/4; if($begin <= $now && $now < $end) { $state{'class'} = $ev; + internal_out("School"); $familiar = 1; last; + } elsif($begin-35<=$now && $now<$end && $state{'phone'} eq "absent") { + internal_out("School"); } elsif (($state{'class'}||'') eq $ev) { $familiar = 1; undef $state{'class'} @@ -154,7 +158,6 @@ sub do_schedule { close(SCHEDULE); undef $state{'class'} unless ($familiar); - open(SCHEDULE, "today --category='!school !private'|"); $familiar = 0; while() { @@ -191,8 +194,18 @@ sub do_chat { } } +sub eval_chat { + if(($state{'chat'}||'') eq "jmwaller") { + internal_out("Work",3*60*60); + } elsif(($state{'chat'}||'') =~ /^tpope-\d+$/) { + internal_out("Work",3*60*60); + } elsif(($state{'chat'}||'') eq "accd") { + #internal_out("School",30*60); + } +} + sub do_hosts { - my (@check) = ("mona", "lisa", "homer", "sarah"); + my (@check) = ("tobias", "lucille", "lindsay", "buster"); my (@uphosts, @livehosts, $host, $hostlist); if(($_[0] || 0) == 1) { $hostlist=$state{'hosts'}; @@ -232,7 +245,7 @@ sub is_alive { eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm(30); - $ret=!(system(@ssh,shift, 'if pidof xscreensaver >/dev/null && DISPLAY=:0.0 xscreensaver-command -version >/dev/null 2>&1; then if DISPLAY=:0.0 xscreensaver-command -time 2>&1 |egrep "non-blanked|no saver status" >/dev/null; then true; else pid=`ps ax|egrep "[0-9]:[0-9][0-9] ssh marge .*(screen.*RR irc|Chat)"|sed -e "s/^ *//"|cut -d" " -f 1`; [ -f "$HOME/.irc.lock" -o -z "$pid" ] || kill $pid; false; fi; else false; fi') >> 8); + $ret=!(system(@ssh,shift, 'if pidof xscreensaver >/dev/null && DISPLAY=:0.0 xscreensaver-command -version >/dev/null 2>&1; then if DISPLAY=:0.0 xscreensaver-command -time 2>&1 |egrep "non-blanked|no saver status" >/dev/null; then true; else pid=`ps ax|egrep "[0-9]:[0-9][0-9] ssh michael .*(screen.*RR irc|Chat)"|sed -e "s/^ *//"|cut -d" " -f 1`; [ -f "$HOME/.irc.lock" -o -z "$pid" ] || kill $pid; false; fi; else false; fi') >> 8); alarm(0); }; if($@) { @@ -244,10 +257,10 @@ sub is_alive { sub do_phone { my $phone; - if(!ping('mona')) { + if(!ping('tobias')) { $phone="unknown"; } else { - my $last_slh=`@ssh mona cat .blue/last_slh 2>/dev/null`; + my $last_slh=`@ssh tobias cat .blue/last_slh 2>/dev/null`; if(!$last_slh) { $phone="unknown"; } elsif (time-$last_slh < 540) { @@ -256,14 +269,15 @@ sub do_phone { $phone="absent"; } } - if($state{'phone'} ne 'present' && $phone eq 'present') { + if(($state{'phone'}||"") ne 'present' && $phone eq 'present') { custom_out(""); + internal_out(""); } $state{'phone'} = $phone; } sub do_power { - open TMP, "upsc milhouse\@localhost|"; + open TMP, "upsc milhouse\@localhost 2>/dev/null|"; my $ups=''; while() { chomp; @@ -280,9 +294,11 @@ sub do_decision { if ($state{'customawayexp'} && $state{'customawayexp'}' . $ENV{'HOME'} . "/.away-tpope" || die $!; @@ -416,6 +446,10 @@ sub save { sub load { open CONF, '<' . $ENV{'HOME'} . "/.away-tpope" or return; + undef $state{'customactivity'}; + undef $state{'customaway'}; + undef $state{'customout'}; + undef $state{'internalout'}; while(my $line=) { $line =~ s/\\n/\n/g; $line =~ s/\\"/"/g;