def idf_remove(name):
    if not idf_exists(name):
        return 0
    proxy = when_proxy()
    if proxy is None:
        return 0
    items = idf_installed_items(name)
    conditions = [x for x in items if x.startswith('conditions' + ':')]
    tasks = [x for x in items if x.startswith('tasks' + ':')]
    sighandlers = [x for x in items if x.startswith('sighandlers' + ':')]
    error = 0
    for item in conditions:
        if not proxy.RemoveItem(item):
            error += 1
    for item in tasks:
        if not proxy.RemoveItem(item):
            error += 1
    for item in sighandlers:
        if not proxy.RemoveItem(item):
            error += 1
    unique_id = _IDF_UNIQUE_ID_MAGIC + name
    if not error:
        datastore.remove(unique_id)
        return 1
    else:
        return -error
Example #2
0
def retrieve_action_history():
    proxy = when_proxy()
    if proxy is None:
        return None
    history = []
    when_history = proxy.GetHistoryEntries()
    when_history.reverse()
    for x in when_history:
        e = x.split(';')
        if e[3].startswith(_PLUGIN_UNIQUE_ID_MAGIC) and \
           e[4].startswith(_PLUGIN_UNIQUE_ID_MAGIC):
            plugin_task = retrieve_plugin(e[3])
            plugin_cond = retrieve_plugin(e[4])
            if plugin_task and plugin_cond:
                d = {
                    'datetime': e[1],
                    'duration': float(e[2]),
                    'task_id': e[3],
                    'task_name': plugin_task.name,
                    'task_icon': load_pixbuf(plugin_task.icon,
                                             not plugin_task.stock),
                    'cond_id': e[4],
                    'cond_name': plugin_cond.name,
                    'cond_icon': load_pixbuf(plugin_cond.icon,
                                             not plugin_cond.stock),
                    'success': bool(e[5] == 'success'),
                }
                history.append(d)
    return history
Example #3
0
def idf_remove(name):
    if not idf_exists(name):
        return 0
    proxy = when_proxy()
    if proxy is None:
        return 0
    items = idf_installed_items(name)
    conditions = [x for x in items if x.startswith('conditions' + ':')]
    tasks = [x for x in items if x.startswith('tasks' + ':')]
    sighandlers = [x for x in items if x.startswith('sighandlers' + ':')]
    error = 0
    for item in conditions:
        if not proxy.RemoveItem(item):
            error += 1
    for item in tasks:
        if not proxy.RemoveItem(item):
            error += 1
    for item in sighandlers:
        if not proxy.RemoveItem(item):
            error += 1
    unique_id = _IDF_UNIQUE_ID_MAGIC + name
    if not error:
        datastore.remove(unique_id)
        return 1
    else:
        return -error
Example #4
0
 def activate(self, active=True):
     proxy = when_proxy()
     if proxy is None:
         return False
     try:
         if not proxy.SuspendCondition(self.unique_id, not active):
             return False
         return True
     except dbus.exceptions.DBusException:
         return False
Example #5
0
 def active(self):
     proxy = when_proxy()
     if proxy is None:
         return False
     try:
         if not proxy.IsSuspendedCondition(self.unique_id):
             return False
         return True
     except dbus.exceptions.DBusException:
         return False
Example #6
0
 def active(self):
     proxy = when_proxy()
     if proxy is None:
         return False
     try:
         if not proxy.IsSuspendedCondition(self.unique_id):
             return False
         return True
     except dbus.exceptions.DBusException:
         return False
Example #7
0
 def activate(self, active=True):
     proxy = when_proxy()
     if proxy is None:
         return False
     try:
         if not proxy.SuspendCondition(self.unique_id, not active):
             return False
         return True
     except dbus.exceptions.DBusException:
         return False
Example #8
0
def unregister_plugin_data(plugin):
    proxy = when_proxy()
    if proxy is None:
        return False
    item_spec = '%s:%s' % (plugin.plugin_type, plugin.unique_id)
    try:
        if not proxy.RemoveItem(item_spec):
            return False
        return True
    except dbus.exceptions.DBusException:
        return False
Example #9
0
def unregister_plugin_data(plugin):
    proxy = when_proxy()
    if proxy is None:
        return False
    item_spec = '%s:%s' % (plugin.plugin_type, plugin.unique_id)
    try:
        if not proxy.RemoveItem(item_spec):
            return False
        return True
    except dbus.exceptions.DBusException:
        return False
Example #10
0
def enable_association_id(unique_id, enable=True):
    proxy = when_proxy()
    if proxy is None:
        return None
    data = retrieve_association(unique_id)
    cond = data[0]
    try:
        if proxy.SuspendCondition(cond, not enable):
            return True
        return False
    except dbus.exceptions.DBusException:
        return None
Example #11
0
def enable_association_id(unique_id, enable=True):
    proxy = when_proxy()
    if proxy is None:
        return None
    data = retrieve_association(unique_id)
    cond = data[0]
    try:
        if proxy.SuspendCondition(cond, not enable):
            return True
        return False
    except dbus.exceptions.DBusException:
        return None
Example #12
0
def idf_install(name, s, force=True):
    if idf_exists(name):
        return False
    unique_id = _IDF_UNIQUE_ID_MAGIC + name
    proxy = when_proxy()
    if proxy is None:
        return False
    items = idf_items(s)
    if items is None:
        return False
    if not proxy.AddItemsBatch(s):
        return False
    datastore.put(unique_id, json.dumps(items))
    return True
Example #13
0
def retrieve_plugin_ids_suspended():
    proxy = when_proxy()
    if proxy is None:
        return None
    l = []
    for x in retrieve_plugin_ids():
        data = retrieve_plugin_data(x)
        if data['plugin_type'] == PLUGIN_CONST.PLUGIN_TYPE_CONDITION:
            try:
                if proxy.IsSuspendedCondition(x):
                    l.append(x)
            except dbus.exceptions.DBusException:
                return None
    return l
Example #14
0
def idf_install(name, s, force=True):
    if idf_exists(name):
        return False
    unique_id = _IDF_UNIQUE_ID_MAGIC + name
    proxy = when_proxy()
    if proxy is None:
        return False
    items = idf_items(s)
    if items is None:
        return False
    if not proxy.AddItemsBatch(s):
        return False
    datastore.put(unique_id, json.dumps(items))
    return True
Example #15
0
def retrieve_plugin_ids_suspended():
    proxy = when_proxy()
    if proxy is None:
        return None
    l = []
    for x in retrieve_plugin_ids():
        data = retrieve_plugin_data(x)
        if data['plugin_type'] == PLUGIN_CONST.PLUGIN_TYPE_CONDITION:
            try:
                if proxy.IsSuspendedCondition(x):
                    l.append(x)
            except dbus.exceptions.DBusException:
                return None
    return l
Example #16
0
def retrieve_association_ids_suspended():
    proxy = when_proxy()
    if proxy is None:
        return None
    l = []
    for unique_id in datastore:
        if unique_id.startswith(_PLUGIN_ASSOCIATION_ID_MAGIC):
            data = retrieve_association(unique_id)
            cond = data[0]
            try:
                if proxy.IsSuspendedCondition(cond):
                    l.append(unique_id)
            except dbus.exceptions.DBusException:
                return None
    return l
Example #17
0
def retrieve_association_ids_suspended():
    proxy = when_proxy()
    if proxy is None:
        return None
    l = []
    for unique_id in datastore:
        if unique_id.startswith(_PLUGIN_ASSOCIATION_ID_MAGIC):
            data = retrieve_association(unique_id)
            cond = data[0]
            try:
                if proxy.IsSuspendedCondition(cond):
                    l.append(unique_id)
            except dbus.exceptions.DBusException:
                return None
    return l
Example #18
0
def register_plugin_data(plugin):
    proxy = when_proxy()
    if proxy is None:
        return False
    data = plugin.to_item_dict()

    # filter empty lists and dictionaries, because DBus will complain
    # that it cannot determine the type otherwise; When has become smart
    # enough to fall back to the default (that is, an empty structure)
    # if it does not find a key in a definition dictionary
    data = dbus.Dictionary({
        key: data[key] for key in data
        if data[key] is not None and not (
            (isinstance(data[key], dict) or
             isinstance(data[key], list)) and not data[key])}, 'sv')
    try:
        if not proxy.AddItemByDefinition(data, True):
            return False
        return True
    except dbus.exceptions.DBusException:
        return False
Example #19
0
def register_plugin_data(plugin):
    proxy = when_proxy()
    if proxy is None:
        return False
    data = plugin.to_item_dict()

    # filter empty lists and dictionaries, because DBus will complain
    # that it cannot determine the type otherwise; When has become smart
    # enough to fall back to the default (that is, an empty structure)
    # if it does not find a key in a definition dictionary
    data = dbus.Dictionary(
        {
            key: data[key]
            for key in data if data[key] is not None and not (
                (isinstance(data[key], dict) or isinstance(data[key], list))
                and not data[key])
        }, 'sv')
    try:
        if not proxy.AddItemByDefinition(data, True):
            return False
        return True
    except dbus.exceptions.DBusException:
        return False
Example #20
0
def retrieve_action_history():
    proxy = when_proxy()
    if proxy is None:
        return None
    history = []
    when_history = proxy.GetHistoryEntries()
    when_history.reverse()
    for x in when_history:
        e = x.split(';')
        if e[3].startswith(_PLUGIN_UNIQUE_ID_MAGIC) and \
           e[4].startswith(_PLUGIN_UNIQUE_ID_MAGIC):
            plugin_task = retrieve_plugin(e[3])
            plugin_cond = retrieve_plugin(e[4])
            if plugin_task and plugin_cond:
                d = {
                    'datetime':
                    e[1],
                    'duration':
                    float(e[2]),
                    'task_id':
                    e[3],
                    'task_name':
                    plugin_task.name,
                    'task_icon':
                    load_pixbuf(plugin_task.icon, not plugin_task.stock),
                    'cond_id':
                    e[4],
                    'cond_name':
                    plugin_cond.name,
                    'cond_icon':
                    load_pixbuf(plugin_cond.icon, not plugin_cond.stock),
                    'success':
                    bool(e[5] == 'success'),
                }
                history.append(d)
    return history