Beispiel #1
0
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
Beispiel #2
0
 def upnp(self):
     upnp = UPNP()
     
     dev = upnp.add_device(self._device)
     
     for name, service in self._services.items():
         dev.add_service(service)
         self._service_abbrev[service.service_id()] = name
     
     self.upnp_ready()
     
     return upnp