Merge branch 'master' of git+ssh://github.com/adefaria/clearscm
authorAndrew DeFaria <Andrew@DeFaria.com>
Wed, 5 May 2021 17:51:09 +0000 (10:51 -0700)
committerAndrew DeFaria <Andrew@DeFaria.com>
Wed, 5 May 2021 17:51:09 +0000 (10:51 -0700)
.project
.pydevproject [deleted file]
bin/announceEmail [new file with mode: 0755]
bin/announceEmail.pl
bin/monitorXScreenSaver.pl [new file with mode: 0755]
etc/cleantmp.conf
lib/Clearcase.pm
lib/Speak.pm
lib/Utils.pm

index 170c616..31a0006 100644 (file)
--- a/.project
+++ b/.project
@@ -18,6 +18,5 @@
        </buildSpec>
        <natures>
                <nature>org.epic.perleditor.perlnature</nature>
-               <nature>org.python.pydev.pythonNature</nature>
        </natures>
 </projectDescription>
diff --git a/.pydevproject b/.pydevproject
deleted file mode 100644 (file)
index 40e9f40..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<?eclipse-pydev version="1.0"?><pydev_project>
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
-</pydev_project>
diff --git a/bin/announceEmail b/bin/announceEmail
new file mode 100755 (executable)
index 0000000..deab422
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/bash
+case $1 in
+  post)
+    # If we send the USR2 signal before the network comes back up then 
+    # announceEmail.pl will die trying to re-establish its connection to the
+    # IMAP server. So instead we use this cheap method of sleeping for a minute
+    # as the network should be back by then. A better method would be to poll
+    # looking for the network to come back up but that's tricker to implement.
+    sleep 60
+    killall -USR2 announceEmail.pl
+    ;;
+esac
index 2826ed3..d21003b 100755 (executable)
@@ -42,7 +42,7 @@ $Date: 2019/04/04 13:40:10 $
    -h|elp        Detailed help
    -v|erbose     Verbose mode (Default: -verbose)
    -de|bug       Turn on debugging (Default: Off)
+
    -user|name    User name to log in with (Default: $USER)
    -p|assword    Password to use (Default: prompted)
    -i|map        IMAP server to talk to (Default: defaria.com)
@@ -54,6 +54,10 @@ $Date: 2019/04/04 13:40:10 $
    -uses|sl      Whether or not to use SSL to connect (Default: False)
    -useb|locking Whether to block on socket (Default: False)
 
+ Signals:
+   $SIG{USR1}:   Toggles debug option
+   $SIG{USR2}:   Reestablishes connection to IMAP server
+
 =head1 DESCRIPTION
 
 This script will connect to an IMAP server, login and then monitor the user's
@@ -98,6 +102,7 @@ my @greetings = (
   'I was looking in your inbox and found a message',
   'Not sure you want to hear this message',
   'Good news',
+  "What's this? A new message",
 );
 
 my %opts = (
@@ -123,7 +128,17 @@ sub interrupted {
   return;
 } # interrupted
 
+sub Connect2IMAP;
+
+sub restart {
+  $log->dbug("Re-establishing connection to $opts{imap} as $opts{username}");
+  Connect2IMAP;
+
+  goto MONITORMAIL;
+} # restart
+
 $SIG{USR1} = \&interrupted;
+$SIG{USR2} = \&restart;
 
 sub unseenMsgs() {
   $IMAP->select('inbox') or
@@ -135,6 +150,9 @@ sub unseenMsgs() {
 sub Connect2IMAP() {
   $log->dbug("Connecting to $opts{imap} as $opts{username}");
 
+  # Destroy any old connections
+  undef $IMAP;
+
   $IMAP = Mail::IMAPTalk->new(
     Server      => $opts{imap},
     Username    => $opts{username},
@@ -236,27 +254,9 @@ sub MonitorMail() {
   # If we return from idle then the server went away for some reason. With Gmail
   # the server seems to time out around 30-40 minutes. Here we simply reconnect
   # to the imap server and continue to MonitorMail.
-  $log->dbug("MonitorMail: Connection to $opts{imap} ended - lasted "
-           . howlong $startTime);
-
-  # Destroy current IMAP connection
-  $log->dbug("MonitorMail: Destroying IMAP connection to $opts{imap}");
+  restart;
 
-  undef $IMAP;
-
-  # Re-establish connection
-  Connect2IMAP;
-
-  $log->dbug("MonitorMail: Reconnected to IMAP server $opts{imap}");
-
-  # MonitorMail again - the dreaded goto! Seems the cleanest way to restart
-  # in this instance. I could call MonitorMail() recursively but that would
-  # leave junk on the stack.
-  $log->dbug('MonitorMail: Going back to the top of the loop');
-
-  goto MONITORMAIL;
-
-  return; # To make perlcritic happy
+  return;
 } # MonitorMail
 
 END {
diff --git a/bin/monitorXScreenSaver.pl b/bin/monitorXScreenSaver.pl
new file mode 100755 (executable)
index 0000000..01180fd
--- /dev/null
@@ -0,0 +1,147 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+=pod
+
+=head1 NAME $RCSfile: monitorXScreenSaver.pl,v $
+
+Monitor xscreensaver and forcefully turn off screens when blanked. Note I had a
+problem before where the screens wouled unblank and not go into powersave mode.
+I think my new system doesn't have this problem anymore but I still run this.
+
+I'd like to augment this so that after blanking of the screen and some time
+thereafter the system would suspend. Suspending the system doesn't always work
+well. It doesn't work well on my MacBook running Ubuntu but it does seem to work
+OK on my Thelio Desktop from System76. But I have not implemented this yet.
+
+=head1 VERSION
+
+=over
+
+=item Author
+
+Andrew DeFaria <Andrew@DeFaria.com>
+
+=item Revision
+
+$Revision: 1.0 $
+
+=item Created:
+
+Fri 09 Apr 2021 10:50:28 AM PDT
+
+=item Modified:
+
+$Date: $
+
+=back
+
+=head1 SYNOPSIS
+
+ Usage: monitorXscreenSaver.pl [-u|sage] [-h|elp] [-v|erbose] [-de|bug]
+                               [-[no]da|emon] [-l|ogpath]
+
+ Where:
+   -u|sage           Print this usage
+   -h|elp            Detailed help
+   -v|erbose:        Verbose mode
+   -d|ebug:          Print debug messages
+   -l|ogpath <path>: Path to logfile (Default: /var/local/log)
+   -da|emon          Run in daemon mode (Default: -daemon)
+
+=head1 DESCRIPTION
+
+This script will monitor the xscreensaver process and forcefully powersave the
+monitors when blanked.
+
+=cut
+
+use FindBin;
+use Getopt::Long;
+use Pod::Usage;
+
+use lib "$FindBin::Bin/lib";
+
+use Display;
+use Logger;
+use Utils;
+
+my %opts = (
+  usage   => sub { pod2usage },
+  help    => sub { pod2usage(-verbose => 2)},
+  verbose => sub { set_verbose },
+  debug   => sub { set_debug },
+  daemon  => 1,
+  logpath => '/var/local/log',
+);
+
+my ($xscreensaver, $log);
+
+sub interrupt() {
+  $log->msg("$FindBin::Script shutdown");
+
+  # For Perl::Critic
+  return;
+} # interrupt
+
+## Main
+GetOptions(
+  \%opts,
+  'usage',
+  'help',
+  'verbose',
+  'debug',
+  'daemon!',
+  'logpath',
+) or pod2usage;
+
+$SIG{INT} = \&interrupt;
+
+$log = Logger->new(
+  path        => $opts{logpath},
+  timestamped => 1,
+  append      => $opts{append},
+);
+
+my $locked = 0;
+
+$| = 1;
+
+$log->msg('Started monitoring XScreenSaver');
+
+if ($opts{daemon}) {
+  # Perl complains if we reference $DB::OUT only once
+  no warnings;
+  EnterDaemonMode unless defined $DB::OUT or get_debug;
+  use warnings;
+} # if
+
+open $xscreensaver, '-|', 'xscreensaver-command -watch'
+  or $log->err("Unable to start xscreensaver-command -watch - $!", 1);
+
+while (<$xscreensaver>) {
+  $log->dbug("Received: $_");
+
+  if (/^LOCK/) {
+    $log->msg('Locked screen');
+    $locked = 1;
+
+    my $cmd = 'xset dpms force off';
+
+    $log->dbug("Calling $cmd");
+    system $cmd;
+    my $status = $?;
+
+    $log->dbug("Returned from $cmd");
+
+    if ($status == 0) {
+      $log->dbug('Success');
+    } else {
+      $log->err("Unable to call $cmd- $!");
+    } # if
+  } elsif ($locked and /^UNBLANK/) {
+    $log->msg('Unlocked screen');
+    $locked = 0;
+  } # if
+} # while
index fdfd9e8..25d3271 100644 (file)
@@ -34,3 +34,4 @@ grilo-plugin-cache*
 qipc*
 birdtry*
 nsemail*
+vboxdrv-Module*
index e9b58ff..e34bf48 100644 (file)
@@ -150,7 +150,7 @@ sub DESTROY {
 
   # Call old signal handler (if any)
   &$oldHandler if $oldHandler;
-  
+
   return;
 } # DESTROY
 
@@ -523,7 +523,7 @@ sub execute {
 Sends a command to the cleartool coprocess. If not running a cleartool coprocess
 is started and managed. The coprocess is implemented as a coprocess using IPC
 for communication that will exist until the object is destroyed. Stdin and
-stdout/stderr are therefore pipes and can be fed. The execute method feds the
+stdout/stderr are therefore pipes and can be fed. The execute method feeds the
 input pipe and returns status and output from the output pipe.
 
 Using execute can speed up execution of repeative cleartool invocations
@@ -594,10 +594,10 @@ Array of output lines from the cleartool command execution.
     # Simple check to see if we can execute cleartool
     @output = `$cleartool -ver 2>&1`;
     @output = ();
-        
+
     return (-1, 'Clearcase not installed')
       unless $? == 0;
-          
+
     $clearpid = open3 ($clearin, $clearout, $clearout, $cleartool, "-status");
 
     return (-1, ('Clearcase not installed')) unless $clearpid;
@@ -631,7 +631,7 @@ Array of output lines from the cleartool command execution.
   $self->{lastcmd} = 'cleartool ' . $cmd;
   $self->{status}  = $status;
   $self->{output}  = join "\n", @output;
-  
+
   return ($status, @output);
 } # execute
 
index c18c2f7..d462490 100644 (file)
@@ -104,10 +104,11 @@ Returns:
 =cut
 
   if (-f "$FindBin::Bin/shh") {
+    $msg .= ' [silent]';
     if ($log) {
-      $log->msg("Not speaking because we were asked to be quiet - $msg");
+      $log->msg($msg);
     } else {
-      verbose "Not speaking because we were asked to be quiet - $msg";
+      verbose $msg;
     } # if
 
     return;
index 29e020c..446d2e7 100644 (file)
@@ -471,7 +471,7 @@ In a scalar context just the 1 minute load average.
   # TODO: Make it work on Windows...
   return if $^O =~ /win/i;
 
-  open my $loadAvg, '/proc/loadavg'
+  open my $loadAvg, '<', '/proc/loadavg'
     or croak "Unable to open /proc/loadavg\n";
 
   my $load = <$loadAvg>;