Calum Lind 535b13b5f1 [Plugins] Convert plugins to deluge_ module prefix convention
This commit reverts namespace for the plugins and uses a module prefix
"deluge_" in it's place. The distribution package name remains the same
for now but will also be considered to use a prefix to help find the
third-party plugins e.g. Deluge-{Plugin} and the pluginmanager will
strip the prefix for displaying.

The change is a result of problems trying to package Deluge with
pyinstaller and the pkg_resources namespaces is not compatible.
Testing alternatives to using the pkgutil or PEP420 (native) namespaces
did not yield any joy either as importing eggs with namespaces does not
work. [1]

At this point importable eggs are considered deprecated but there is no
viable alternative yet. [2]

[1] https://github.com/pypa/packaging-problems/issues/212
[2] https://github.com/pypa/packaging-problems/issues/244
2019-05-15 19:20:08 +01:00

90 lines
3.5 KiB
Python

# -*- coding: utf-8 -*-
# vim: sw=4 ts=4 fenc=utf-8 et
# ==============================================================================
# Copyright © 2009-2010 UfSoft.org - Pedro Algarvio <pedro@algarvio.me>
#
# License: BSD - Please view the LICENSE file for additional information.
# ==============================================================================
from __future__ import unicode_literals
import logging
from twisted.internet import task
from deluge import component
from deluge.event import DelugeEvent
log = logging.getLogger(__name__)
class FooEvent(DelugeEvent):
"""foo Event"""
class CustomEvent(DelugeEvent):
"""Just a custom event to test"""
class TestEmailNotifications(component.Component):
def __init__(self, imp):
component.Component.__init__(self, self.__class__.__name__, 5)
self.__imp = imp
self.lc = task.LoopingCall(self.update)
self.n = 1
self.events = [FooEvent(), CustomEvent()]
self.events_classes = []
def enable(self):
log.debug('\n\nEnabling %s', self.__class__.__name__)
for event in self.events:
if self.__imp == 'core':
# component.get('CorePlugin.Notifications').register_custom_email_notification(
component.get('Notifications').register_custom_email_notification(
event.__class__.__name__, self.custom_email_message_provider
)
elif self.__imp == 'gtk':
notifications_component = component.get('Notifications')
notifications_component.register_custom_popup_notification(
event.__class__.__name__, self.custom_popup_message_provider
)
notifications_component.register_custom_blink_notification(
event.__class__.__name__, self.custom_blink_message_provider
)
notifications_component.register_custom_sound_notification(
event.__class__.__name__, self.custom_sound_message_provider
)
self.lc.start(60, False)
def disable(self):
log.debug('\n\nDisabling %s', self.__class__.__name__)
self.lc.stop()
def update(self):
if self.__imp == 'core':
log.debug('\n\nUpdating %s', self.__class__.__name__)
self.events.append(self.events.pop(0)) # Re-Queue
self.n += 1
component.get('EventManager').emit(self.events[0])
def custom_email_message_provider(self, *evt_args, **evt_kwargs):
log.debug('Running custom email message provider: %s %s', evt_args, evt_kwargs)
subject = '%s Email Subject: %s' % (self.events[0].__class__.__name__, self.n)
message = '%s Email Message: %s' % (self.events[0].__class__.__name__, self.n)
return subject, message
def custom_popup_message_provider(self, *evt_args, **evt_kwargs):
log.debug('Running custom popup message provider: %s %s', evt_args, evt_kwargs)
title = '%s Popup Title: %s' % (self.events[0].__class__.__name__, self.n)
message = '%s Popup Message: %s' % (self.events[0].__class__.__name__, self.n)
return title, message
def custom_blink_message_provider(self, *evt_args, **evt_kwargs):
log.debug('Running custom blink message provider: %s %s', evt_args, evt_kwargs)
return True
def custom_sound_message_provider(self, *evt_args, **evt_kwargs):
log.debug('Running custom sound message provider: %s %s', evt_args, evt_kwargs)
return ''