當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。