2007-02-16 04:48:48 +00:00
|
|
|
#!/usr/bin/env python
|
2006-11-30 23:04:59 +00:00
|
|
|
#
|
|
|
|
# deluge
|
|
|
|
# Copyright (C) Zach Tibbitts 2006 <zach@collegegeek.org>
|
|
|
|
# Copyright (C) Alon Zakai 2006 <kripkensteiner@gmail.com>
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Deluge is free software.
|
|
|
|
#
|
|
|
|
# You may redistribute it and/or modify it under the terms of the
|
|
|
|
# GNU General Public License, as published by the Free Software
|
|
|
|
# Foundation; either version 2 of the License, or (at your option)
|
|
|
|
# any later version.
|
|
|
|
#
|
|
|
|
# deluge is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
# See the GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with deluge. If not, write to:
|
|
|
|
# The Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor
|
|
|
|
# Boston, MA 02110-1301, USA.
|
2007-06-12 16:33:32 +00:00
|
|
|
#
|
|
|
|
# In addition, as a special exception, the copyright holders give
|
|
|
|
# permission to link the code of portions of this program with the OpenSSL
|
|
|
|
# library.
|
|
|
|
# You must obey the GNU General Public License in all respects for all of
|
|
|
|
# the code used other than OpenSSL. If you modify file(s) with this
|
|
|
|
# exception, you may extend this exception to your version of the file(s),
|
|
|
|
# but you are not obligated to do so. If you do not wish to do so, delete
|
|
|
|
# this exception statement from your version. If you delete this exception
|
|
|
|
# statement from all source files in the program, then also delete it here.
|
2006-11-30 23:04:59 +00:00
|
|
|
|
|
|
|
from optparse import OptionParser
|
2007-01-12 20:07:55 +00:00
|
|
|
import sys
|
|
|
|
import os, os.path
|
2007-03-05 22:30:54 +00:00
|
|
|
import gettext, locale
|
2007-03-27 22:13:09 +00:00
|
|
|
import deluge, deluge.common, deluge.interface
|
2007-02-26 20:39:35 +00:00
|
|
|
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
|
2006-11-30 23:04:59 +00:00
|
|
|
|
2007-03-05 20:53:22 +00:00
|
|
|
|
2007-03-27 22:20:57 +00:00
|
|
|
parser = OptionParser(usage="%prog [options] [actions]", version=deluge.common.PROGRAM_VERSION)
|
2007-03-05 20:53:22 +00:00
|
|
|
parser.add_option("--tray", dest="tray", help="start Deluge hidden in system tray",
|
|
|
|
metavar="TRAY", action="store_true")
|
2007-06-09 23:50:10 +00:00
|
|
|
parser.add_option("--url", dest="url", help="Load a torrent from a URL",
|
|
|
|
metavar="URL", action="store")
|
2007-03-05 20:53:22 +00:00
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
|
|
|
|
2007-06-09 23:50:10 +00:00
|
|
|
def start_deluge():
|
|
|
|
print "Starting new Deluge session..."
|
|
|
|
interface = deluge.interface.DelugeGTK()
|
|
|
|
add_args(interface)
|
2007-06-12 02:21:18 +00:00
|
|
|
interface.start()
|
2007-01-12 20:07:55 +00:00
|
|
|
|
|
|
|
|
2007-06-09 23:50:10 +00:00
|
|
|
def add_args(interface):
|
|
|
|
if options.url:
|
|
|
|
interface.external_add_url(options.url)
|
|
|
|
else:
|
2007-02-26 20:39:35 +00:00
|
|
|
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"
|
2007-06-09 23:50:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
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()
|
2007-02-26 20:39:35 +00:00
|
|
|
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"
|
2007-06-09 23:50:10 +00:00
|
|
|
|
|
|
|
add_args(deluge_iface)
|
|
|
|
|
2007-02-26 20:39:35 +00:00
|
|
|
else:
|
2007-01-12 20:07:55 +00:00
|
|
|
print "no existing Deluge session"
|
2007-06-09 23:50:10 +00:00
|
|
|
start_deluge()
|