Changed from Pyro to DBUS.. Still doesn't do anything.

This commit is contained in:
Andrew Resch 2007-07-08 00:28:17 +00:00
parent 29c4b6aee1
commit 59656397d0
5 changed files with 89 additions and 53 deletions

View File

@ -33,6 +33,21 @@
import logging import logging
try:
import dbus, dbus.service
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 gobject
from deluge.config import Config from deluge.config import Config
import deluge.common import deluge.common
@ -42,11 +57,18 @@ log = logging.getLogger("deluge")
DEFAULT_PREFS = { DEFAULT_PREFS = {
} }
class Core: class Core(dbus.service.Object):
def __init__(self): def __init__(self, path="/org/deluge_torrent/Core"):
log.debug("Core init..") log.debug("Core init..")
bus_name = dbus.service.BusName("org.deluge_torrent.Deluge",
bus=dbus.SessionBus())
dbus.service.Object.__init__(self, bus_name, path)
self.config = Config("core.conf", DEFAULT_PREFS) self.config = Config("core.conf", DEFAULT_PREFS)
log.debug("Starting main loop..")
loop = gobject.MainLoop()
loop.run()
@dbus.service.method("org.deluge_torrent.Deluge")
def test(self): def test(self):
print "test" print "test"

View File

@ -30,11 +30,21 @@
# but you are not obligated to do so. If you do not wish to do so, delete # 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 # this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here. # statement from all source files in the program, then also delete it here.
try:
import dbus, dbus.service
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 logging import logging
import Pyro.core
from deluge.core import Core from deluge.core import Core
# Get the logger # Get the logger
@ -42,22 +52,15 @@ log = logging.getLogger("deluge")
class Daemon: class Daemon:
def __init__(self): def __init__(self):
# Instantiate the Manager class # Check to see if the daemon is already running and if not, start it
bus = dbus.SessionBus()
obj = bus.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus")
iface = dbus.Interface(obj, "org.freedesktop.DBus")
if iface.NameHasOwner("org.deluge_torrent.Deluge"):
# Daemon is running so lets tell the user
log.info("Daemon is already running..")
else:
# Daemon is not running so lets start up the core
log.debug("Daemon is not running..")
self.core = Core() self.core = Core()
# Initialize the Pyro core and daemon
Pyro.core.initServer(banner=0)
log.debug("Pyro server initiliazed..")
self.daemon = Pyro.core.Daemon()
# Connect the Manager to the Pyro server
obj = Pyro.core.ObjBase()
obj.delegateTo(self.core)
self.uri = self.daemon.connect(obj, "core")
log.debug("uri: %s", self.uri)
def start(self):
# Start the main loop for the pyro daemon
self.daemon.requestLoop()
def get_uri(self):
# Return the URI for the Pyro server
return self.uri

View File

@ -76,18 +76,19 @@ def main():
# Start the daemon # Start the daemon
if options.daemon: if options.daemon:
log.info("Starting daemon..") log.info("Starting daemon..")
daemon = Daemon()
uri = daemon.get_uri()
# We need to fork() the process to run it in the background... # We need to fork() the process to run it in the background...
# FIXME: We cannot use fork() on Windows # FIXME: We cannot use fork() on Windows
pid = os.fork() pid = os.fork()
if not pid: if not pid:
daemon.start() # Since we are starting daemon this process will not start a UI
options.ui = False
# Create the daemon object
daemon = Daemon()
# Start the UI # Start the UI
if options.ui: if options.ui:
log.info("Starting ui..") log.info("Starting ui..")
ui = Ui(uri) ui = Ui()
# Stop Deluge # Stop Deluge
log.info ("Stopping Deluge..") log.info ("Stopping Deluge..")

View File

@ -33,18 +33,31 @@
import logging import logging
import Pyro.core try:
import dbus, dbus.service
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
# Get the logger # Get the logger
log = logging.getLogger("deluge") log = logging.getLogger("deluge")
class Ui: class Ui:
def __init__(self, core_uri): def __init__(self):
log.debug("Ui init..") log.debug("Ui init..")
log.debug("core_uri: %s", core_uri) log.debug("Getting core proxy object from DBUS..")
# Get the core manager from the Pyro server # Get the proxy object from DBUS
if core_uri != None: bus = dbus.SessionBus()
self.core = Pyro.core.getProxyForURI(core_uri) proxy = bus.get_object("org.deluge_torrent.Deluge",
# Test "/org/deluge_torrent/Core")
self.core = dbus.Interface(proxy, "org.deluge_torrent.Deluge")
log.debug("Got core proxy object..")
# Test the interface.. this calls test() in Core
self.core.test() self.core.test()

View File

@ -38,7 +38,7 @@ import glob
python_version = platform.python_version()[0:3] python_version = platform.python_version()[0:3]
# The libtorrent extension # The libtorrent extension
__extra_compile_args = [ _extra_compile_args = [
"-Wno-missing-braces", "-Wno-missing-braces",
"-DHAVE_INCLUDE_LIBTORRENT_ASIO____ASIO_HPP=1", "-DHAVE_INCLUDE_LIBTORRENT_ASIO____ASIO_HPP=1",
"-DHAVE_INCLUDE_LIBTORRENT_ASIO_SSL_STREAM_HPP=1", "-DHAVE_INCLUDE_LIBTORRENT_ASIO_SSL_STREAM_HPP=1",
@ -48,14 +48,14 @@ __extra_compile_args = [
"-DHAVE_SSL=1" "-DHAVE_SSL=1"
] ]
__include_dirs = [ _include_dirs = [
'./libtorrent', './libtorrent',
'./libtorrent/include', './libtorrent/include',
'./libtorrent/include/libtorrent', './libtorrent/include/libtorrent',
'/usr/include/python' + python_version '/usr/include/python' + python_version
] ]
__libraries = [ _libraries = [
'boost_filesystem', 'boost_filesystem',
'boost_date_time', 'boost_date_time',
'boost_thread', 'boost_thread',
@ -64,26 +64,25 @@ __libraries = [
'ssl' 'ssl'
] ]
__sources = glob.glob("./libtorrent/src/*.cpp") + glob.glob("./libtorrent/src/kademelia/*.cpp") + glob.glob("./libtorrent/bindings/python/src/*.cpp") _sources = glob.glob("./libtorrent/src/*.cpp") + glob.glob("./libtorrent/src/kademelia/*.cpp") + glob.glob("./libtorrent/bindings/python/src/*.cpp")
# Remove file_win.cpp as it is only for Windows builds # Remove file_win.cpp as it is only for Windows builds
for source in __sources: for source in _sources:
if "file_win.cpp" in source: if "file_win.cpp" in source:
__sources.remove(source) _sources.remove(source)
break break
libtorrent = Extension( libtorrent = Extension(
'libtorrent', 'libtorrent',
include_dirs = __include_dirs, include_dirs = _include_dirs,
libraries = __libraries, libraries = _libraries,
extra_compile_args = __extra_compile_args, extra_compile_args = _extra_compile_args,
sources = __sources sources = _sources
) )
print find_packages("deluge")
# Main setup # Main setup
__data_files = [ _data_files = [
# ('share/deluge/glade', glob.glob("share/deluge/glade/*.glade")), # ('share/deluge/glade', glob.glob("share/deluge/glade/*.glade")),
# ('share/deluge/pixmaps', glob.glob('share/deluge/pixmaps/*.png')), # ('share/deluge/pixmaps', glob.glob('share/deluge/pixmaps/*.png')),
('share/applications' , ["deluge/share/applications/deluge.desktop"]), ('share/applications' , ["deluge/share/applications/deluge.desktop"]),
@ -100,10 +99,8 @@ setup(
url = "http://deluge-torrent.org", url = "http://deluge-torrent.org",
license = "GPLv2", license = "GPLv2",
# packages = find_packages("deluge"),
include_package_data = True, include_package_data = True,
#scripts = ["scripts/deluge"], data_files = _data_files,
data_files = __data_files,
ext_package = "deluge", ext_package = "deluge",
ext_modules = [libtorrent], ext_modules = [libtorrent],
packages=['deluge'], packages=['deluge'],