Exemple #1
0
def AddServer(self):
    root = '/com/intel/dLeynaServer/server/%d' % (self.next_server_id,)

    # Pre-process the items tree anchoring paths to the new root object
    items = copy.deepcopy(ITEMS)
    for item in items:
        item['Path'] = dbus.ObjectPath(item['Path'].replace('{root}', root))
        item['Parent'] = dbus.ObjectPath(item['Parent'].replace('{root}', root))

    for item in items:
        path = item['Path']
        self.AddObject(path, 'org.gnome.UPnP.MediaObject2', {}, [])
        obj = get_object(path)
        obj.items = items

        if path == root:
            item['FriendlyName'] = 'Mock Server <#{0}>'.format(self.next_server_id)
            item['UDN'] = str(uuid.uuid5(uuid.UUID('9123ef5c-f083-11e2-8000-000000000000'), str(self.next_server_id)))
            obj.AddTemplate("dleynamediadevice.py", filter_properties (item, MEDIA_DEVICE_PROPERTIES))
        obj.AddTemplate("dleynamediaobject.py", filter_properties(item, MEDIA_OBJECT2_PROPERTIES))
        obj.AddTemplate("dleynamediacontainer.py", filter_properties(item, MEDIA_CONTAINER2_PROPERTIES))

    self.servers.append(root)
    self.EmitSignal(MAIN_IFACE, 'FoundServer', 'o', [root])

    self.next_server_id += 1
    return path
Exemple #2
0
def CreateContainer(self, display_name, container_type, child_types):
    upload_id = self.next_upload_id
    self.next_upload_id += 1

    path = "{0}/up{1:03}".format(self.__dbus_object_path__, upload_id)
    upload = {
        'ChildCount': dbus.UInt32(0),
        'DisplayName': display_name,
        'Parent': self.__dbus_object_path__,
        'Path': path,
        'Type': 'container',
        'TypeEx': container_type,
    }
    self.items.append(upload)

    self.AddObject(path, 'org.gnome.UPnP.MediaObject2', {}, [])
    obj = get_object(path)
    obj.items = self.items
    obj.AddTemplate("dleynamediaobject.py",
                    filter_properties(upload, MEDIA_OBJECT2_PROPERTIES))
    obj.AddTemplate("dleynamediacontainer.py",
                    filter_properties(upload, MEDIA_CONTAINER2_PROPERTIES))

    device = get_object(
        find_root(self.items, self.__dbus_object_path__)['Path'])
    device.queue_change({'ChangeType': CHANGE_TYPES['Add'], 'Path': path})

    return (path)
def CreateContainerInAnyContainer(self, display_name, container_type, child_types):
    upload_id = self.next_upload_id
    self.next_upload_id += 1

    path = '{0}/any{1:03}'.format(self.__dbus_object_path__, upload_id)
    upload = {
        'ChildCount': dbus.UInt32(0),
        'DisplayName': display_name,
        'Parent': self.__dbus_object_path__,
        'Path': path,
        'Type': 'container',
        'TypeEx': container_type,
      }
    self.items.append(upload)

    self.AddObject(path, 'org.gnome.UPnP.MediaObject2', {}, [])
    obj = get_object(path)
    obj.items = self.items
    obj.AddTemplate('dleynamediaobject.py', filter_properties(upload, MEDIA_OBJECT2_PROPERTIES))
    obj.AddTemplate('dleynamediacontainer.py', filter_properties(upload, MEDIA_CONTAINER2_PROPERTIES))

    self.queue_change ({
        'ChangeType': CHANGE_TYPES['Add'],
        'Path': path
    })

    return (path)
Exemple #4
0
def AddServer(self):
    root = '/com/intel/dLeynaServer/server/%d' % (self.next_server_id, )

    # Pre-process the items tree anchoring paths to the new root object
    items = copy.deepcopy(ITEMS)
    for item in items:
        item['Path'] = dbus.ObjectPath(item['Path'].replace('{root}', root))
        item['Parent'] = dbus.ObjectPath(item['Parent'].replace(
            '{root}', root))

    for item in items:
        path = item['Path']
        self.AddObject(path, 'org.gnome.UPnP.MediaObject2', {}, [])
        obj = get_object(path)
        obj.items = items

        if path == root:
            item['FriendlyName'] = 'Mock Server <#{0}>'.format(
                self.next_server_id)
            item['UDN'] = str(
                uuid.uuid5(uuid.UUID('9123ef5c-f083-11e2-8000-000000000000'),
                           str(self.next_server_id)))
            obj.AddTemplate("dleynamediadevice.py",
                            filter_properties(item, MEDIA_DEVICE_PROPERTIES))
        obj.AddTemplate("dleynamediaobject.py",
                        filter_properties(item, MEDIA_OBJECT2_PROPERTIES))
        obj.AddTemplate("dleynamediacontainer.py",
                        filter_properties(item, MEDIA_CONTAINER2_PROPERTIES))

    self.servers.append(root)
    self.EmitSignal(MAIN_IFACE, 'FoundServer', 'o', [root])

    self.next_server_id += 1
    return path
def UploadToAnyContainer(self, display_name, filename):
    upload_id = self.next_upload_id
    self.next_upload_id += 1

    path = '{0}/any{1:03}'.format(self.__dbus_object_path__, upload_id)
    size = os.stat(filename).st_size
    upload = {
        'DisplayName': display_name,
        'Parent': self.__dbus_object_path__,
        'Path': path,
        'Type': 'item.unclassified',
        'UploadFilename': filename,
        'UploadId': upload_id,
        'UploadSize': size,
      }
    self.items.append(upload)

    self.AddObject(path, 'org.gnome.UPnP.MediaObject2', {}, [])
    obj = get_object(path)
    obj.items = self.items
    obj.AddTemplate('dleynamediaobject.py', filter_properties(upload, MEDIA_OBJECT2_PROPERTIES))

    device = get_object(find_root(self.items, self.__dbus_object_path__)['Path'])

    def upload_completed():
        device.EmitSignal(MAIN_IFACE, 'UploadUpdate', 'ustt', (upload_id, 'COMPLETED', size, size))
        self.queue_change ({
            'ChangeType': CHANGE_TYPES['Add'],
            'Path': path
        })
    GLib.idle_add(upload_completed)

    return (upload_id, path)
Exemple #6
0
def Upload(self, display_name, filename):
    upload_id = self.next_upload_id
    self.next_upload_id += 1

    path = "{0}/up{1:03}".format(self.__dbus_object_path__, upload_id)
    size = os.stat(filename).st_size
    upload = {
        'DisplayName': display_name,
        'Parent': self.__dbus_object_path__,
        'Path': path,
        'UploadFilename': filename,
        'UploadId': upload_id,
        'UploadSize': size,
    }
    self.items.append(upload)

    self.AddObject(path, 'org.gnome.UPnP.MediaObject2', {}, [])
    obj = get_object(path)
    obj.items = self.items
    obj.AddTemplate("dleynamediaobject.py",
                    filter_properties(upload, MEDIA_OBJECT2_PROPERTIES))

    device = get_object(
        find_root(self.items, self.__dbus_object_path__)['Path'])

    def upload_completed():
        device.EmitSignal(MEDIA_DEVICE_IFACE, 'UploadUpdate', 'ustt',
                          (upload_id, 'COMPLETED', size, size))
        device.queue_change({'ChangeType': CHANGE_TYPES['Add'], 'Path': path})

    GLib.idle_add(upload_completed)

    item = find_item(self.items, self.__dbus_object_path__)
    item['ChildCount'] += 1
    return (upload_id, path)
def ListChildren(self, offset, count, prop_filter):
    children = [i for i in self.items if i['Parent'] == self.__dbus_object_path__]
    if count:
        children = children[offset:offset+count]
    else:
        children = children[offset:]
    return [filter_properties(i, prop_filter) for i in children]
Exemple #8
0
def ListChildren(self, offset, count, prop_filter):
    children = [
        i for i in self.items if i['Parent'] == self.__dbus_object_path__
    ]
    if count:
        children = children[offset:offset + count]
    else:
        children = children[offset:]
    return [filter_properties(i, prop_filter) for i in children]
def BrowseObjects(self, object_paths, props):
    results = []
    for object_path in object_paths:
        item = find_item(self.items, object_path)
        if item:
            result = filter_properties(item, props)
        else:
            result = {
                'Error': dbus.Dictionary({
                    'ID': dbus.Int32(42),
                    'Message': 'Object not found'}, 'sv') }
        results.append(result)
    return results
def queue_change(self, change):
    self.changes_id += 1

    if self.changes is None:
        return

    # return only the parent if we want to emulate ContainerUpdateID-generated
    # change notifications
    if not self.changes_detailed:
        parent = find_item(self.items, change['Path'])
        change = filter_properties(parent, 'Path Type TypeEx'.split())
        change['ChangeType'] = CHANGE_TYPES['Container']
        change['UpdateID'] = self.changes_id

    self.changes += (change,)
Exemple #11
0
def queue_change(self, change):
    self.changes_id += 1

    if self.changes is None:
        return

    # return only the parent if we want to emulate ContainerUpdateID-generated
    # change notifications
    if not self.changes_detailed:
        parent = find_item(self.items, change['Path'])
        change = filter_properties(parent, 'Path Type TypeEx'.split())
        change['ChangeType'] = CHANGE_TYPES['Container']
        change['UpdateID'] = self.changes_id

    self.changes += (change, )
Exemple #12
0
def BrowseObjects(self, object_paths, props):
    results = []
    for object_path in object_paths:
        item = find_item(self.items, object_path)
        if item:
            result = filter_properties(item, props)
        else:
            result = {
                'Error':
                dbus.Dictionary(
                    {
                        'ID': dbus.Int32(42),
                        'Message': 'Object not found'
                    }, 'sv')
            }
        results.append(result)
    return results