Commit 864d0d53749f2a0c81e3e4bc3402f209a3ece94a

imported

Commit diff

.autotest

 
1# vi: ft=ruby
2
3module Autotest::GnomeNotify
4
5 # Time notification will be displayed before disappearing automatically
6 EXPIRATION_IN_SECONDS = 20
7 ERROR_STOCK_ICON = "gtk-dialog-error"
8 SUCCESS_STOCK_ICON = "gtk-dialog-info"
9
10
11 # Convenience method to send an error notification message
12 #
13 # [stock_icon] Stock icon name of icon to display
14 # [title] Notification message title
15 # [message] Core message for the notification
16 def self.notify stock_icon, title, message
17 options = "-t #{EXPIRATION_IN_SECONDS * 1000} -i #{stock_icon}"
18 system "notify-send #{options} '#{title}' '#{message}'"
19 end
20
21 Autotest.add_hook :red do |at|
22 title = filter_title(at.results)
23 message = filter_message(at.results)
24 notify ERROR_STOCK_ICON, title, message
25 end
26
27 Autotest.add_hook :green do |at|
28 title = filter_title(at.results)
29 if title
30 message = filter_message(at.results)
31 notify SUCCESS_STOCK_ICON, title, message
32 else
33 title = 'ERROR'
34 notify ERROR_STOCK_ICON, title, message
35 end
36 end
37
38 def self.filter_title(results)
39 output = results.slice(/(\d+)\sexamples?,\s(\d+)\sfailures?/)
40 output = swap_position(output)
41 return output
42 end
43
44 def self.swap_position(string)
45 return string if string.nil?
46
47 splitted = string.split(',')
48 "#{splitted[1]}, #{splitted[0]}"
49 end
50
51 def self.filter_message(results)
52 output = ''
53
54 magneta = results[/\n\e\[35m.*\n.*/]
55 if magneta
56 output << magneta.sub(/\n\e\[35m/, '').sub(/\e\[0m/, '')
57 end
58
59 unless magneta # no need to find red if magneta excisted
60 red = results[/\n\e\[31m.*\n.*/]
61 if red
62 output << red.sub(/\n\e\[31m/, '').sub(/\e\[0m/, '')
63 end
64 end
65
66 output.gsub!(/['#`<>]/, '') # notify-send don't like those symbols
67 return output
68 end
69end
toggle raw diff

README

 
1A little improved autotest notification for Gnome.
2
3More info at:
4http://gitorious.org/projects/autotest-gnomenotify
toggle raw diff

TODO

 
1[] need to write install info
2
toggle raw diff