def Delete(self): device = get_object(find_root(self.items, self.__dbus_object_path__)['Path']) device.queue_change ({ 'ChangeType': CHANGE_TYPES['Del'], 'Path': self.__dbus_object_path__ }) item = find_item(self.items, self.__dbus_object_path__) self.items.remove(item) parent = find_item(self.items, item['Parent']) parent['ChildCount'] -= 1
def Delete(self): device = get_object( find_root(self.items, self.__dbus_object_path__)['Path']) device.queue_change({ 'ChangeType': CHANGE_TYPES['Del'], 'Path': self.__dbus_object_path__ }) item = find_item(self.items, self.__dbus_object_path__) self.items.remove(item) parent = find_item(self.items, item['Parent']) parent['ChildCount'] -= 1
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 add_to_player_health(self): """Calculating player health additions depending the food""" if self.health == 100: return print(dedent("You are at full health you do not need nourishment.")) else: valid_food = items.find_item(map.user, desired_type="food") if valid_food: food = map.user.get_player_item_val(valid_food.name, map.user) if food: if food == 1: dropping = player_inventory.drop(validated=True) elif food > 1: self.health += valid_food.health_add food -= 1 if self.health > 100: self.health = 100 return print(dedent("Your health is now {}".format(self.health)))
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 Update(self, to_add_update, to_delete): item = find_item(self.items, self.__dbus_object_path__) for prop in to_delete: del item[prop] for prop, val in to_add_update.items(): item[prop] = val device = get_object(find_root(self.items, self.__dbus_object_path__)['Path']) device.queue_change ({ 'ChangeType': CHANGE_TYPES['Mod'], 'Path': self.__dbus_object_path__ })
def Update(self, to_add_update, to_delete): item = find_item(self.items, self.__dbus_object_path__) for prop in to_delete: del item[prop] for prop, val in to_add_update.items(): item[prop] = val device = get_object( find_root(self.items, self.__dbus_object_path__)['Path']) device.queue_change({ 'ChangeType': CHANGE_TYPES['Mod'], 'Path': self.__dbus_object_path__ })
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,)
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, )
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 drop(self, validated=False): if validated == False: valid_item = items.find_item(map.user) if valid_item: item = self.get_player_item_val(valid_item.name, map.user) if item: self.player_inventory.pop(valid_item.name) print(dedent('The {} has been removed from your inventory.'.format(valid_item.name))) else: map.message_pop_up(dedent('Not a valid item, try again.')) return item else: map.message_pop_up(dedent('Not an item, try again.')) return valid_item else: self.player_inventory.pop(valid_item.name) print(dedent('The {} has been removed from your inventory.'.format(valid_item.name)))