mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-13 11:48:40 +00:00
dbus fallback
This commit is contained in:
parent
0eb837ba18
commit
93378db25d
1 changed files with 47 additions and 31 deletions
|
@ -31,27 +31,56 @@ import os, os.path
|
||||||
parser = OptionParser(usage="%prog [options] [actions]", version="%prog 0.4.90.0")
|
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",
|
parser.add_option("--tray", dest="tray", help="start Deluge hidden in system tray",
|
||||||
metavar="TRAY", action="store_true")
|
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
|
if dbus_imported:
|
||||||
dbus_version = getattr(dbus, 'version', (0,0,0))
|
bus = dbus.SessionBus()
|
||||||
if dbus_version >= (0,41,0) and dbus_version < (0,80,0):
|
|
||||||
import dbus.glib
|
dbus_objects = dbus.Interface(bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus'), 'org.freedesktop.DBus').ListNames()
|
||||||
elif dbus_version >= (0,80,0):
|
|
||||||
from dbus.mainloop.glib import DBusGMainLoop
|
interface = None
|
||||||
DBusGMainLoop(set_as_default=True)
|
|
||||||
|
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:
|
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"
|
print "no existing Deluge session"
|
||||||
import deluge, deluge.delugegtk
|
import deluge, deluge.delugegtk
|
||||||
import gettext
|
import gettext
|
||||||
|
@ -65,16 +94,3 @@ if not "org.deluge_torrent.Deluge" in dbus_objects:
|
||||||
else:
|
else:
|
||||||
print "Error,", arg, " does not seem to be a .torrent file"
|
print "Error,", arg, " does not seem to be a .torrent file"
|
||||||
interface.start(hidden=options.tray)
|
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"
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue