Changeset 154

Show
Ignore:
Timestamp:
04/27/08 01:31:31 (23 months ago)
Author:
omega
Message:

Refonte de la base de données, cette version est complètement différente de la version "officiel", elle est beaucoup plus simple, les infos ne sont plus stockés au format iCal. On perd un peu de fonctionnalités, mais on a un truc plus clean. Pour l'instant seul la commande easyadd marche.

Location:
zadolbator
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • zadolbator/data/zadolbator/Zadolbator_schema.sql

    r130 r154  
    11CREATE TABLE Users(id TEXT NOT NULL, PRIMARY KEY(id)); 
    22 
    3 CREATE TABLE Events(id TEXT NOT NULL, owner_id TEXT, ical TEXT, PRIMARY KEY(id)); 
     3CREATE TABLE Events(id INTEGER PRIMARY KEY AUTOINCREMENT, owner_id TEXT, title TEXT, description TEXT, datetime DATETIME, alarm DATETIME); 
    44CREATE INDEX IDX_events_owner ON Events(owner_id); 
    55 
  • zadolbator/lib/zadolbator/component.rb

    r133 r154  
    4545require 'zadolbator/common_cmds.rb' 
    4646require 'zadolbator/add_events.rb' 
     47require 'zadolbator/easyadd_events.rb' 
    4748require 'zadolbator/search_events.rb' 
    4849require 'zadolbator/import_events.rb' 
     
    7879    @cmd_procs = { 
    7980                   AddEventsCmd.cmd_name => AddEventsCmd.new, 
     81                   EasyAddEventsCmd.cmd_name => EasyAddEventsCmd.new, 
    8082                   ImportEventsCmd.cmd_name => ImportEventsCmd.new, 
    8183                   ModifyEventsCmd.cmd_name => ModifyEventsCmd.new, 
     
    190192      end 
    191193    end 
     194    puts iq 
     195    puts "####" 
    192196    iq.to, iq.from = iq.from, iq.to 
    193197    send(iq) 
  • zadolbator/lib/zadolbator/worker_thread.rb

    r130 r154  
    2323      @component = comp 
    2424      @occurs = [] 
    25       @next_fill_date = DateTime.now 
     25      @next_fill_date = Time.now 
    2626      @current_date = @next_fill_date 
    2727      @occurs_lock = Mutex.new 
     28      refill_occurences 
    2829    end 
    2930 
    3031    def send_reminder(info) 
     32      puts "SENDING REMINDER #{info.inspect}" 
    3133      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) 
    3836 
    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) 
    5340    end 
    5441 
    5542    # Fill occurences for all events until 'date_end' 
    5643    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") 
    5846      @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| 
    9148         
    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} 
    11850      } 
    11951      @occurs.sort_by { |occ| occ[:time] } 
     
    12557      while true 
    12658        @occurs_lock.synchronize { 
    127           now = DateTime.now 
     59          now = Time.now 
    12860          @component.log.debug("Current time: #{now}") 
    12961          if not @occurs.empty? 
    13062            @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" 
    13167            while not @occurs.empty? and @occurs.first[:time] <= now 
     68              puts "*******" 
    13269              send_reminder(@occurs.shift) 
    13370            end 
     71            puts "END WHILE" 
    13472          end 
    13573          fill_occurences(now) if @next_fill_date <= now 
    13674          @current_date = now 
    13775        } 
     76        puts "####" 
     77        puts @component.reminder_conf['check_interval'] 
    13878        sleep(@component.reminder_conf['check_interval']) 
     79        puts "$$$$" 
    13980      end 
    14081    end 
  • zadolbator/zadolbator.sh

    r133 r154  
    22#helper to launch zadolbator without installing it 
    33 
    4 ruby -Ilib bin/zadolbator.rb -c zadolbator.yaml -l zadolbator.log 
     4ruby -Ilib bin/zadolbator.rb -c zadolbator.yaml -l zadolbator.log --log-level DEBUG