<commit_before>
import dbus.service
from gi.repository import GObject as gobject

from oacids.helpers.dbus_props import GPropSync, Manager, WithProperties
from ifaces import BUS, IFACE, PATH, INTROSPECTABLE_IFACE, TRIGGER_IFACE, OPENAPS_IFACE

from oacids.schedules import utils
import datetime
from dateutil import parser, rrule, tz
import recurrent

from collections import deque, defaultdict
import hashlib

class Trigger (GPropSync):
  OWN_IFACE = IFACE + '.Trigger'
  PROP_SIGS = {
    'name': 's'
  , 'obj': 's'
  , 'expected': 's'
  , 'phases': 's'
  , 'rrule': 's'
  , 'id': 's'
  , 'countdown': 'd'
  }
  name = gobject.property(type=str)
  expected = gobject.property(type=str)
  obj = gobject.property(type=str)
  phases = gobject.property(type=str)
  rrule = gobject.property(type=str)
  @gobject.property(type=float)
  def countdown (self):
    return (self.when - datetime.datetime.now( )).total_seconds( )
  @gobject.property(type=str)
  def id (self):
    return self.armed.hashed
  def __init__ (self, path, manager=None, props=None, armed=None):
    self.manager = manager
    bus = manager.bus
    self.bus = bus or dbus.SessionBus( )
    self.path = path
    self.when = armed.when
    self.armed = armed
    GPropSync.__init__(self, self.bus.get_connection( ), path)
    # WithProperties.__init__(self, self.bus.get_connection( ), path)
    self.attrs = props
    if props:
      for key in props:
        self.set_property(key, props[key])
    self.sync_all_props( )

  @dbus.service.signal(dbus_interface=OWN_IFACE,
                       signature='')
  def Fire (self):
    now = datetime.datetime.now( )
    print "FIRED", now.isoformat( ), self.when.isoformat( ), self.name, self.path
    self.manager.Trigger("Queue", self.path)
    self.manager.master.background.Do(self.attrs, ack=self.on_success, error=self.Error)
  def on_success (self, results):
    print "RESULTS", results<commit_msg>signal generators can't be used as callbacks<commit_after>
import dbus.service
from gi.repository import GObject as gobject

from oacids.helpers.dbus_props import GPropSync, Manager, WithProperties
from ifaces import BUS, IFACE, PATH, INTROSPECTABLE_IFACE, TRIGGER_IFACE, OPENAPS_IFACE

from oacids.schedules import utils
import datetime
from dateutil import parser, rrule, tz
import recurrent

from collections import deque, defaultdict
import hashlib

class Trigger (GPropSync):
  OWN_IFACE = IFACE + '.Trigger'
  PROP_SIGS = {
    'name': 's'
  , 'obj': 's'
  , 'expected': 's'
  , 'phases': 's'
  , 'rrule': 's'
  , 'id': 's'
  , 'countdown': 'd'
  }
  name = gobject.property(type=str)
  expected = gobject.property(type=str)
  obj = gobject.property(type=str)
  phases = gobject.property(type=str)
  rrule = gobject.property(type=str)
  @gobject.property(type=float)
  def countdown (self):
    return (self.when - datetime.datetime.now( )).total_seconds( )
  @gobject.property(type=str)
  def id (self):
    return self.armed.hashed
  def __init__ (self, path, manager=None, props=None, armed=None):
    self.manager = manager
    bus = manager.bus
    self.bus = bus or dbus.SessionBus( )
    self.path = path
    self.when = armed.when
    self.armed = armed
    GPropSync.__init__(self, self.bus.get_connection( ), path)
    # WithProperties.__init__(self, self.bus.get_connection( ), path)
    self.attrs = props
    if props:
      for key in props:
        self.set_property(key, props[key])
    self.sync_all_props( )

  @dbus.service.signal(dbus_interface=OWN_IFACE,
                       signature='')
  def Fire (self):
    now = datetime.datetime.now( )
    print "FIRED", now.isoformat( ), self.when.isoformat( ), self.name, self.path
    self.manager.Trigger("Queue", self.path)
    self.manager.master.background.Do(self.attrs, ack=self.on_success, error=self.on_error)
  def on_error (self):
    self.Error( )
  def on_success (self, results):
    print "RESULTS", results
{'fraction_non_alphanumeric': 0.1259259259259259, 'fraction_numerical': 0.0, 'mean_word_length': 3.735187424425635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7221210', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1338, 'n_words': 315}