1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# Copyright (C) 2009 Canonical
#
# Authors:
# Michael Vogt
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 3.
#
# This program 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
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import dbus
import dbus.service
import logging
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
from gi.repository import GObject
from .database import StoreDatabase
from .application import Application
# To test, run with e.g.
# dbus-send --session --type=method_call \
# --dest=com.ubuntu.SoftwareCenterDataProvider --print-reply \
# /com/ubuntu/SoftwareCenterDataProvider
# com.ubuntu.SoftwareCenterDataProvider.GetAppDetails string:"" string:"apt"
#
LOG = logging.getLogger(__file__)
class SoftwareCenterDataProvider(dbus.service.Object):
def __init__(self, bus_name,
object_path='/com/ubuntu/SoftwareCenterDataProvider'):
dbus.service.Object.__init__(self, bus_name, object_path)
self.bus_name = bus_name
self.db = StoreDatabase()
self.db.open()
self.db._aptcache.open(blocking=True)
def stop(self):
""" stop the dbus controller and remove from the bus """
self.remove_from_connection()
@dbus.service.method('com.ubuntu.SoftwareCenterDataProvider',
in_signature='ss', out_signature='a{sv}')
def GetAppDetails(self, appname, pkgname):
LOG.debug("ShowDetails() called with ('%s', '%s')" % (
appname, pkgname))
app = Application(appname, pkgname)
appdetails = app.get_details(self.db)
return appdetails.as_property_dict()
def dbus_main():
bus = dbus.SessionBus()
bus_name = dbus.service.BusName(
'com.ubuntu.SoftwareCenterDataProvider', bus)
data_provider = SoftwareCenterDataProvider(bus_name)
data_provider # pyflakes
main_context = GObject.main_context_default()
main_loop = GObject.MainLoop(main_context)
main_loop.run()
|