Permalink
Browse files

- Add LisPackages and PackageDetails tasks.

- Fix backend interface to pass keyed arguments.
  • Loading branch information...
1 parent 177100d commit 8649acc88e97bb8dd8a83d4cdbd2de90b3be22cb J. Victor Martins committed Mar 11, 2011
Showing with 50 additions and 2 deletions.
  1. +45 −0 mdvpkg/tasks.py
  2. +5 −2 mdvpkg/worker.py
View
@@ -91,3 +91,48 @@ def worker_callback(self, backend):
for group in groups:
self.Group(*group)
self.Finished()
+
+
+class ListPackagesTask(TaskBase):
+ """ List all available packages. """
+
+ @dbus.service.signal(dbus_interface=mdvpkg.DBUS_TASK_INTERFACE,
+ signature='ssssssb')
+ def Package(self,
+ name,
+ version,
+ release,
+ disttag,
+ distepoch,
+ arch,
+ installed):
+ pass
+
+ def worker_callback(self, backend):
+ pkgs = backend.do('list_packages')
+ for pkg in pkgs:
+ self.Package(*pkg)
+ self.Finished()
+
+
+class PackageDetailsTask(TaskBase):
+ """ Query for details of a package. """
+
+ @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)
+ self.Finished()
View
@@ -57,14 +57,17 @@ def running(self):
return self.urpm.poll() == None
return False
- def do(self, cmd):
+ def do(self, cmd, **kwargs):
"""
Send a command to the backend and return a list of results.
Results are python objects, which were created from eval()'d
string returned by the backend.
"""
- self.urpm.stdin.write("%s\n" % cmd)
+ kwargs_line = ' '.join([ '='.join([ str(e) for e in pair ])
+ for pair in kwargs.items() ])
+
+ self.urpm.stdin.write("%s %s\n" % (cmd, kwargs_line))
results = []
while True:
l = self.urpm.stdout.readline().strip()

0 comments on commit 8649acc

Please sign in to comment.