Refactored the way dbus is imported.
This commit is contained in:
parent
3edd3280ae
commit
72fa2a44a5
|
@ -39,22 +39,10 @@ from optparse import OptionParser
|
|||
import re
|
||||
import sys
|
||||
|
||||
try:
|
||||
import dbus
|
||||
dbus_version = getattr(dbus, 'version', (0,0,0))
|
||||
if dbus_version >= (0,41,0) and dbus_version < (0,80,0):
|
||||
import dbus.glib
|
||||
elif dbus_version >= (0,80,0):
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
else:
|
||||
pass
|
||||
except: dbus_imported = False
|
||||
else: dbus_imported = True
|
||||
|
||||
import deluge
|
||||
import deluge.common
|
||||
import deluge.core
|
||||
import deluge._dbus as dbus
|
||||
import deluge.interface
|
||||
|
||||
parser = OptionParser(usage="%prog [options] [torrents to add]",
|
||||
|
@ -123,13 +111,11 @@ def start_deluge():
|
|||
|
||||
interface.start(get_cmd_line_torrents())
|
||||
|
||||
if dbus_imported:
|
||||
|
||||
bus = dbus.SessionBus()
|
||||
|
||||
dbus_objects = dbus.Interface(bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus'), 'org.freedesktop.DBus').ListNames()
|
||||
|
||||
interface = None
|
||||
|
||||
if not "org.deluge_torrent.Deluge" in dbus_objects:
|
||||
print "no existing Deluge session"
|
||||
start_deluge()
|
||||
|
@ -143,6 +129,3 @@ if dbus_imported:
|
|||
|
||||
for filename in get_cmd_line_torrents():
|
||||
deluge_iface.interactive_add_torrent(filename)
|
||||
else:
|
||||
print "no existing Deluge session"
|
||||
start_deluge()
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
# Import all we will use in deluge
|
||||
from dbus import Interface, SessionBus, version
|
||||
|
||||
# Code for dbus_importing borrowed from Listen (http://listen-project.org)
|
||||
# I couldn't figure out how to use dbus without breaking on versions past
|
||||
# 0.80.0. I finally found a solution by reading the source code from the
|
||||
# Listen project.
|
||||
if version >= (0,41,0) and version < (0,80,0):
|
||||
import dbus.glib
|
||||
elif version >= (0,80,0):
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
DBusGMainLoop(set_as_default=True)
|
|
@ -30,28 +30,9 @@
|
|||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
|
||||
|
||||
# Code for dbus_importing borrowed from Listen (http://listen-project.org)
|
||||
# I couldn't figure out how to use dbus without breaking on versions past
|
||||
# 0.80.0. I finally found a solution by reading the source code from the
|
||||
# Listen project.
|
||||
try:
|
||||
import dbus
|
||||
import deluge._dbus as dbus
|
||||
import dbus.service
|
||||
dbus_version = getattr(dbus, 'version', (0,0,0))
|
||||
if dbus_version >= (0,41,0) and dbus_version < (0,80,0):
|
||||
dbus.SessionBus()
|
||||
import dbus.glib
|
||||
elif dbus_version >= (0,80,0):
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
dbus.SessionBus()
|
||||
else:
|
||||
pass
|
||||
except: dbus_imported = False
|
||||
else: dbus_imported = True
|
||||
|
||||
if dbus_imported:
|
||||
class Manager(dbus.service.Object):
|
||||
def __init__(self, interface, object_path='/org/deluge_torrent/DelugeObject'):
|
||||
self.interface = interface
|
||||
|
@ -63,11 +44,3 @@ if dbus_imported:
|
|||
@dbus.service.method('org.deluge_torrent.Deluge')
|
||||
def interactive_add_torrent(self, torrent_file):
|
||||
self.interface.interactive_add_torrent(torrent_file)
|
||||
else:
|
||||
# This is a fallback class in case dbus is not available
|
||||
class Manager:
|
||||
def __init__(self, interface, object_path=None):
|
||||
self.interface = interface
|
||||
|
||||
def interactive_add_torrent(self, torrent_file):
|
||||
print "I can't do anything with this."
|
||||
|
|
Loading…
Reference in New Issue