本文整理汇总了Python中device.Device.add_service方法的典型用法代码示例。如果您正苦于以下问题:Python Device.add_service方法的具体用法?Python Device.add_service怎么用?Python Device.add_service使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类device.Device
的用法示例。
在下文中一共展示了Device.add_service方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_from_dir
# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import add_service [as 别名]
def add_from_dir(directory, upnp = None):
import os
from device import Device
from service import Service
if upnp is None:
from upnp import UPNP
upnp = UPNP()
path = os.path.abspath(directory)
device_files = os.listdir(path)
for device in device_files:
device_path = os.path.join(path, device)
if os.path.isdir(device_path):
device_name = device
device_file = "%s.xml" % device_name
device_file_path = os.path.join(path, device_file)
# check for service files
service_files = os.listdir(device_path)
services = dict()
for service_file in service_files:
service_file_path = os.path.join(device_path, service_file)
if os.path.isfile(service_file_path) and service_file.endswith(".xml"):
services[service_file] = service_file_path
if len(services) > 0:
new_device = Device("/" + device_file).from_file(device_file_path)
for location, path in services.items():
new_device.add_service(Service("/" + location).from_file(path))
upnp.add_device(new_device)
return upnp