public
Rubygem
Description: This gem set the autotest (ZenTest) to send messages to software as Growl, LibNotify, and Snarl, displaying a window with the results.
Homepage: http://www.nomedojogo.com/
Clone URL: git://github.com/carlosbrando/autotest-notification.git
Refactoring.
carlosbrando (author)
Wed Jun 18 12:19:34 -0700 2008
commit  150728cf6658bea8bfb98a783c55fdbdb3ce8f7b
tree    90e1d720062dc7a137381e0fdd4f69fbd27084b0
parent  b81fac549b27e8395de1cdc7047242a9fc5fa88b
...
6
7
8
9
10
11
12
13
 
 
 
 
 
 
 
 
14
15
16
...
6
7
8
 
 
 
 
 
9
10
11
12
13
14
15
16
17
18
19
0
@@ -6,11 +6,14 @@ module AutotestNotification
0
       end
0
 
0
       def play_sound(total, failures)
0
- `#{File.expand_path(File.dirname(__FILE__) + "/../../bin/")}/playsound #{File.expand_path(File.dirname(__FILE__) + "/../../sounds/doom/")}/#{percent(total, failures)}.wav`
0
- end
0
-
0
- def mplayer_sound(total, failures)
0
- system("/usr/bin/mplayer #{File.expand_path(File.dirname(__FILE__) + "../../../sounds/doom/")}/#{percent(total, failures)}.wav")
0
+ sound_file = "#{File.expand_path(File.dirname(__FILE__) + "/../../sounds/doom/")}/#{percent(total, failures)}.wav"
0
+
0
+ case RUBY_PLATFORM
0
+ when /darwin/
0
+ `#{File.expand_path(File.dirname(__FILE__) + "/../../bin/")}/playsound #{sound_file}`
0
+ when /linux/
0
+ system("/usr/bin/mplayer #{sound_file}")
0
+ end
0
       end
0
 
0
       private
...
2
3
4
5
 
6
7
8
...
11
12
13
14
 
15
16
17
 
 
 
 
 
 
 
 
 
 
 
 
 
18
19
20
...
27
28
29
30
31
32
33
34
35
36
37
38
 
 
 
 
 
39
 
 
40
41
42
43
44
45
46
47
48
49
50
51
52
 
53
54
55
...
2
3
4
 
5
6
7
8
...
11
12
13
 
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
...
40
41
42
 
 
 
 
 
 
 
 
 
43
44
45
46
47
48
49
50
51
 
 
 
 
 
 
 
 
 
 
 
 
52
53
54
55
0
@@ -2,7 +2,7 @@ module AutotestNotification
0
   class Linux
0
     class << self
0
 
0
- def notify(title, msg, img, total=1, failures=0)
0
+ def notify(title, msg, img, total = 1, failures = 0)
0
         if has_notify?
0
           notify_send(title, msg, img)
0
         elsif has_zenity?
0
@@ -11,10 +11,23 @@ module AutotestNotification
0
           kdialog(title, msg, img)
0
         end
0
 
0
- talk(msg, total, failures) if SPEAKING
0
+ say(total, failures) if SPEAKING
0
       end
0
 
0
       protected
0
+
0
+ def has_notify?
0
+ system "which notify-send 2> /dev/null"
0
+ end
0
+
0
+ def has_kdialog?
0
+ system "which kdialog 2> /dev/null"
0
+ end
0
+
0
+ def has_zenity?
0
+ system "which zenity 2> /dev/null"
0
+ end
0
+
0
         def notify_send(title, msg, img)
0
           system "notify-send -t #{EXPIRATION_IN_SECONDS * 1000} -i #{img} '#{title}' '#{msg}'"
0
         end
0
@@ -27,29 +40,16 @@ module AutotestNotification
0
           system "zenity --info --text='#{msg}' --title='#{title}'"
0
         end
0
 
0
- def talk(msg, total, failures)
0
- # TODO: check if user has espeak and mplayer installed
0
- begin
0
- if failures > 0
0
- DOOM_EDITION ? Doom.mplayer_sound(total, failures) : system("/usr/bin/espeak '#{failures} test#{'s' unless failures == 1} failed'")
0
- else
0
- DOOM_EDITION ? Doom.mplayer_sound(total, failures) : system("/usr/bin/espeak 'All tests passed successfully'")
0
- end
0
- rescue
0
+ def say(total, failures)
0
+ if failures > 0
0
+ DOOM_EDITION ? Doom.play_sound(total, failures) : system("/usr/bin/espeak '#{failures} test#{'s' unless failures == 1} failed'")
0
+ else
0
+ DOOM_EDITION ? Doom.play_sound(total, failures) : system("/usr/bin/espeak 'All tests passed successfully'")
0
           end
0
+ rescue
0
+ puts "You need the #{DOOM_EDITION ? 'mplayer' : 'espeak'} installed to hear the sounds."
0
         end
0
-
0
- def has_zenity?
0
- system "which zenity 2> /dev/null"
0
- end
0
-
0
- def has_notify?
0
- system "which notify-send 2> /dev/null"
0
- end
0
-
0
- def has_kdialog?
0
- system "which kdialog 2> /dev/null"
0
- end
0
+
0
     end
0
   end
0
 end

Comments

    No one has commented yet.