Adding support for coroutines for async ops through trampolines
[theonering] / hand_tests / hand_mcclient.py
1 #!/usr/bin/env python
2
3 import logging
4
5 import gobject
6 import dbus
7 import dbus.mainloop.glib
8
9
10 _moduleLogger = logging.getLogger(__name__)
11
12
13 class SetSecondaryVCardFields(object):
14
15         ACCOUNT_MGR_NAME = "org.freedesktop.Telepathy.AccountManager"
16         ACCOUNT_MGR_PATH = "/org/freedesktop/Telepathy/AccountManager"
17         ACCOUNT_MGR_IFACE_QUERY = "com.nokia.AccountManager.Interface.Query"
18         ACCOUNT_IFACE_COMPAT = "com.nokia.Account.Interface.Compat"
19         ACCOUNT_IFACE_COMPAT_PROFILE = "com.nokia.Account.Interface.Compat.Profile"
20         DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
21
22         def __init__(self, profileName):
23                 self._bus = dbus.SessionBus()
24                 self._profileName = profileName
25
26         def start(self):
27                 self._accountManager = self._bus.get_object(
28                         self.ACCOUNT_MGR_NAME,
29                         self.ACCOUNT_MGR_PATH,
30                 )
31                 self._accountManagerQuery = dbus.Interface(
32                         self._accountManager,
33                         dbus_interface=self.ACCOUNT_MGR_IFACE_QUERY,
34                 )
35
36                 self._accountManagerQuery.FindAccounts(
37                         {
38                                 self.ACCOUNT_IFACE_COMPAT_PROFILE: self._profileName,
39                         },
40                         reply_handler = self._on_found_accounts_reply,
41                         error_handler = self._on_error,
42                 )
43
44         def _on_found_accounts_reply(self, accountObjectPaths):
45                 for accountObjectPath in accountObjectPaths:
46                         print accountObjectPath
47                         account = self._bus.get_object(
48                                 self.ACCOUNT_MGR_NAME,
49                                 accountObjectPath,
50                         )
51                         accountProperties = dbus.Interface(
52                                 account,
53                                 self.DBUS_PROPERTIES,
54                         )
55                         accountProperties.Set(
56                                 self.ACCOUNT_IFACE_COMPAT,
57                                 "SecondaryVCardFields",
58                                 ["TEL"],
59                                 reply_handler = self._on_field_set,
60                                 error_handler = self._on_error,
61                         )
62
63         def _on_field_set(self):
64                 _moduleLogger.info("Field set")
65
66         def _on_error(self, error):
67                 _moduleLogger.error("%r" % (error, ))
68
69
70 if __name__ == "__main__":
71         logging.basicConfig(level=logging.DEBUG)
72         l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
73         manager = SetSecondaryVCardFields("theonering")
74
75         gobject.threads_init()
76         gobject.idle_add(manager.start)
77
78         mainloop = gobject.MainLoop(is_running=True)
79         mainloop.run()