Skip to content

Commit

Permalink
use json for returning non simple data types (GetAttribute, BuildTran…
Browse files Browse the repository at this point in the history
…saction)
  • Loading branch information
Tim Lauridsen committed Feb 12, 2011
1 parent 9459f2d commit 92d7db6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions yum-daemon/client.py
Expand Up @@ -19,6 +19,7 @@
import os
import dbus
import sys
import json
from datetime import date

DAEMON_ORG = 'org.baseurl.Yum'
Expand Down Expand Up @@ -95,7 +96,7 @@ def GetAttribute(self, id, attr):
elif result == ':not_found': # package not found
result = None # FIXME: maybe raise an exception
else:
result = eval(result)
result = json.loads(result)
return result

@catch_exception
Expand Down Expand Up @@ -223,10 +224,10 @@ def show_transaction_result(output):
res = cli.AddTransaction(id, action)
show_transaction_list(res)
print "Resolving dependencies"
rc, output = cli.BuildTransaction()
rc, output = json.loads(cli.BuildTransaction())
#print rc,output
if rc == 2:
show_transaction_result(eval(output))
show_transaction_result(output)
try:
print "Running the transaction"
cli.RunTransaction()
Expand Down
8 changes: 5 additions & 3 deletions yum-daemon/daemon.py
Expand Up @@ -22,6 +22,7 @@
import gobject
import os
import subprocess
import json
import yum
import yum.Errors as Errors
from urlgrabber.progress import format_number
Expand All @@ -30,6 +31,7 @@
from yum.constants import *



version = 100 # must be integer
DAEMON_ORG = 'org.baseurl.Yum'
DAEMON_INTERFACE = DAEMON_ORG+'.Interface'
Expand Down Expand Up @@ -252,7 +254,7 @@ def GetAttribute(self, id, attr,sender=None):
po = self._get_po(id)
if po:
if hasattr(po, attr):
value = repr(getattr(po,attr))
value = json.dumps(getattr(po,attr))
return value
else:
return ':none'
Expand Down Expand Up @@ -298,7 +300,7 @@ def AddTransaction(self, id, action, sender=None):

@dbus.service.method(DAEMON_INTERFACE,
in_signature='',
out_signature='is',
out_signature='s',
sender_keyword='sender')
def BuildTransaction(self, sender):
'''
Expand All @@ -311,7 +313,7 @@ def BuildTransaction(self, sender):
else:
output = msgs
self.TransactionEvent('end-build')
return rc,repr(output)
return json.dumps((rc,output))


@dbus.service.method(DAEMON_INTERFACE,
Expand Down

0 comments on commit 92d7db6

Please sign in to comment.