def main(argv=sys.argv, object_classes=None, default_bus_name=None): # Set default mainloop dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) if not default_bus_name: default_bus_name = rhsmlib.dbus.constants.BUS_NAME options, args = parse_argv(argv, default_bus_name) if options.verbose: logger = logging.getLogger("") logger.setLevel(logging.DEBUG) if not object_classes: # Read the object classes from the command-line if we don't # get anything as a parameter object_classes = [] for clazz in args: object_classes.append(rhsmlib.import_class(clazz)) try: log.debug("Starting DBus service with name %s" % options.bus_name) server.Server(bus_class=options.bus, bus_name=options.bus_name, object_classes=object_classes).run() except dbus.exceptions.DBusException as e: if e._dbus_error_name == "org.freedesktop.DBus.Error.AccessDenied": print( "Access to DBus denied. You need to edit /etc/dbus-1/system.conf to allow %s or run with " "dbus-daemon and a custom config file." % options.bus_name) return 0
def run(self): try: self.server = server.Server(bus_class=self.bus_class, bus_name=self.bus_name, object_classes=self.object_classes, bus_kwargs=self.bus_kwargs) self.server.run(self.started_event, self.stopped_event) except Exception as e: log.exception(e) self.started_event.set()