~verterok/ubuntuone-client/volumemanager_udfs-2

« back to all changes in this revision

Viewing changes to ubuntuone/syncdaemon/dbus_interface.py

  • Committer: Tarmac
  • Author(s): guillermo.gonzalez at canonical
  • Date: 2009-12-17 13:10:22 UTC
  • mfrom: (289.1.3 dbus-iface-docs)
  • Revision ID: john.lenton@canonical.com-20091217131022-1h4mlsys313hr0sl
export method and signal docstrings via DBus Introspect, add script to generate a simple text file with SyncDaemon DBus API

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from dbus import DBusException
24
24
from itertools import groupby, chain
 
25
from xml.etree import ElementTree
25
26
 
26
27
from twisted.internet import defer
27
28
from twisted.python.failure import Failure
90
91
        """ emit's a Error signal. """
91
92
        self.SignalError(signal, extra_args)
92
93
 
 
94
    @classmethod
 
95
    def _add_docstring(cls, func, reflection_data):
 
96
        """add <docstring> tag to reflection_data if func.__doc__ isn't None."""
 
97
        # add docstring element
 
98
        if getattr(func, '__doc__', None) is not None:
 
99
 
 
100
            element = ElementTree.fromstring(reflection_data)
 
101
            doc = element.makeelement('docstring', dict())
 
102
            data = '<![CDATA[' + func.__doc__ + ']]>'
 
103
            doc.text = '%s'
 
104
            element.insert(0, doc)
 
105
            return ElementTree.tostring(element) % data
 
106
        else:
 
107
            return reflection_data
 
108
 
 
109
    @classmethod
 
110
    def _reflect_on_method(cls, func):
 
111
        """override _reflect_on_method to provide an extra <docstring> element
 
112
        in the xml.
 
113
        """
 
114
        reflection_data = dbus.service.Object._reflect_on_method(func)
 
115
        reflection_data = cls._add_docstring(func, reflection_data)
 
116
        return reflection_data
 
117
 
 
118
    @classmethod
 
119
    def _reflect_on_signal(cls, func):
 
120
        reflection_data = dbus.service.Object._reflect_on_signal(func)
 
121
        reflection_data = cls._add_docstring(func, reflection_data)
 
122
        return reflection_data
 
123
 
93
124
 
94
125
class Status(DBusExposedObject):
95
126
    """ Represent the status of the syncdaemon """