Maybe add lib? working on a homebrew formula

This commit is contained in:
Matthew Connelly 2015-02-24 23:06:17 +00:00
parent fd820b9a1c
commit 156b218aaf
3 changed files with 72 additions and 29 deletions

37
ayudante-lobo Normal file → Executable file
View File

@ -2,29 +2,45 @@
package Maff::Utility::AyudanteLobo;
use strict;
use warnings;
# github:MaffC/maffpl.git provides the Maff:: namespace
use Maff::Common::Conf qw/conf_load/;
use Maff::Common::Net qw/scp_upload/;
use Maff::Common::OSX qw/:all/;
use Maff::Common::Time qw/timefmt2str/;
use Cwd; use POSIX;
use Date::Format qw/time2str/;
use Net::SSH2; use Try::Tiny;
use POE; use POE::Component::DirWatch::WithCaller;
use Unix::PID;
use Unix::PID; use YAML;
use Maff::Common::OSX qw/:all/;
my $ME = "ayudante-lobo";
my $VERSION = "0.9.1";
my $VERSION = "0.9.2";
my $HOSTNAME = `hostname`; chomp $HOSTNAME;
#Expects that it will be launched either in an environment where $HOME is an exported env variable or that it will be launched by an initscript with the current working directory being the user's homedir.
my $home = $ENV{HOME} || cwd();
my $Conf = conf_load("$home/.${ME}rc") or logger(9,"Couldn't load .${ME}rc file in $home!");
my $Conf = YAML::LoadFile("$home/.${ME}rc") or logger(9,"Couldn't load .${ME}rc file in $home!");
my $running = 0;
my $sighup = 0;
# Functions included from github:MaffC/maffpl to reduce dependencies on non-CPAN modules
sub scp_upload {
my $file = shift; my $ssh = Net::SSH2->new();
try {
$ssh->connect($Conf->{upload}->{server},$Conf->{upload}->{port},Timeout => 3);
} catch {
logger(2,"SSH connection failed (exception): $_") and return 0;
};
logger(2,"SSH connection failed (error): $ssh->error") and return 0 if $ssh->error;
$ssh->auth_publickey($Conf->{upload}->{user},$Conf->{upload}->{sshkeypath}.'.pub',$Conf->{upload}->{sshkeypath});
logger(2,"SSH connection failed (auth error): $ssh->error") and return 0 unless $ssh->auth_ok;
$Conf->{upload}->{remotepath} .= "/" unless $Conf->{upload}->{remotepath} =~ /\/$/;
logger(2,"File upload failed: $ssh->error") and return 0 unless $ssh->scp_put("$file",$Conf->{upload}->{remotepath}.$file->basename);
$ssh->disconnect; return 1;
}
sub timefmt2str {
return Date::Format::time2str(shift,time());
}
# Functions
sub sigtrap {
my $sig = shift;
@ -87,6 +103,7 @@ sub upload {
}
# Main
#TODO: error out if monitors are defined but none are enabled
logger(9,"At least one monitor must be defined in ~/.${ME}rc.") unless scalar keys %{$Conf->{monitor}};
POE::Kernel->run();
$Conf->{general}->{pidfile} = "$home/.$ME.pid" unless defined $Conf->{general}->{pidfile} and length $Conf->{general}->{pidfile};

45
lib/Maff-Common-OSX.pm Normal file
View File

@ -0,0 +1,45 @@
package Maff::Common::OSX;
use strict;
use Exporter;
use vars qw/$VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS/;
use Carp;
use Mac::Pasteboard;
$VERSION = 1.0.0;
@ISA = qw/Exporter/;
@EXPORT = qw//;
@EXPORT_OK = qw/&clipb_copy macintalk_say nc_notify/;
%EXPORT_TAGS = (all=>[@EXPORT_OK]);
sub copy ($);
sub nc_notify (@);
sub macintalk_say (@);
*clipb_copy = \©
sub copy ($) {
my $text = shift;
my $clipboard = Mac::Pasteboard->new();
$clipboard->clear();
$clipboard->copy($text);
$clipboard->copy($text, "public.utf8-plain-text");
$clipboard->copy($text, "public.utf16-plain-text");
$clipboard->copy($text, "public.utf16-external-plain-text");
}
sub nc_notify (@) {
my ($title,$text) = @_;
system("/usr/bin/osascript -e 'display notification \"$text\" with title \"$title\"' &");
}
sub macintalk_say (@) {
my %args = @_;
my $voice = $args{voice} || "Daniel";
my $rate = $args{rate} || 190;
my $text = $args{text} or croak "named parameter 'text' is required!";
system("/usr/bin/say -v$voice -r$rate '$text' &");
}
1;
__END__

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>scot.maff.mac.ayudantelobo</string>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>EnvironmentVariables</key>
<dict>
<key>PERL5LIB</key>
<string>./lib/perl</string>
</dict>
<key>Program</key>
<string>./bin/ayudante-lobo</string>
</dict>
</plist>