Changeset 154
- Timestamp:
- 04/27/08 01:31:31 (23 months ago)
- Location:
- zadolbator
- Files:
-
- 1 added
- 4 modified
-
data/zadolbator/Zadolbator_schema.sql (modified) (1 diff)
-
lib/zadolbator/component.rb (modified) (3 diffs)
-
lib/zadolbator/easyadd_events.rb (added)
-
lib/zadolbator/worker_thread.rb (modified) (2 diffs)
-
zadolbator.sh (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
zadolbator/data/zadolbator/Zadolbator_schema.sql
r130 r154 1 1 CREATE TABLE Users(id TEXT NOT NULL, PRIMARY KEY(id)); 2 2 3 CREATE TABLE Events(id TEXT NOT NULL, owner_id TEXT, ical TEXT, PRIMARY KEY(id));3 CREATE TABLE Events(id INTEGER PRIMARY KEY AUTOINCREMENT, owner_id TEXT, title TEXT, description TEXT, datetime DATETIME, alarm DATETIME); 4 4 CREATE INDEX IDX_events_owner ON Events(owner_id); 5 5 -
zadolbator/lib/zadolbator/component.rb
r133 r154 45 45 require 'zadolbator/common_cmds.rb' 46 46 require 'zadolbator/add_events.rb' 47 require 'zadolbator/easyadd_events.rb' 47 48 require 'zadolbator/search_events.rb' 48 49 require 'zadolbator/import_events.rb' … … 78 79 @cmd_procs = { 79 80 AddEventsCmd.cmd_name => AddEventsCmd.new, 81 EasyAddEventsCmd.cmd_name => EasyAddEventsCmd.new, 80 82 ImportEventsCmd.cmd_name => ImportEventsCmd.new, 81 83 ModifyEventsCmd.cmd_name => ModifyEventsCmd.new, … … 190 192 end 191 193 end 194 puts iq 195 puts "####" 192 196 iq.to, iq.from = iq.from, iq.to 193 197 send(iq) -
zadolbator/lib/zadolbator/worker_thread.rb
r130 r154 23 23 @component = comp 24 24 @occurs = [] 25 @next_fill_date = DateTime.now25 @next_fill_date = Time.now 26 26 @current_date = @next_fill_date 27 27 @occurs_lock = Mutex.new 28 refill_occurences 28 29 end 29 30 30 31 def send_reminder(info) 32 puts "SENDING REMINDER #{info.inspect}" 31 33 e = Storage::Event.find(info[:uid]) 32 e.users.each { |user| 33 @component.log.debug("Sending reminder #{info[:uid]} to #{user.id}") 34 msg = Jabber::Message.new.set_from(@component.jabber_conf['jid']).set_to(user.id) 35 cals = Icalendar::parse(e.ical) 36 # We know only one calendar and one event should be present 37 event = cals.first.events.first 34 @component.log.debug("Sending reminder #{info[:uid]} to #{e.owner.id}") 35 msg = Jabber::Message.new.set_from(@component.jabber_conf['jid']).set_to(e.owner.id) 38 36 39 if @component.reminder_conf['allow_ruby_script'] and (ruby_script = event.properties['x-ruby_script']) != nil 40 @component.log.debug("Script: #{ruby_script}") 41 begin 42 safe_level = @component.reminder_conf['ruby_script_safe'] 43 safe_level = 3 if safe_level == nil 44 ruby_res = eval "$SAFE = #{safe_level}; #{ruby_script}" 45 rescue => ex 46 @component.log.error(ex) 47 end 48 end 49 50 msg.body = "#{event.dtstart} - #{event.summary}\n#{info[:desc]}\n#{ruby_res}\n\n\n#{e.ical}" 51 @component.send(msg) 52 } 37 msg.body = "#{e.datetime} - #{e.title}\n#{e.description}" 38 puts msg.inspect 39 @component.send(msg) 53 40 end 54 41 55 42 # Fill occurences for all events until 'date_end' 56 43 def fill_occurences(date_start) 57 date_end = date_start + @component.reminder_conf['queue_interval'] / (24.0 * 3600) 44 date_end = date_start + @component.reminder_conf['queue_interval'] 45 puts date_end.strftime("%c") 58 46 @occurs.clear 59 Storage::Event.find(:all).each { |e| 60 cals = Icalendar::parse(e.ical) 61 @component.log.debug(e.ical) 62 event = cals.first.events.first 63 64 event.alarms.each { |alarm| 65 # If events are repeated - put their durations into array. 66 # At least first item is always filled. 67 durs = [0] 68 if alarm.duration? 69 dur = Vpim::Icalendar::decode_duration(alarm.duration) 70 alarm.repeat.times { |i| durs << (i + 1) * dur } 71 end 72 73 @component.log.debug("Durations: #{durs.inspect}") 74 75 rel = alarm.trigger.ical_params['RELATED'] 76 raise "RELATED=END option is not supported yet" if rel and rel.first == 'END' 77 78 @component.log.debug(alarm.trigger.ical_params['VALUE']) 79 80 if alarm.trigger.ical_params['VALUE'] and alarm.trigger.ical_params['VALUE'].first == 'DATE-TIME' 81 # The easy one: start date is supplied directly 82 @component.log.debug("Alarm date: #{alarm.trigger}") 83 durs.each { |dur| 84 cur_occ = DateTime.parse(alarm.trigger) + dur / (24.0 * 3600) 85 @component.log.debug("Actual occ: #{cur_occ}") 86 @occurs << {:time => cur_occ, :uid => e.id, :desc => alarm.description} if date_start <= cur_occ and cur_occ <= date_end 87 } 88 else 89 trig_dur = Vpim::Icalendar::decode_duration(alarm.trigger) 90 @component.log.debug("Trigger duration: #{trig_dur}, start time: #{event.dtstart}") 47 Storage::Event.find(:all, :conditions => {:alarm => date_start..(date_start+@component.reminder_conf['queue_interval']) } ).each { |e| 91 48 92 # Vpim does not work in DateTime (btw, why???), but uses Time instead - 93 # thus, it cannot handle years before 1970. To overcome that, we replace here 94 # all years before 1970 by 1970, hoping that recurrence is not more than yearly, 95 # so this replacement, being done for calculations only, does not break things. 96 if event.dtstart.year < 1970 97 # Is there any better way to just replace a year in date??? 98 start = DateTime.civil(1970, event.dtstart.month(), event.dtstart.day(), 99 event.dtstart.hour(), event.dtstart.min(), event.dtstart.sec(), 100 event.dtstart.offset(), event.dtstart.start()) 101 else 102 start = event.dtstart 103 end 104 105 # We know only one calendar should be present 106 rrule = Vpim::Rrule.new(Time.parse(start.strftime("%c")), event.recurrence_rules.first) 107 @component.log.debug("date_end: #{date_end}, durs.min: #{durs.min}, trig_dur: #{trig_dur}") 108 rrule.each(Time.parse(date_end.strftime("%c")) - durs.min - trig_dur) { |occ| 109 @component.log.debug("Occ: #{occ}") 110 durs.each { |dur| 111 cur_occ = DateTime.parse((occ + dur + trig_dur).iso8601) 112 @component.log.debug("Actual occ: #{cur_occ}") 113 @occurs << {:time => cur_occ, :uid => e.id, :desc => alarm.description} if date_start <= cur_occ and cur_occ <= date_end 114 } 115 } 116 end 117 } 49 @occurs << {:time => e.alarm, :uid => e.id} 118 50 } 119 51 @occurs.sort_by { |occ| occ[:time] } … … 125 57 while true 126 58 @occurs_lock.synchronize { 127 now = DateTime.now59 now = Time.now 128 60 @component.log.debug("Current time: #{now}") 129 61 if not @occurs.empty? 130 62 @component.log.debug("First time: #{@occurs.first[:time]}") 63 puts "TEST" 64 puts @occurs.first[:time].to_s < now.to_s 65 puts @occurs.empty? 66 puts "BEGIN WHILE" 131 67 while not @occurs.empty? and @occurs.first[:time] <= now 68 puts "*******" 132 69 send_reminder(@occurs.shift) 133 70 end 71 puts "END WHILE" 134 72 end 135 73 fill_occurences(now) if @next_fill_date <= now 136 74 @current_date = now 137 75 } 76 puts "####" 77 puts @component.reminder_conf['check_interval'] 138 78 sleep(@component.reminder_conf['check_interval']) 79 puts "$$$$" 139 80 end 140 81 end -
zadolbator/zadolbator.sh
r133 r154 2 2 #helper to launch zadolbator without installing it 3 3 4 ruby -Ilib bin/zadolbator.rb -c zadolbator.yaml -l zadolbator.log 4 ruby -Ilib bin/zadolbator.rb -c zadolbator.yaml -l zadolbator.log --log-level DEBUG
