armin-joellenbeck-smilies 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,74 @@
1
+ =Smilies
2
+
3
+ This library consists of a notification server for linux desktops and a
4
+ correspondent ruby client API. It further contains a binary named *smile*
5
+ which runs a given shell command and reports its output and return status.
6
+
7
+ =Installation
8
+
9
+ You have to install first:
10
+ * notification-daemon >= 0.3.7
11
+ * RNotify.rb >= 0.3.3
12
+
13
+ Install the *smilies* gem itself by the following command:
14
+
15
+ $ gem install --source=http://gems.github.com armin-joellenbeck-smilies
16
+
17
+ =Usage
18
+
19
+ Start the notification server as follows:
20
+
21
+ $ smilies
22
+
23
+ Then run the binary *smile* with a command line as parameter, for example:
24
+
25
+ $ smile rake
26
+
27
+ You get a notification if the command line has passed or failed with the
28
+ last line of its output (stdout and stderr together). You can click the
29
+ button '*Details*' to get the full output.
30
+
31
+ For writing a client for the *smilies* notification server see the binary
32
+ *smile*:
33
+
34
+ :include:bin/smile
35
+
36
+ =Support
37
+
38
+ The project home is at GitHub[http://github.com/armin-joellenbeck/smilies/tree/master]:
39
+ http://github.com/armin-joellenbeck/smilies/tree/master
40
+
41
+ Feel free to send:
42
+ * bug reports
43
+ * support requests
44
+ * feature requests
45
+ * patches
46
+
47
+ =Copyright
48
+
49
+ Copyright (c) 2008 by Armin Jöllenbeck
50
+ <armin@joellenbeck.net[mailto:armin@joellenbeck.net]>
51
+
52
+ All rights reserved.
53
+
54
+ Redistribution and use in source and binary forms, with or without
55
+ modification, are permitted provided that the following conditions
56
+ are met:
57
+ 1. Redistributions of source code must retain the above copyright
58
+ notice, this list of conditions and the following disclaimer.
59
+ 2. Redistributions in binary form must reproduce the above copyright
60
+ notice, this list of conditions and the following disclaimer in the
61
+ documentation and/or other materials provided with the distribution.
62
+ 3. The names of the contributors may not be used to endorse or promote products
63
+ derived from this software without specific prior written permission.
64
+
65
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
66
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
67
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
68
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
69
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
70
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
71
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
72
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
73
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
74
+ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ require 'rake/gempackagetask'
2
+ require 'spec/rake/spectask'
3
+ require 'rake/rdoctask'
4
+
5
+
6
+ task :default => [:spec]
7
+
8
+
9
+ task :all => [:spec, :doc]
10
+
11
+
12
+ Spec::Rake::SpecTask.new do |t|
13
+ t.libs << 'spec' << 'lib'
14
+ t.spec_opts << '--format' << 'specdoc'
15
+ end
16
+
17
+
18
+ Rake::RDocTask.new(:doc) do |t|
19
+ t.rdoc_dir = 'doc'
20
+ t.rdoc_files.include('README', 'lib/**/*.rb')
21
+ t.options = [
22
+ '--all',
23
+ '--charset', 'utf8',
24
+ '--inline-source',
25
+ '--main', 'README',
26
+ '--title', 'Smilies'
27
+ ]
28
+ end
29
+
30
+
31
+ Rake::GemPackageTask.new(eval(File.read('smilies.gemspec'))) do |pkg|
32
+ end
data/bin/smile ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
3
+ require 'smilies/client'
4
+
5
+ if ARGV.empty?
6
+ puts 'smile: usage: smile <command line>'
7
+ puts 'smile: command line cannot be blank'
8
+ exit(-1)
9
+ end
10
+
11
+ command = ARGV.join(' ')
12
+
13
+ client = Smilies::Client.new
14
+
15
+ client.yellow("Running: #{command}")
16
+ output= nil
17
+ IO.popen("#{command} 2>&1") do |io|
18
+ output = io.read
19
+ end
20
+ exitstatus = $?.exitstatus
21
+ if exitstatus == 0
22
+ client.green("Passed: #{command}", output)
23
+ else
24
+ client.red("Failed: #{command}", output)
25
+ end
data/bin/smilies ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
3
+ require 'smilies/server'
4
+
5
+ Smilies::Server.start
6
+
7
+ trap 'INT' do
8
+ Smilies::Server.stop
9
+ end
10
+
11
+ trap 'TERM' do
12
+ Smilies::Server.stop
13
+ end
14
+
15
+ Smilies::Server.join
data/icons/green.png ADDED
Binary file
data/icons/red.png ADDED
Binary file
data/icons/yellow.png ADDED
Binary file
@@ -0,0 +1,30 @@
1
+ require 'drb'
2
+
3
+
4
+ module Smilies
5
+
6
+ class Client
7
+
8
+ def initialize(server=nil)
9
+ if server
10
+ @server = server
11
+ else
12
+ @server = DRb::DRbObject.new(nil, 'druby://localhost:8809')
13
+ end
14
+ end
15
+
16
+ def green(summary=nil, message=nil)
17
+ @server.green(summary, message)
18
+ end
19
+
20
+ def yellow(summary=nil, message=nil)
21
+ @server.yellow(summary, message)
22
+ end
23
+
24
+ def red(summary=nil, message=nil)
25
+ @server.red(summary, message)
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,23 @@
1
+ module Smilies
2
+
3
+ module Helper
4
+
5
+ def self.smilies_directory
6
+ File.dirname(__FILE__) + '/../../icons'
7
+ end
8
+
9
+ def self.green_smiley_path
10
+ smilies_directory + '/green.png'
11
+ end
12
+
13
+ def self.yellow_smiley_path
14
+ smilies_directory + '/yellow.png'
15
+ end
16
+
17
+ def self.red_smiley_path
18
+ smilies_directory + '/red.png'
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,82 @@
1
+ require 'drb'
2
+ require 'RNotify'
3
+ require 'singleton'
4
+
5
+ require 'smilies/helper'
6
+
7
+
8
+ module Smilies
9
+
10
+ class Server
11
+
12
+ include DRbUndumped
13
+ include Singleton
14
+
15
+ def self.start
16
+ @gtk_thread = Thread.new { Gtk.main }
17
+ DRb.start_service('druby://localhost:8809', self.instance)
18
+ end
19
+
20
+ def self.stop
21
+ DRb.stop_service
22
+ @gtk_thread.terminate
23
+ end
24
+
25
+ def self.join
26
+ DRb.thread.join
27
+ end
28
+
29
+ def initialize
30
+ @green_smiley = read_icon(Helper.green_smiley_path)
31
+ @yellow_smiley = read_icon(Helper.yellow_smiley_path)
32
+ @red_smiley = read_icon(Helper.red_smiley_path)
33
+ Notify.init('Smilies')
34
+ @tray_icon = Gtk::StatusIcon.new
35
+ @tray_icon.pixbuf = @yellow_smiley
36
+ @tray_icon.tooltip = 'Started'
37
+ @notification = Notify::Notification.new('Start',nil,nil,@tray_icon)
38
+ @notification.urgency = Notify::Notification::URGENCY_LOW
39
+ @notification.timeout = 10000
40
+ @notification.add_action('details', 'Details') { |action| send(action) }
41
+ end
42
+
43
+ def details
44
+ puts @message
45
+ end
46
+
47
+ def green(summary=nil, message=nil)
48
+ message(@green_smiley, summary, message)
49
+ end
50
+
51
+ def yellow(summary=nil, message=nil)
52
+ message(@yellow_smiley, summary, message)
53
+ end
54
+
55
+ def red(summary=nil, message=nil)
56
+ message(@red_smiley, summary, message)
57
+ end
58
+
59
+ private
60
+
61
+ def read_icon(icon_path)
62
+ Gdk::Pixbuf.new(icon_path, 64, 64)
63
+ end
64
+
65
+ def message(icon, summary=nil, message=nil)
66
+ @tray_icon.pixbuf = icon
67
+ @message = message
68
+ if summary
69
+ @tray_icon.tooltip = summary
70
+ end
71
+ if message
72
+ tail = message.split("\n")[-1]
73
+ @notification.update(summary, tail, nil)
74
+ @notification.pixbuf_icon = icon
75
+ @notification.show
76
+ end
77
+ nil
78
+ end
79
+
80
+ end
81
+
82
+ end
data/smilies.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'smilies'
3
+ s.version = '0.0.1'
4
+ s.summary = 'Notification for linux desktops'
5
+ s.author = 'Armin Joellenbeck'
6
+ s.email = 'armin@joellenbeck.net'
7
+ s.homepage = 'http://github.com/armin-joellenbeck/smilies/tree/master'
8
+ s.description = <<-EOF
9
+ This library consists of a notification server for linux desktops and a
10
+ correspondent ruby client API. It further contains a binary named smile
11
+ which runs a given shell command and reports its output and return status.
12
+ EOF
13
+ s.requirements <<
14
+ 'notification-daemon >= 0.3.7' <<
15
+ 'RNotify.rb >= 0.3.3'
16
+ s.files = Dir.glob([
17
+ 'README',
18
+ 'Rakefile',
19
+ '*.gemspec',
20
+ 'bin/*',
21
+ 'icons/*',
22
+ 'lib/**/*',
23
+ 'spec/**/*'
24
+ ])
25
+ s.bindir = 'bin'
26
+ s.executables << 'smilies' << 'smile'
27
+ s.has_rdoc = true
28
+ s.extra_rdoc_files << 'README'
29
+ s.rdoc_options = [
30
+ '--all',
31
+ '--charset', 'utf8',
32
+ '--main', 'README',
33
+ '--title', 'Smilies'
34
+ ]
35
+ end
@@ -0,0 +1,30 @@
1
+ require 'smilies/client'
2
+
3
+
4
+ module Smilies
5
+
6
+ describe Client do
7
+
8
+ before do
9
+ @server = mock :server
10
+ @client = Client.new(@server)
11
+ end
12
+
13
+ it 'should send a green message to server' do
14
+ @server.should_receive(:green).with('green', 'Really green!')
15
+ @client.green('green', 'Really green!')
16
+ end
17
+
18
+ it 'should send a yellow message to server' do
19
+ @server.should_receive(:yellow).with('yellow', 'Really yellow!')
20
+ @client.yellow('yellow', 'Really yellow!')
21
+ end
22
+
23
+ it 'should send a red message to server' do
24
+ @server.should_receive(:red).with('red', 'Really red!')
25
+ @client.red('red', 'Really red!')
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'smilies/helper'
2
+
3
+
4
+ module Smilies
5
+
6
+ describe Helper do
7
+
8
+ it 'should give the smilies directory' do
9
+ path = Helper.smilies_directory
10
+ File.directory?(path).should be_true
11
+ end
12
+
13
+ it 'should give the green smiley' do
14
+ path = Helper.green_smiley_path
15
+ File.file?(path).should be_true
16
+ end
17
+
18
+ it 'should give the yellow smiley' do
19
+ path = Helper.yellow_smiley_path
20
+ File.file?(path).should be_true
21
+ end
22
+
23
+ it 'should give the red smiley' do
24
+ path = Helper.red_smiley_path
25
+ File.file?(path).should be_true
26
+ end
27
+
28
+ end
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: armin-joellenbeck-smilies
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Armin Joellenbeck
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-14 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: This library consists of a notification server for linux desktops and a correspondent ruby client API. It further contains a binary named smile which runs a given shell command and reports its output and return status.
17
+ email: armin@joellenbeck.net
18
+ executables:
19
+ - smilies
20
+ - smile
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - README
25
+ files:
26
+ - README
27
+ - Rakefile
28
+ - smilies.gemspec
29
+ - bin/smile
30
+ - bin/smilies
31
+ - icons/green.png
32
+ - icons/yellow.png
33
+ - icons/red.png
34
+ - lib/smilies
35
+ - lib/smilies/server.rb
36
+ - lib/smilies/client.rb
37
+ - lib/smilies/helper.rb
38
+ - spec/smilies
39
+ - spec/smilies/helper_spec.rb
40
+ - spec/smilies/client_spec.rb
41
+ has_rdoc: true
42
+ homepage: http://github.com/armin-joellenbeck/smilies/tree/master
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --all
46
+ - --charset
47
+ - utf8
48
+ - --main
49
+ - README
50
+ - --title
51
+ - Smilies
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements:
67
+ - notification-daemon >= 0.3.7
68
+ - RNotify.rb >= 0.3.3
69
+ rubyforge_project:
70
+ rubygems_version: 1.0.1
71
+ signing_key:
72
+ specification_version: 2
73
+ summary: Notification for linux desktops
74
+ test_files: []
75
+