Skip to content

Commit

Permalink
[v2.0] Support for Deluge v2
Browse files Browse the repository at this point in the history
  • Loading branch information
bendikro committed Oct 17, 2019
1 parent 4b4fad3 commit 981e53b
Show file tree
Hide file tree
Showing 23 changed files with 424 additions and 1,218 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ $ python setup.py bdist_egg

## Changelog ##

v2.0 - 2019-10-17

* Support for Deluge v2

v1.2 - 2015-11-13

* Moved interface checking to background thread
Expand All @@ -27,5 +31,3 @@ v1.1 - 2015-09-27
v1.0 - 2015-09-27

* Support for unix hosts with pyiface

(Tested with Deluge 1.3.11)
20 changes: 9 additions & 11 deletions ifacewatch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2012-2015 bendikro [email protected]
#
# Based on work by:
# Copyright (C) 2009 Camillo Dell'mour <[email protected]>
# Copyright (C) 2012-2015 bendikro [email protected]
#
# Basic plugin template created by:
# Copyright (C) 2008 Martijn Voncken <[email protected]>
# Copyright (C) 2007-2009 Andrew Resch <[email protected]>
# Copyright (C) 2009 Damien Churchill <[email protected]>
#
# This file is part of YaRSS2 and is licensed under GNU General Public License 3.0, or later, with
# This file is part of IfaceWatch and is licensed under GNU General Public License 3.0, or later, with
# the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details.
#

import sys

import pkg_resources

from deluge.plugins.init import PluginInitBase

import ifacewatch.util.logger
Expand All @@ -30,21 +28,21 @@ def load_libs():
for name in egg.get_entry_map("ifacewatch.libpaths"):
ep = egg.get_entry_info("ifacewatch.libpaths", name)
location = "%s/%s" % (egg.location, ep.module_name.replace(".", "/"))
sys.path.append(location)
log.info("Appending to sys.path: '%s'" % location)
if location not in sys.path:
sys.path.append(location)


class CorePlugin(PluginInitBase):
def __init__(self, plugin_name):
load_libs()
from core import Core as CorePluginClass
from .core import Core as CorePluginClass
self._plugin_cls = CorePluginClass
super(CorePlugin, self).__init__(plugin_name)


class GtkUIPlugin(PluginInitBase):
class Gtk3UIPlugin(PluginInitBase):
def __init__(self, plugin_name):
load_libs()
from gtkui.gtkui import GtkUI as GtkUIPluginClass
from .gtk3ui.gtkui import GtkUI as GtkUIPluginClass
self._plugin_cls = GtkUIPluginClass
super(GtkUIPlugin, self).__init__(plugin_name)
super(Gtk3UIPlugin, self).__init__(plugin_name)
37 changes: 22 additions & 15 deletions ifacewatch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,25 @@

import platform

from twisted.internet import threads
from twisted.internet.task import LoopingCall

import deluge.common
import deluge.component as component
from deluge.core.rpcserver import export
from deluge.plugins.pluginbase import CorePluginBase
from twisted.internet import threads
from twisted.internet.task import LoopingCall

import ifacewatch.util.common
import ifacewatch.util.logger
import ifcfg
import pyiface.iface
from ifacewatch.ifacewatch_config import IfacewatchConfig
from ifacewatch.lib import ifcfg
from ifacewatch.lib.pyiface.iface import Interface
from ifacewatch.util.common import IfaceWatchIPChangedEvent
from ifacewatch.util import common, logger


class Core(CorePluginBase):

def __init__(self, name):
"""Used for tests only"""
if name is not "test":
if name != "test":
super(Core, self).__init__(name)
else:
# To avoid warnings when running tests
Expand All @@ -38,7 +37,7 @@ def __init__(self, name):
self.config = None
self.is_checking = False
self.ip = None
self.log = ifacewatch.util.logger.Logger()
self.log = logger.Logger()
self.core = component.get("Core")
self.core.config.register_set_function("listen_interface", self.interface_changed)

Expand All @@ -49,7 +48,8 @@ def interface_changed(self, iface, ip):
self.ip = ip

def emit(ip):
component.get("EventManager").emit(IfaceWatchIPChangedEvent(ip))
component.get("EventManager").emit(common.IfaceWatchIPChangedEvent(ip))

# Only emit while plugin is enabled
if self.config is not None:
emit(ip)
Expand All @@ -59,7 +59,7 @@ def enable(self, config=None):
self.config = IfacewatchConfig(self.log)
else:
self.config = config
self.log.info("Enabled Iface Watch %s" % ifacewatch.util.common.get_version())
self.log.info("Enabled Iface Watch %s" % common.get_version())

self.scheduler_timer()
self.check_interface()
Expand Down Expand Up @@ -95,12 +95,12 @@ def _check_interface(self, *args, **kwargs):
iface = self.config.get_config()["interface"]
if iface.strip():
try:
for interface in ifcfg.interfaces().itervalues():
for interface in ifcfg.interfaces().values():
if interface["device"] == iface:
ip = interface["inet"]
break
if ip is None and platform.system() == "Linux":
iff = Interface(name=str(iface))
iff = pyiface.iface.Interface(name=str(iface))
ip = iff.ip_str()
if ip is not None and not deluge.common.is_ip(ip):
self.log.info("Invalid IP returned for interface '%s': %s" % (iface, ip), gtkui=True)
Expand Down Expand Up @@ -142,6 +142,13 @@ def get_ip(self):
"""Returns the config dictionary"""
return self.core.get_config_value("listen_interface")

@export
def get_interfaces(self):
ifaces = []
for name, interface in ifcfg.interfaces().items():
ifaces.append(name)
return ifaces

@export
def get_config(self):
"""Returns the config dictionary"""
Expand All @@ -150,8 +157,8 @@ def get_config(self):
@export
def save_config(self, config):
newiface = "interface" in config and config["interface"] != self.config.get_config()["interface"]
newinterval = ("update_interval" in config and
config["update_interval"] != self.config.get_config()["update_interval"])
newinterval = ("update_interval" in config
and config["update_interval"] != self.config.get_config()["update_interval"])
newstate = config["active"] != self.config.get_config()["active"]
self.config.set_config(config)
if newstate and config["active"] is True:
Expand Down
Loading

0 comments on commit 981e53b

Please sign in to comment.