395
395
logger.error(bad_states[state] + ": %r", error)
397
397
elif state == avahi.SERVER_RUNNING:
400
except dbus.exceptions.DBusException as error:
401
if (error.get_dbus_name()
402
== "org.freedesktop.Avahi.CollisionError"):
403
logger.info("Local Zeroconf service name"
405
return self.rename(remove=False)
407
logger.critical("D-Bus Exception", exc_info=error)
411
400
if error is None:
412
401
logger.debug("Unknown state: %r", state)
874
class DBusObjectWithAnnotations(dbus.service.Object):
875
"""A D-Bus object with annotations.
861
class DBusObjectWithProperties(dbus.service.Object):
862
"""A D-Bus object with properties.
877
Classes inheriting from this can use the dbus_annotations
878
decorator to add annotations to methods or signals.
864
Classes inheriting from this can use the dbus_service_property
865
decorator to expose methods as D-Bus properties. It exposes the
866
standard Get(), Set(), and GetAll() methods on the D-Bus.
897
885
for name, athing in
898
886
inspect.getmembers(cls, self._is_dbus_thing(thing)))
900
@dbus.service.method(dbus.INTROSPECTABLE_IFACE,
902
path_keyword = 'object_path',
903
connection_keyword = 'connection')
904
def Introspect(self, object_path, connection):
905
"""Overloading of standard D-Bus method.
907
Inserts annotation tags on methods and signals.
909
xmlstring = dbus.service.Object.Introspect(self, object_path,
912
document = xml.dom.minidom.parseString(xmlstring)
914
for if_tag in document.getElementsByTagName("interface"):
915
# Add annotation tags
916
for typ in ("method", "signal"):
917
for tag in if_tag.getElementsByTagName(typ):
919
for name, prop in (self.
920
_get_all_dbus_things(typ)):
921
if (name == tag.getAttribute("name")
922
and prop._dbus_interface
923
== if_tag.getAttribute("name")):
924
annots.update(getattr(
925
prop, "_dbus_annotations", {}))
926
for name, value in annots.items():
927
ann_tag = document.createElement(
929
ann_tag.setAttribute("name", name)
930
ann_tag.setAttribute("value", value)
931
tag.appendChild(ann_tag)
932
# Add interface annotation tags
933
for annotation, value in dict(
934
itertools.chain.from_iterable(
935
annotations().items()
936
for name, annotations
937
in self._get_all_dbus_things("interface")
938
if name == if_tag.getAttribute("name")
940
ann_tag = document.createElement("annotation")
941
ann_tag.setAttribute("name", annotation)
942
ann_tag.setAttribute("value", value)
943
if_tag.appendChild(ann_tag)
944
# Fix argument name for the Introspect method itself
945
if (if_tag.getAttribute("name")
946
== dbus.INTROSPECTABLE_IFACE):
947
for cn in if_tag.getElementsByTagName("method"):
948
if cn.getAttribute("name") == "Introspect":
949
for arg in cn.getElementsByTagName("arg"):
950
if (arg.getAttribute("direction")
952
arg.setAttribute("name",
954
xmlstring = document.toxml("utf-8")
956
except (AttributeError, xml.dom.DOMException,
957
xml.parsers.expat.ExpatError) as error:
958
logger.error("Failed to override Introspection method",
963
class DBusObjectWithProperties(DBusObjectWithAnnotations):
964
"""A D-Bus object with properties.
966
Classes inheriting from this can use the dbus_service_property
967
decorator to expose methods as D-Bus properties. It exposes the
968
standard Get(), Set(), and GetAll() methods on the D-Bus.
971
888
def _get_dbus_property(self, interface_name, property_name):
972
889
"""Returns a bound method if one exists which is a D-Bus
973
890
property with the specified name and interface.
1079
995
if prop._dbus_interface
1080
996
== if_tag.getAttribute("name")):
1081
997
if_tag.appendChild(tag)
1082
# Add annotation tags for properties
1083
for tag in if_tag.getElementsByTagName("property"):
1085
for name, prop in self._get_all_dbus_things(
1087
if (name == tag.getAttribute("name")
1088
and prop._dbus_interface
1089
== if_tag.getAttribute("name")):
1090
annots.update(getattr(
1091
prop, "_dbus_annotations", {}))
1092
for name, value in annots.items():
1093
ann_tag = document.createElement(
1095
ann_tag.setAttribute("name", name)
1096
ann_tag.setAttribute("value", value)
1097
tag.appendChild(ann_tag)
998
# Add annotation tags
999
for typ in ("method", "signal", "property"):
1000
for tag in if_tag.getElementsByTagName(typ):
1002
for name, prop in (self.
1003
_get_all_dbus_things(typ)):
1004
if (name == tag.getAttribute("name")
1005
and prop._dbus_interface
1006
== if_tag.getAttribute("name")):
1007
annots.update(getattr(
1008
prop, "_dbus_annotations", {}))
1009
for name, value in annots.items():
1010
ann_tag = document.createElement(
1012
ann_tag.setAttribute("name", name)
1013
ann_tag.setAttribute("value", value)
1014
tag.appendChild(ann_tag)
1015
# Add interface annotation tags
1016
for annotation, value in dict(
1017
itertools.chain.from_iterable(
1018
annotations().items()
1019
for name, annotations
1020
in self._get_all_dbus_things("interface")
1021
if name == if_tag.getAttribute("name")
1023
ann_tag = document.createElement("annotation")
1024
ann_tag.setAttribute("name", annotation)
1025
ann_tag.setAttribute("value", value)
1026
if_tag.appendChild(ann_tag)
1098
1027
# Add the names to the return values for the
1099
1028
# "org.freedesktop.DBus.Properties" methods
1100
1029
if (if_tag.getAttribute("name")
1436
1365
if exitstatus >= 0:
1437
1366
# Emit D-Bus signal
1438
1367
self.CheckerCompleted(dbus.Int16(exitstatus),
1439
# This is specific to GNU libC
1440
dbus.Int64(exitstatus << 8),
1441
1369
dbus.String(command))
1443
1371
# Emit D-Bus signal
1444
1372
self.CheckerCompleted(dbus.Int16(-1),
1446
# This is specific to GNU libC
1448
| self.last_checker_signal),
1374
self.last_checker_signal),
1449
1375
dbus.String(command))
1591
1513
self.approval_duration = datetime.timedelta(0, 0, 0, value)
1593
1515
# Name - property
1595
{"org.freedesktop.DBus.Property.EmitsChangedSignal": "const"})
1596
1516
@dbus_service_property(_interface, signature="s", access="read")
1597
1517
def Name_dbus_property(self):
1598
1518
return dbus.String(self.name)
1600
1520
# Fingerprint - property
1602
{"org.freedesktop.DBus.Property.EmitsChangedSignal": "const"})
1603
1521
@dbus_service_property(_interface, signature="s", access="read")
1604
1522
def Fingerprint_dbus_property(self):
1605
1523
return dbus.String(self.fingerprint)
1736
1652
self.stop_checker()
1738
1654
# ObjectPath - property
1740
{"org.freedesktop.DBus.Property.EmitsChangedSignal": "const",
1741
"org.freedesktop.DBus.Deprecated": "true"})
1742
1655
@dbus_service_property(_interface, signature="o", access="read")
1743
1656
def ObjectPath_dbus_property(self):
1744
1657
return self.dbus_object_path # is already a dbus.ObjectPath
1746
1659
# Secret = property
1748
{"org.freedesktop.DBus.Property.EmitsChangedSignal":
1750
1660
@dbus_service_property(_interface,
1751
1661
signature="ay",
1752
1662
access="write",