本文整理汇总了Python中dbus.Interface方法的典型用法代码示例。如果您正苦于以下问题:Python dbus.Interface方法的具体用法?Python dbus.Interface怎么用?Python dbus.Interface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dbus
的用法示例。
在下文中一共展示了dbus.Interface方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_song_info
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Interface [as 别名]
def get_song_info(player):
if player == "mpd":
from mpd import MPDClient
client = MPDClient()
client.connect("localhost", 6600)
song_info = client.currentsong()
return song_info["artist"], song_info["title"]
else:
bus = dbus.SessionBus()
try:
proxy = bus.get_object("org.mpris.MediaPlayer2.%s" % player,
"/org/mpris/MediaPlayer2")
except dbus.exceptions.DBusException:
print("[ERROR] Player \"%s\" doesn't exist or isn't playing" \
% player)
return
interface = dbus.Interface(
proxy, dbus_interface="org.freedesktop.DBus.Properties"
)
properties = interface.GetAll("org.mpris.MediaPlayer2.Player")
metadata = properties["Metadata"]
artist = str(metadata["xesam:artist"][0])
title = str(metadata["xesam:title"])
return artist, title
示例2: __init__
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Interface [as 别名]
def __init__(self, adapter_name):
self.listener = None
self.adapter_name = adapter_name
self._bus = dbus.SystemBus()
try:
adapter_object = self._bus.get_object('org.bluez', '/org/bluez/' + adapter_name)
except dbus.exceptions.DBusException as e:
raise _error_from_dbus_error(e)
object_manager_object = self._bus.get_object("org.bluez", "/")
self._adapter = dbus.Interface(adapter_object, 'org.bluez.Adapter1')
self._adapter_properties = dbus.Interface(self._adapter, 'org.freedesktop.DBus.Properties')
self._object_manager = dbus.Interface(object_manager_object, "org.freedesktop.DBus.ObjectManager")
self._device_path_regex = re.compile('^/org/bluez/' + adapter_name + '/dev((_[A-Z0-9]{2}){6})$')
self._devices = {}
self._discovered_devices = {}
self._interface_added_signal = None
self._properties_changed_signal = None
self._main_loop = None
self.update_devices()
示例3: __init__
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Interface [as 别名]
def __init__(self, path):
proxy = dbus.SystemBus().get_object('org.freedesktop.systemd1', path)
self._unit = dbus.Interface(
proxy, dbus_interface='org.freedesktop.systemd1.Unit')
props = self._unit.GetAll(
'org.freedesktop.systemd1.Unit',
dbus_interface=dbus.PROPERTIES_IFACE)
for prop in props:
prop = str(prop)
if not hasattr(self.__class__, prop):
setattr(self.__class__, prop, self._make_property(prop))
if self.LoadState == 'not-found':
raise NoSuchUnit(self.Id)
示例4: display3dgraph
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Interface [as 别名]
def display3dgraph(graph, reset_world=True):
"""Send the graph (produced by buildgraph()) to a running
rtgraph3d instance.
"""
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
control = bus.get_object("org.secdev.rtgraph3d", "/control")
graph3d = dbus.Interface(control, "org.secdev.rtgraph3d.command")
if reset_world:
graph3d.reset_world()
for node, node_edges in viewitems(graph):
for destnode in node_edges:
if destnode == node:
continue
try:
graph3d.new_edge(utils.int2ip(node), {},
utils.int2ip(destnode), {})
except Exception:
utils.LOGGER.warning('Exception', exc_info=True)
return graph3d
示例5: is_service_running
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Interface [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
示例6: __init__
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Interface [as 别名]
def __init__(self):
self.bus = dbus.SystemBus()
self.adapters = {}
self.bus.add_signal_receiver(self._interfaceAdded, dbus_interface='org.freedesktop.DBus.ObjectManager', signal_name = "InterfacesAdded")
self.bus.add_signal_receiver(self._interfaceRemoved, dbus_interface='org.freedesktop.DBus.ObjectManager', signal_name = "InterfacesRemoved")
self.bus.add_signal_receiver(self._propertiesChanged, dbus_interface='org.freedesktop.DBus.Properties', signal_name = "PropertiesChanged", path_keyword = "path")
# Find the adapters and create the objects
obj_mgr = dbus.Interface(self.bus.get_object("org.bluez", "/"), 'org.freedesktop.DBus.ObjectManager')
objs = obj_mgr.GetManagedObjects()
for obj_path in objs:
obj = objs[obj_path]
if 'org.bluez.Adapter1' in obj:
adapt_name = obj_path.split('/')[3]
self.adapters[adapt_name] = Adapter(self.bus, obj_path)
self.adapters[adapt_name].agentRegister()
示例7: auth_with_policykit
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Interface [as 别名]
def auth_with_policykit(action,
bus_name,
object_path,
interface_name,
interactive=1, ):
system_bus = dbus.SystemBus()
obj = system_bus.get_object(bus_name, object_path, interface_name)
policykit = dbus.Interface(obj, interface_name)
pid = os.getpid()
subject = ('unix-process', {'pid': dbus.UInt32(pid,
variant_level=1),
'start-time': dbus.UInt64(0), })
details = {'': ''}
flags = dbus.UInt32(interactive)
cancel_id = ''
(ok, notused, details) = policykit.CheckAuthorization(
subject, action, details, flags, cancel_id)
return ok
示例8: factory
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Interface [as 别名]
def factory(type):
try:
interface = dbus.Interface(
dbus.SessionBus().get_object(
'org.mpris.MediaPlayer2.spotify',
'/org/mpris/MediaPlayer2'
),
type
)
except dbus.exceptions.DBusException:
"""
If we catch this exception, Spotify is not running.
Let the user know.
"""
sys.exit(
"\nSome errors occured. Try restart or start Spotify. Pytify is just a cli application which controls Spotify. So you can't use Pytify without Spotify.\n"
)
return interface
示例9: find_device_in_objects
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Interface [as 别名]
def find_device_in_objects(objects, device_address, adapter_pattern=None):
bus = dbus.SystemBus()
path_prefix = ""
if adapter_pattern:
adapter = find_adapter_in_objects(objects, adapter_pattern)
path_prefix = adapter.object_path
for path, ifaces in objects.iteritems():
device = ifaces.get(DEVICE_INTERFACE)
if device is None:
continue
if (device["Address"] == device_address and
path.startswith(path_prefix)):
obj = bus.get_object(SERVICE_NAME, path)
return dbus.Interface(obj, DEVICE_INTERFACE)
raise Exception("Bluetooth device not found")
示例10: test_011_reg_agent_activate_put
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Interface [as 别名]
def test_011_reg_agent_activate_put(self):
"""Test registrar's PUT /v2/agents/{UUID}/activate Interface"""
global keyblob, aik
self.assertIsNotNone(keyblob, "Required value not set. Previous step may have failed?")
self.assertIsNotNone(aik, "Required value not set. Previous step may have failed?")
key = tpm.activate_identity(keyblob)
data = {
'auth_tag': crypto.do_hmac(key,tenant_templ.agent_uuid),
}
v_json_message = json.dumps(data)
params = f"/v{self.api_version}/agents/{tenant_templ.agent_uuid}/activate"
response = httpclient_requests.request("PUT", "%s"%tenant_templ.registrar_ip,tenant_templ.registrar_boot_port, params=params, data=v_json_message, context=None)
self.assertEqual(response.status, 200, "Non-successful Registrar agent Activate return code!")
json_response = json.loads(response.read().decode())
# Ensure response is well-formed
self.assertIn("results", json_response, "Malformed response body!")
示例11: test_012_reg_agent_vactivate_put
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Interface [as 别名]
def test_012_reg_agent_vactivate_put(self):
"""Test registrar's PUT /v2/agents/{UUID}/vactivate Interface"""
global keyblob, aik, ek
self.assertIsNotNone(keyblob, "Required value not set. Previous step may have failed?")
self.assertIsNotNone(aik, "Required value not set. Previous step may have failed?")
self.assertIsNotNone(ek, "Required value not set. Previous step may have failed?")
key = tpm.activate_identity(keyblob)
deepquote = tpm.create_deep_quote(hashlib.sha1(key).hexdigest(),tenant_templ.agent_uuid+aik+ek)
data = {
'deepquote': deepquote,
}
v_json_message = json.dumps(data)
params = '/v%s/agents/%s/vactivate'% self.api_version, tenant_templ.agent_uuid
response = httpclient_requests.request("PUT", "%s"%tenant_templ.registrar_ip,tenant_templ.registrar_tls_boot_port, params=params, data=v_json_message, context=tenant_templ.context)
self.assertEqual(response.status, 200, "Non-successful Registrar agent vActivate return code!")
json_response = json.loads(response.read().decode())
# Ensure response is well-formed
self.assertIn("results", json_response, "Malformed response body!")
示例12: test_020_agent_keys_pubkey_get
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Interface [as 别名]
def test_020_agent_keys_pubkey_get(self):
"""Test agent's GET /v2/keys/pubkey Interface"""
# We want a real cloud agent to communicate with!
launch_cloudagent()
time.sleep(10)
params = f"/v{self.api_version}/keys/pubkey"
response = httpclient_requests.request("GET", "%s"%tenant_templ.cloudagent_ip,tenant_templ.cloudagent_port, params=params)
self.assertEqual(response.status, 200, "Non-successful Agent pubkey return code!")
json_response = json.loads(response.read().decode())
# Ensure response is well-formed
self.assertIn("results", json_response, "Malformed response body!")
self.assertIn("pubkey", json_response["results"], "Malformed response body!")
global public_key
public_key = json_response["results"]["pubkey"]
self.assertNotEqual(public_key, None, "Malformed response body!")
示例13: test_023_agent_keys_vkey_post
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Interface [as 别名]
def test_023_agent_keys_vkey_post(self):
"""Test agent's POST /v2/keys/vkey Interface"""
# CV should do this (during CV POST/PUT test)
# Running this test might hide problems with the CV sending the V key
global public_key
self.assertIsNotNone(self.V, "Required value not set. Previous step may have failed?")
self.assertIsNotNone(public_key, "Required value not set. Previous step may have failed?")
encrypted_V = crypto.rsa_encrypt(crypto.rsa_import_pubkey(public_key),str(self.V))
b64_encrypted_V = base64.b64encode(encrypted_V)
data = {
'encrypted_key': b64_encrypted_V
}
v_json_message = json.dumps(data)
params = f"/v{self.api_version}/keys/vkey"
response = httpclient_requests.request("POST", "%s"%tenant_templ.cloudagent_ip,tenant_templ.cloudagent_port, params=params, data=v_json_message)
self.assertEqual(response.status, 200, "Non-successful Agent vkey post return code!")
json_response = json.loads(response.read().decode())
# Ensure response is well-formed
self.assertIn("results", json_response, "Malformed response body!")
示例14: test_024_agent_keys_ukey_post
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Interface [as 别名]
def test_024_agent_keys_ukey_post(self):
"""Test agents's POST /v2/keys/ukey Interface"""
global public_key
self.assertIsNotNone(public_key, "Required value not set. Previous step may have failed?")
self.assertIsNotNone(self.U, "Required value not set. Previous step may have failed?")
self.assertIsNotNone(self.auth_tag, "Required value not set. Previous step may have failed?")
self.assertIsNotNone(self.payload, "Required value not set. Previous step may have failed?")
encrypted_U = crypto.rsa_encrypt(crypto.rsa_import_pubkey(public_key),self.U)
b64_encrypted_u = base64.b64encode(encrypted_U)
data = {
'encrypted_key': b64_encrypted_u,
'auth_tag': self.auth_tag,
'payload': self.payload
}
u_yaml_message = json.dumps(data)
params = '/v%s/keys/ukey'% self.api_version
response = httpclient_requests.request("POST", "%s"%tenant_templ.cloudagent_ip,tenant_templ.cloudagent_port, params=params, data=u_yaml_message)
self.assertEqual(response.status, 200, "Non-successful Agent ukey post return code!")
json_response = json.loads(response.read().decode())
# Ensure response is well-formed
self.assertIn("results", json_response, "Malformed response body!")
示例15: test_041_agent_keys_verify_get
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Interface [as 别名]
def test_041_agent_keys_verify_get(self):
"""Test agent's GET /v2/keys/verify Interface
We use async here to allow function await while key processes"""
self.assertIsNotNone(self.K, "Required value not set. Previous step may have failed?")
challenge = tpm_abstract.TPM_Utilities.random_password(20)
encoded = base64.b64encode(self.K).decode('utf-8')
response = tornado_requests.request("GET",
"http://%s:%s/keys/verify?challenge=%s"%(self.cloudagent_ip,self.cloudagent_port,challenge))
response = await response
self.assertEqual(response.status, 200, "Non-successful Agent verify return code!")
json_response = json.loads(response.read().decode())
# Ensure response is well-formed
self.assertIn("results", json_response, "Malformed response body!")
self.assertIn("hmac", json_response["results"], "Malformed response body!")
# Be sure response is valid
mac = json_response['results']['hmac']
ex_mac = crypto.do_hmac(encoded, challenge)
# ex_mac = crypto.do_hmac(self.K, challenge)
self.assertEqual(mac, ex_mac, "Agent failed to validate challenge code!")