Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 96 lines (77 sloc) 2.572 kb
33ecec1 KapiNotify tool added!
Anton Pirogov authored
1 #!/usr/bin/env ruby
2 #KapiNotify - show message box when something changes in kapiland (production/research ready)
3 #Copyright (C) 2010 Anton Pirogov
4 #Licensed under the GPLv3 or later
5
6 require 'tk' #for message box
2010054 Adapted to Ruby 1.9.2
Anton Pirogov authored
7 require_relative 'login'
8 require_relative 'funcs'
33ecec1 KapiNotify tool added!
Anton Pirogov authored
9 include HelpFuncs
10
11 #show a message box with given text
12 def notify(str)
13 Tk.messageBox('title'=>'KapiNotify', 'message'=>str)
14 end
15
16
17 #ensure only ONE instance of KapiNotify is running
18 tmp_file = File.expand_path(File.dirname(__FILE__)) + "/KapiNotify.lock"
19 if File.exists?(tmp_file)
20 puts "Already running (lock file)! Shutting down..."
21 notify("KapiNotify is already running!\n\nIf you are sure that it is not, delete #{tmp_file}")
22 exit
23 else
24 f=File.open(tmp_file,'w')
25 f.puts "This is a lock file, ensuring KapiNotify is started only once."
26 f.close
27 end
28
29 #script gets killed -> shutdown, remove lock
30 trap("INT") {
31 puts "KapiNotify shutting down..."
b047301 Context sensitive completion improved
Anton Pirogov authored
32 Login.logout() #clean logout from kapiland (just to make sure)
33ecec1 KapiNotify tool added!
Anton Pirogov authored
33 File.delete(tmp_file) #remove lock file
34 exit
35 }
36
b047301 Context sensitive completion improved
Anton Pirogov authored
37 Login.init_and_login() #init mechanize, login to kapiland
33ecec1 KapiNotify tool added!
Anton Pirogov authored
38
39 puts "KapiNotify started!"
40
41 ##### FUNCTIONS FOR KAPINOTIFY #####
42
43 #get initial info - type, id, task and current activity state
44 #(activity: bereit=false, everything else=true)
45 def get_infos
46 array = list_prod_or_res('prod')+list_prod_or_res('res')
47 array.map! {|item|
48 item = item.split(' ')
49 new = Hash.new
50 new[:type] = item[1]
51 new[:id] = item[0]
52 new[:task] = item[4...-1].join(' ')
53
54 if item[-1]=='bereit'
55 new[:state] = false
56 else
57 new[:state] = true
58 end
59
60 new
61 }
62 end
63
64 #get array telling where something changed
65 def compare_state(a, b)
66 c = Array.new
67 0.upto(a.length-1) do |i|
68 c << (a[i][:state] == b[i][:state])
69 end
70 return c
71 end
72
73 ##################
74
75 #get list of types, ids and tasks to inform user what finished doing what
76 #and also save activity state (true/false)
77 state = get_infos()
78 while true #endless loop checking for updates
79 newstate = get_infos() #get current list with data
80
81 msg = '' #empty message for now...
82
83 #check the changes and create a notification
84 comparedata = compare_state(state, newstate)
85 comparedata.each_with_index{|item, i|
86 if !item && newstate[i][:state]==false #something has finished!
87 msg += "#{state[i][:type]} #{state[i][:id]} finished! (#{state[i][:task]})\n"
88 end
89 }
90 notify(msg) if msg != '' #we have changes -> show the message
91
caeffbf little change in kapinotify, project rename
Anton Pirogov authored
92 sleep 60 #checking every minute
33ecec1 KapiNotify tool added!
Anton Pirogov authored
93 state = newstate #replace old with new, start over
94 end
95
Something went wrong with that request. Please try again.