本文整理汇总了Python中dbus.DBusException方法的典型用法代码示例。如果您正苦于以下问题:Python dbus.DBusException方法的具体用法?Python dbus.DBusException怎么用?Python dbus.DBusException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dbus
的用法示例。
在下文中一共展示了dbus.DBusException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import DBusException [as 别名]
def run(self):
self.loop = GLib.MainLoop()
if self.config.notifications:
try:
notify2.init("pantalaimon", mainloop=self.loop)
self.notifications = True
except dbus.DBusException:
logger.error(
"Notifications are enabled but no notification "
"server could be found, disabling notifications."
)
self.notifications = False
GLib.timeout_add(100, self.message_callback)
if not self.loop:
return
self.loop.run()
示例2: all
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import DBusException [as 别名]
def all(cls):
result = []
for connection in NMSettings.ListConnections():
try:
conn_settings = connection.GetSettings()
except DBusException as e:
# NM throws an exception if we try to use GetSettings on a
# connection owned by another user. We just ignore it.
continue
if '802-11-wireless' not in conn_settings:
continue
result.append(cls(connection))
return OrderedDict(
[(c.ssid, c) for c in sorted(result, key=attrgetter('ssid'))])
示例3: VideoPosWrapper
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import DBusException [as 别名]
def VideoPosWrapper(self,args):
timeout=3
try:
# Neither get_object nor start_service_by_name support a timeout. As a workaround you can directly use call_blocking before.
#This call is just for forcing a shorter timeout then default in case bus is not ready or available
logger.debug("DBusConnection: start TESTING if bus " + self._dbus_name + " is ready to accept videopos commands")
self._bus.call_blocking(self._dbus_name, '/org/mpris/MediaPlayer2',
'org.mpris.MediaPlayer2.Player',
'VideoPos',
None, (args), timeout=timeout)
logger.debug("DBusConnection: bus: " + self._dbus_name + " is ready to accept videopos commands")
#The previous call_blocking directly is kind of a hack to be able to set the timeout, if this stops working in the future use below to set the VideoPos
#self.player_interface.VideoPos(args)
except dbus.DBusException as e:
logger.debug("DBusConnection: The bus: " + self._dbus_name + " is NOT ready to accept videopos commands: %s", e)
# The python dbus bindings don't provide property access via the
# 'org.freedesktop.DBus.Properties' interface so we wrap the access of
# properties using
示例4: emit
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import DBusException [as 别名]
def emit(self, record):
app_icon = self.app_icons[
max(level for level in self.app_icons if level <= record.levelno)]
try:
# https://developer.gnome.org/notification-spec/#command-notify
self._notify_object.Notify(
'Qubes', # STRING app_name
0, # UINT32 replaces_id
app_icon, # STRING app_icon
record.msg, # STRING summary
'', # STRING body
(), # ARRAY actions
{}, # DICT hints
0, # INT32 timeout
dbus_interface='org.freedesktop.Notifications')
except dbus.DBusException:
pass
示例5: __exit__
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import DBusException [as 别名]
def __exit__(self, exception_type, value, traceback):
"""
Checks the state of the connection.
If something went wrong for the connection, notifies the user.
@param exception_type: the type of exception that occurred, or
None
@param value: the instance of the exception occurred, or None
@param traceback: the traceback of the error
@returns: False if some exception must be re-raised.
"""
if isinstance(value, dbus.DBusException) or \
not self.tomboy_connection_is_ok:
self.tomboy_failed()
return True
else:
return False
示例6: get_records
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import DBusException [as 别名]
def get_records(self, task):
"""Get a list of hamster facts for a task"""
ids = self.get_hamster_ids(task)
records = []
modified = False
valid_ids = []
for i in ids:
try:
d = self.hamster.GetFact(i)
if d and i not in valid_ids:
records.append(d)
valid_ids.append(i)
continue
except dbus.DBusException:
pass
modified = True
print("Removing invalid fact", i)
if modified:
self.set_hamster_ids(task, valid_ids)
return records
示例7: priority
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import DBusException [as 别名]
def priority(cls):
if 'dbus' not in globals():
raise RuntimeError('python-dbus not installed')
try:
bus = dbus.SessionBus(mainloop=DBusGMainLoop())
except dbus.DBusException as exc:
raise RuntimeError(exc.get_dbus_message())
try:
bus.get_object(cls.bus_name, cls.object_path)
except dbus.DBusException:
tmpl = 'cannot connect to {bus_name}'
msg = tmpl.format(bus_name=cls.bus_name)
raise RuntimeError(msg)
if "KDE" in os.getenv("XDG_CURRENT_DESKTOP", "").split(":"):
return 5.1
return 4.9
示例8: connected
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import DBusException [as 别名]
def connected(self, service):
if self.handle >= 0:
if self.iface.isOpen(self.handle):
return True
bus = dbus.SessionBus(mainloop=DBusGMainLoop())
wId = 0
try:
remote_obj = bus.get_object(self.bus_name, self.object_path)
self.iface = dbus.Interface(remote_obj, 'org.kde.KWallet')
self.handle = self.iface.open(self.iface.networkWallet(), wId, self.appid)
except dbus.DBusException as e:
raise InitError('Failed to open keyring: %s.' % e)
if self.handle < 0:
return False
self._migrate(service)
return True
示例9: _check_permission
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import DBusException [as 别名]
def _check_permission(self, sender, action):
'''
Verifies if the specified action is permitted, and raises
an AccessDeniedException if not.
The caller should use ObtainAuthorization() to get permission.
'''
try:
if sender:
kit = dbus.SystemBus().get_object('org.freedesktop.PolicyKit1', '/org/freedesktop/PolicyKit1/Authority')
kit = dbus.Interface(kit, 'org.freedesktop.PolicyKit1.Authority')
(granted, _, details) = kit.CheckAuthorization(
('system-bus-name', {'name': sender}),
action, {}, dbus.UInt32(1), '', timeout=600)
if not granted:
raise AccessDeniedException('Session not authorized by PolicyKit')
except AccessDeniedException:
raise
except dbus.DBusException as ex:
raise AccessDeniedException(ex.message)
示例10: __verifyNotRunning
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import DBusException [as 别名]
def __verifyNotRunning(self):
if os.path.exists(common.LOCK_FILE):
pid = Application._read_pid_from_lock_file()
# Check that the found PID is running and is autokey
with subprocess.Popen(["ps", "-p", pid, "-o", "command"], stdout=subprocess.PIPE) as p:
output = p.communicate()[0]
if "autokey" in output.decode():
logging.debug("AutoKey is already running as pid %s", pid)
bus = dbus.SessionBus()
try:
dbusService = bus.get_object("org.autokey.Service", "/AppService")
dbusService.show_configure(dbus_interface="org.autokey.Service")
sys.exit(0)
except dbus.DBusException as e:
logging.exception("Error communicating with Dbus service")
self.show_error_dialog(_("AutoKey is already running as pid %s but is not responding") % pid, str(e))
sys.exit(1)
return True
示例11: send_password_to_clipboard
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import DBusException [as 别名]
def send_password_to_clipboard(self, name):
field = None
if name.startswith("otp "):
base_args = ["pass", "otp", "code"]
name = name[4:]
else:
base_args = ["pass", "show"]
if name.startswith(":"):
field, name = name.split(" ", 1)
field = field[1:]
try:
self.send_password_to_gpaste(base_args, name, field)
except dbus.DBusException:
# We couldn't join GPaste over D-Bus,
# use pass native clipboard copy
self.send_password_to_native_clipboard(base_args, name, field)
示例12: notify
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import DBusException [as 别名]
def notify(self, message, body="", error=False):
try:
self.session_bus.get_object(
"org.freedesktop.Notifications", "/org/freedesktop/Notifications"
).Notify(
"Pass",
0,
"dialog-password",
message,
body,
"",
{"transient": False if error else True},
0 if error else 3000,
dbus_interface="org.freedesktop.Notifications",
)
except dbus.DBusException as err:
print(f"Error {err} while trying to display {message}.")
示例13: __init__
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import DBusException [as 别名]
def __init__(self):
# Load up the DBus
session_bus = _dbus.SessionBus()
try:
self._dbus = session_bus.get_object("org.razer", "/org/razer")
except _dbus.DBusException:
raise DaemonNotFound("Could not connect to daemon")
# Get interface for daemon methods
self._dbus_daemon = _dbus.Interface(self._dbus, "razer.daemon")
# Get interface for devices methods
self._dbus_devices = _dbus.Interface(self._dbus, "razer.devices")
self._device_serials = self._dbus_devices.getDevices()
self._devices = []
self._daemon_version = self._dbus_daemon.version()
for serial in self._device_serials:
device = _RazerDeviceFactory.get_device(serial)
self._devices.append(device)
示例14: _create_proxy
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import DBusException [as 别名]
def _create_proxy(self):
try:
# introspection fails so it is disabled
proxy = self._bus.get_object(self._dbus_name,
'/org/mpris/MediaPlayer2',
introspect=False)
return proxy
except dbus.DBusException:
raise DBusConnectionError('Could not get proxy object')
示例15: set_dns_systemd_resolved
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import DBusException [as 别名]
def set_dns_systemd_resolved(lease):
# NOTE: if systemd-resolved is not already running, we might not want to
# run it in case there's specific system configuration for other resolvers
ipr = IPRoute()
index = ipr.link_lookup(ifname=lease.interface)[0]
# Construct the argument to pass to DBUS.
# the equivalent argument for:
# busctl call org.freedesktop.resolve1 /org/freedesktop/resolve1 \
# org.freedesktop.resolve1.Manager SetLinkDNS 'ia(iay)' 2 1 2 4 1 2 3 4
# is SetLinkDNS(2, [(2, [8, 8, 8, 8])]_
iay = [(2, [int(b) for b in ns.split('.')])
for ns in lease.name_server.split()]
# if '.' in ns
# else (10, [ord(x) for x in
# socket.inet_pton(socket.AF_INET6, ns)])
bus = SystemBus()
resolved = bus.get_object('org.freedesktop.resolve1',
'/org/freedesktop/resolve1')
manager = Interface(resolved,
dbus_interface='org.freedesktop.resolve1.Manager')
try:
manager.SetLinkDNS(index, iay)
return True
except DBusException as e:
logger.error(e)
return False