diff --git a/scripts/deluge b/scripts/deluge index 51b30638b..a0bddb9f5 100755 --- a/scripts/deluge +++ b/scripts/deluge @@ -31,27 +31,56 @@ import os, os.path parser = OptionParser(usage="%prog [options] [actions]", version="%prog 0.4.90.0") parser.add_option("--tray", dest="tray", help="start Deluge hidden in system tray", metavar="TRAY", action="store_true") +try: + (options, args) = parser.parse_args() -(options, args) = parser.parse_args() + 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 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) +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" + import deluge, deluge.delugegtk + import gettext + gettext.install('deluge') + + interface = deluge.delugegtk.DelugeGTK() + for arg in args: + apath = os.path.abspath(arg) + if apath.endswith(".torrent"): + interface.external_add_torrent(apath) + else: + print "Error,", arg, " does not seem to be a .torrent file" + interface.start(hidden=options.tray) + else: + ## This connects to the deluge interface + print "create proxy object" + proxy = bus.get_object('org.deluge_torrent.Deluge', '/org/deluge_torrent/DelugeObject') + print "create iface" + deluge_iface = dbus.Interface(proxy, 'org.deluge_torrent.Deluge') + print "send to iface" + for arg in args: + apath = os.path.abspath(arg) + if apath.endswith(".torrent"): + deluge_iface.external_add_torrent(apath) + else: + print "Error,", arg, " does not seem to be a .torrent file" else: - pass - - -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" import deluge, deluge.delugegtk import gettext @@ -65,16 +94,3 @@ if not "org.deluge_torrent.Deluge" in dbus_objects: else: print "Error,", arg, " does not seem to be a .torrent file" interface.start(hidden=options.tray) -else: - ## This connects to the deluge interface - print "create proxy object" - proxy = bus.get_object('org.deluge_torrent.Deluge', '/org/deluge_torrent/DelugeObject') - print "create iface" - deluge_iface = dbus.Interface(proxy, 'org.deluge_torrent.Deluge') - print "send to iface" - for arg in args: - apath = os.path.abspath(arg) - if apath.endswith(".torrent"): - deluge_iface.external_add_torrent(apath) - else: - print "Error,", arg, " does not seem to be a .torrent file"