当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.DBusException方法代码示例

本文整理汇总了Python中dbus.exceptions.DBusException方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.DBusException方法的具体用法?Python exceptions.DBusException怎么用?Python exceptions.DBusException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dbus.exceptions的用法示例。


在下文中一共展示了exceptions.DBusException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: is_service_running

# 需要导入模块: from dbus import exceptions [as 别名]
# 或者: from dbus.exceptions import DBusException [as 别名]
def is_service_running(service):
    """ Queries systemd through dbus to see if the service is running """
    service_running = False
    bus = SystemBus()
    systemd = bus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1')
    manager = Interface(systemd, dbus_interface='org.freedesktop.systemd1.Manager')
    try:
        service_unit = service if service.endswith('.service') else manager.GetUnit('{0}.service'.format(service))
        service_proxy = bus.get_object('org.freedesktop.systemd1', str(service_unit))
        service_properties = Interface(service_proxy, dbus_interface='org.freedesktop.DBus.Properties')
        service_load_state = service_properties.Get('org.freedesktop.systemd1.Unit', 'LoadState')
        service_active_state = service_properties.Get('org.freedesktop.systemd1.Unit', 'ActiveState')
        if service_load_state == 'loaded' and service_active_state == 'active':
            service_running = True
    except DBusException:
        pass

    return service_running 
开发者ID:openshift,项目名称:origin-ci-tool,代码行数:20,代码来源:openshift_facts.py

示例2: connect_provider

# 需要导入模块: from dbus import exceptions [as 别名]
# 或者: from dbus.exceptions import DBusException [as 别名]
def connect_provider(uuid):  # type: (str) -> Any
    """
    Enable the network manager configuration by its UUID

    args:
        uuid (str): the unique ID of the configuration
    """
    logger.info(u"connecting profile with uuid {}"
                "using NetworkManager".format(uuid))
    if not have_dbus():
        raise EduvpnException("No DBus daemon running")

    try:
        connection = NetworkManager.Settings.GetConnectionByUuid(uuid)  # type: ignore
        return NetworkManager.NetworkManager.ActivateConnection(connection, "/", "/")  # type: ignore
    except DBusException as e:  # type: ignore
        raise EduvpnException(e) 
开发者ID:eduvpn,项目名称:python-eduvpn-client,代码行数:19,代码来源:manager.py

示例3: list_active

# 需要导入模块: from dbus import exceptions [as 别名]
# 或者: from dbus.exceptions import DBusException [as 别名]
def list_active():  # type: () -> list
    """
    List active connections

    returns:
        list: a list of NetworkManager.ActiveConnection objects
    """
    logger.info(u"getting list of active connections")
    if not have_dbus():
        return []

    try:
        active = NetworkManager.NetworkManager.ActiveConnections  # type: ignore
        return [a for a in active if NetworkManager.Settings.  # type: ignore
                GetConnectionByUuid(a.Uuid).GetSettings()  # type: ignore
                ['connection']['type'] == 'vpn']  # type: ignore
    except DBusException:
        return [] 
开发者ID:eduvpn,项目名称:python-eduvpn-client,代码行数:20,代码来源:manager.py

示例4: __init__

# 需要导入模块: from dbus import exceptions [as 别名]
# 或者: from dbus.exceptions import DBusException [as 别名]
def __init__(self, app_name, icon):
        self.icon = icon
        try:
            if Notify is not None:
                Notify.init(app_name)
                self.notifier = Notify
            else:
                notify2.init(app_name)
                self.notifier = notify2
            self.enabled = True
        except DBusException:
            print("WARNING: No notification daemon found! "
                  "Notifications will be ignored.")
            self.enabled = False 
开发者ID:raelgc,项目名称:scudcloud,代码行数:16,代码来源:notifier.py

示例5: run

# 需要导入模块: from dbus import exceptions [as 别名]
# 或者: from dbus.exceptions import DBusException [as 别名]
def run(self):
		self._stopped = False
		self._loop = GObject.MainLoop()

		self._propertiesListener = NetworkManager.NetworkManager.OnPropertiesChanged(self.propertiesChanged)
		self._stateChangeListener = NetworkManager.NetworkManager.OnStateChanged(self.globalStateChanged)

		connectionState = NetworkManager.NetworkManager.State
		logger.info('Network Manager reports state: *[%s]*' % NetworkManager.const('state', connectionState))
		if connectionState == NetworkManager.NM_STATE_CONNECTED_GLOBAL:
			self._setOnline(True)

		#d = self.getActiveConnectionDevice()
		#if d:
		#	self._devicePropertiesListener = d.Dhcp4Config.connect_to_signal('PropertiesChanged', self.activeDeviceConfigChanged)
		#	self._currentIpv4Address = d.Ip4Address
		#	self._activeDevice = d
		#	self._online = True
		#	logger.info('Active Connection found at %s (%s)' % (d.IpInterface, d.Ip4Address))

		while not self._stopped:
			try:
				self._loop.run()

			except KeyboardInterrupt:
				#kill the main process too
				from octoprint import astrobox
				astrobox.stop()

			except DBusException as e:
				#GObject.idle_add(logger.error, 'Exception during NetworkManagerEvents: %s' % e)
				logger.error('Exception during NetworkManagerEvents: %s' % e)

			finally:
				self.stop() 
开发者ID:AstroPrint,项目名称:AstroBox,代码行数:37,代码来源:debian.py

示例6: start_unit

# 需要导入模块: from dbus import exceptions [as 别名]
# 或者: from dbus.exceptions import DBusException [as 别名]
def start_unit(self, unit):
        try:
            self.manager.StartUnit(unit, 'replace')
            return True
        except exceptions.DBusException:
            return False 
开发者ID:ogarcia,项目名称:sysdweb,代码行数:8,代码来源:systemd.py

示例7: stop_unit

# 需要导入模块: from dbus import exceptions [as 别名]
# 或者: from dbus.exceptions import DBusException [as 别名]
def stop_unit(self, unit):
        try:
            self.manager.StopUnit(unit, 'replace')
            return True
        except exceptions.DBusException:
            return False 
开发者ID:ogarcia,项目名称:sysdweb,代码行数:8,代码来源:systemd.py

示例8: restart_unit

# 需要导入模块: from dbus import exceptions [as 别名]
# 或者: from dbus.exceptions import DBusException [as 别名]
def restart_unit(self, unit):
        try:
            self.manager.RestartUnit(unit, 'replace')
            return True
        except exceptions.DBusException:
            return False 
开发者ID:ogarcia,项目名称:sysdweb,代码行数:8,代码来源:systemd.py

示例9: reload_unit

# 需要导入模块: from dbus import exceptions [as 别名]
# 或者: from dbus.exceptions import DBusException [as 别名]
def reload_unit(self, unit):
        try:
            self.manager.ReloadUnit(unit, 'replace')
            return True
        except exceptions.DBusException:
            return False 
开发者ID:ogarcia,项目名称:sysdweb,代码行数:8,代码来源:systemd.py

示例10: reload_or_restart_unit

# 需要导入模块: from dbus import exceptions [as 别名]
# 或者: from dbus.exceptions import DBusException [as 别名]
def reload_or_restart_unit(self, unit):
        try:
            self.manager.ReloadOrRestartUnit(unit, 'replace')
            return True
        except exceptions.DBusException:
            return False 
开发者ID:ogarcia,项目名称:sysdweb,代码行数:8,代码来源:systemd.py

示例11: start

# 需要导入模块: from dbus import exceptions [as 别名]
# 或者: from dbus.exceptions import DBusException [as 别名]
def start(self):
        """Start service."""
        signals.emit("services", "pre_start", self)
        if self.stype == "supervisor":
            supervisor_ping()
            try:
                conns.Supervisor.startProcess(self.name)
                signals.emit("services", "post_start", self)
            except:
                raise ActionError(
                    "svc", "The service failed to start. Please check "
                    "`sudo arkosctl svc status {0}`".format(self.name))
        else:
            # Send the start command to systemd
            try:
                path = conns.SystemD.LoadUnit(self.sfname)
                conns.SystemD.StartUnit(self.sfname, "replace")
            except DBusException as e:
                raise ActionError("dbus", str(e))
            timeout = 0
            time.sleep(1)
            # Wait for the service to start, raise exception if it fails
            while timeout < 10:
                data = conns.SystemDConnect(
                    path, "org.freedesktop.DBus.Properties")
                data = data.GetAll("org.freedesktop.systemd1.Unit")
                if str(data["ActiveState"]) == "failed":
                    raise ActionError(
                        "svc", "The service failed to start. Please check "
                        "`sudo arkosctl svc status {0}`".format(self.name))
                elif str(data["ActiveState"]) == "active":
                    self.state = "running"
                    signals.emit("services", "post_start", self)
                    break
                timeout += 1
                time.sleep(1)
            else:
                raise ActionError("svc", "The service start timed out. "
                                  "Please check `sudo arkosctl svc status {0}`"
                                  .format(self.sfname)) 
开发者ID:arkOScloud,项目名称:core,代码行数:42,代码来源:services.py

示例12: stop

# 需要导入模块: from dbus import exceptions [as 别名]
# 或者: from dbus.exceptions import DBusException [as 别名]
def stop(self):
        """Stop service."""
        signals.emit("services", "pre_stop", self)
        if self.stype == "supervisor":
            supervisor_ping()
            conns.Supervisor.stopProcess(self.name)
            signals.emit("services", "post_stop", self)
            self.state = "stopped"
        else:
            # Send the stop command to systemd
            try:
                path = conns.SystemD.LoadUnit(self.sfname)
                conns.SystemD.StopUnit(self.sfname, "replace")
            except DBusException as e:
                raise ActionError("dbus", str(e))
            timeout = 0
            time.sleep(1)
            # Wait for the service to stop, raise exception if it fails
            while timeout < 10:
                data = conns.SystemDConnect(
                    path, "org.freedesktop.DBus.Properties")
                data = data.GetAll("org.freedesktop.systemd1.Unit")
                if str(data["ActiveState"]) in ["inactive", "failed"]:
                    self.state = "stopped"
                    signals.emit("services", "post_stop", self)
                    break
                timeout + 1
                time.sleep(1)
            else:
                raise ActionError("svc", "The service stop timed out. "
                                  "Please check `sudo arkosctl svc status {0}`"
                                  .format(self.sfname)) 
开发者ID:arkOScloud,项目名称:core,代码行数:34,代码来源:services.py

示例13: restart

# 需要导入模块: from dbus import exceptions [as 别名]
# 或者: from dbus.exceptions import DBusException [as 别名]
def restart(self, real=False):
        """Restart service."""
        signals.emit("services", "pre_restart", self)
        if self.stype == "supervisor":
            supervisor_ping()
            conns.Supervisor.stopProcess(self.name, wait=True)
            conns.Supervisor.startProcess(self.name)
            signals.emit("services", "post_restart", self)
        else:
            # Send the restart command to systemd
            try:
                path = conns.SystemD.LoadUnit(self.sfname)
                if real:
                    conns.SystemD.RestartUnit(self.sfname, "replace")
                else:
                    conns.SystemD.ReloadOrRestartUnit(self.sfname, "replace")
            except DBusException as e:
                raise ActionError("dbus", str(e))
            timeout = 0
            time.sleep(1)
            # Wait for the service to restart, raise exception if it fails
            while timeout < 10:
                data = conns.SystemDConnect(
                    path, "org.freedesktop.DBus.Properties")
                data = data.GetAll("org.freedesktop.systemd1.Unit")
                if str(data["ActiveState"]) == "failed":
                    raise ActionError(
                        "svc", "The service failed to restart. Please check "
                        "`sudo arkosctl svc status {0}`".format(self.name))
                elif str(data["ActiveState"]) == "active":
                    self.state = "running"
                    signals.emit("services", "post_restart", self)
                    break
                timeout + 1
                time.sleep(1)
            else:
                raise ActionError("svc", "The service restart timed out. "
                                  "Please check `sudo arkosctl svc status {0}`"
                                  .format(self.sfname)) 
开发者ID:arkOScloud,项目名称:core,代码行数:41,代码来源:services.py

示例14: enable

# 需要导入模块: from dbus import exceptions [as 别名]
# 或者: from dbus.exceptions import DBusException [as 别名]
def enable(self):
        """Enable service to start on boot."""
        if self.stype == "supervisor":
            disfsname = "{0}.disabled".format(self.sfname)
            supervisor_ping()
            if os.path.exists(os.path.join("/etc/supervisor.d", disfsname)):
                os.rename(os.path.join("/etc/supervisor.d", disfsname),
                          os.path.join("/etc/supervisor.d", self.sfname))
            conns.Supervisor.restart()
        else:
            try:
                conns.SystemD.EnableUnitFiles([self.sfname], False, True)
            except DBusException as e:
                raise ActionError("dbus", str(e))
        self.enabled = True 
开发者ID:arkOScloud,项目名称:core,代码行数:17,代码来源:services.py

示例15: disable

# 需要导入模块: from dbus import exceptions [as 别名]
# 或者: from dbus.exceptions import DBusException [as 别名]
def disable(self):
        """Disable service starting on boot."""
        if self.stype == "supervisor":
            disfsname = "{0}.disabled".format(self.sfname)
            if self.state == "running":
                self.stop()
            os.rename(os.path.join("/etc/supervisor.d", self.sfname),
                      os.path.join("/etc/supervisor.d", disfsname))
            self.state = "stopped"
        else:
            try:
                conns.SystemD.DisableUnitFiles([self.sfname], False)
            except DBusException as e:
                raise ActionError("dbus", str(e))
        self.enabled = False 
开发者ID:arkOScloud,项目名称:core,代码行数:17,代码来源:services.py


注:本文中的dbus.exceptions.DBusException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。