Skip to content
Browse files

New release 0.3.0

- Replace GetTask() method by methods for each task in main d-bus path
- Add setup.cfg to populate /usr/share/mandriva (instead of convetional
  /usr/lib/python)
- Fix examples to match new d-bus interface
  • Loading branch information...
1 parent 17754bc commit fae5d115d2270d531c8684832520c93297e1974a J. Victor Martins committed Mar 15, 2011
Showing with 50 additions and 38 deletions.
  1. +1 −1 doc/examples/list_media.py
  2. +4 −9 doc/examples/task.py
  3. +1 −1 mdvpkg/__init__.py
  4. +40 −18 mdvpkg/daemon.py
  5. +4 −9 mdvpkg/tasks.py
View
2 doc/examples/list_media.py
@@ -10,7 +10,7 @@
bus = dbus.SystemBus()
proxy = bus.get_object(mdvpkg.DBUS_SERVICE, mdvpkg.DBUS_PATH)
-task_path = proxy.GetTask('ListMedia', dbus_interface=mdvpkg.DBUS_INTERFACE)
+task_path = proxy.ListMedias(dbus_interface=mdvpkg.DBUS_INTERFACE)
def media_cb(*args):
print 'media %s (update=%s, ignore=%s)' % args
View
13 doc/examples/task.py
@@ -30,15 +30,10 @@ def signal_cb(*args, **kwargs):
member_keyword='signal')
proxy = bus.get_object(mdvpkg.DBUS_SERVICE, mdvpkg.DBUS_PATH)
-task_path = proxy.GetTask(task_name, dbus_interface=mdvpkg.DBUS_INTERFACE)
+task_path = getattr(proxy, task_name)(dbus_interface=mdvpkg.DBUS_INTERFACE,
+ *sys.argv[2:])
-proxy = bus.get_object(mdvpkg.DBUS_SERVICE, task_path)
-iface = dbus.Interface(proxy, dbus_interface=mdvpkg.DBUS_TASK_INTERFACE)
+task_proxy = bus.get_object(mdvpkg.DBUS_SERVICE, task_path)
+task_proxy.Run(dbus_interface=mdvpkg.DBUS_TASK_INTERFACE)
-for cmd in sys.argv[2:]:
- (name, args) = cmd.split('=')
- method = getattr(iface, name)
- method(*args.split(','))
-
-iface.Run()
loop.run()
View
2 mdvpkg/__init__.py
@@ -22,7 +22,7 @@
__author__ = "J. Victor Martins <jvdm@mandriva.com>"
__state__ = "development"
-__version__ = "0.2.1"
+__version__ = "0.2.2"
DBUS_SERVICE = 'org.mandrivalinux.mdvpkg'
DBUS_INTERFACE = 'org.mandrivalinux.mdvpkg'
View
58 mdvpkg/daemon.py
@@ -68,26 +68,48 @@ def run(self):
self._loop.run()
@dbus.service.method(mdvpkg.DBUS_INTERFACE,
+ in_signature='',
+ out_signature='s',
+ sender_keyword='sender')
+ def ListMedias(self, sender):
+ return self._create_task(mdvpkg.tasks.ListMediasTask,
+ sender)
+
+ @dbus.service.method(mdvpkg.DBUS_INTERFACE,
+ in_signature='',
+ out_signature='s',
+ sender_keyword='sender')
+ def ListGroups(self, sender):
+ return self._create_task(mdvpkg.tasks.ListGroupsTask,
+ sender)
+
+ @dbus.service.method(mdvpkg.DBUS_INTERFACE,
+ in_signature='',
+ out_signature='s',
+ sender_keyword='sender')
+ def ListPackages(self, sender):
+ return self._create_task(mdvpkg.tasks.ListPackagesTask,
+ sender)
+
+ @dbus.service.method(mdvpkg.DBUS_INTERFACE,
in_signature='s',
out_signature='s',
sender_keyword='sender')
- def GetTask(self, task_name, sender):
- """ Create a new task and return it's path."""
- return self._create_task(task_name, sender)
+ def PackageDetails(self, name, sender):
+ return self._create_task(mdvpkg.tasks.PackageDetailsTask,
+ sender,
+ name)
- def _create_task(self, name, sender):
- print 'Request task: %s, %s' % (name, sender)
- klass = self._get_task_class(name)
- task = klass(self._bus, sender, self._worker)
+ @dbus.service.method(mdvpkg.DBUS_INTERFACE,
+ in_signature='as',
+ out_signature='s',
+ sender_keyword='sender')
+ def SearchFiles(self, files, sender):
+ return self._create_task(mdvpkg.tasks.SearchFilesTask,
+ sender,
+ files)
+
+ def _create_task(self, task_class, sender, *args):
+ print 'Request task: %s, %s' % (task_class.__name__, sender)
+ task = task_class(self._bus, sender, self._worker, *args)
return task.path
-
- def _get_task_class(self, name):
- """ Returns the class of a task by it's name. """
- try:
- klass = getattr(mdvpkg.tasks, '%sTask' % name)
- if klass != mdvpkg.tasks.TaskBase \
- and issubclass(klass, mdvpkg.tasks.TaskBase):
- return klass
- except AttributeError:
- pass
- raise mdvpkg.exceptions.UnknownTaskError()
View
13 mdvpkg/tasks.py
@@ -125,21 +125,16 @@ def worker_callback(self, backend):
class PackageDetailsTask(TaskBase):
""" Query for details of a package. """
+ def __init__(self, bus, sender, worker, name):
+ TaskBase.__init__(self, bus, sender, worker)
+ self.name = name
+
@dbus.service.signal(dbus_interface=mdvpkg.DBUS_TASK_INTERFACE,
signature='a{ss}')
def PackageDetails(self, details_dict):
pass
- @dbus.service.method(mdvpkg.DBUS_TASK_INTERFACE,
- in_signature='s',
- out_signature='',
- sender_keyword='sender')
- def SetName(self, name, sender):
- """ Set the package name to get details from. """
- self.name = name
-
def worker_callback(self, backend):
results = backend.do('package_details', name=self.name)
for details in results:
self.PackageDetails(details)
-

0 comments on commit fae5d11

Please sign in to comment.
Something went wrong with that request. Please try again.