def get_items_ids(search_attributes): """Returns item id for all items in the default collection matching `search_attributes`.""" bus = dbus_init() collection = get_any_collection(bus) search_results = collection.search_items(search_attributes) return [item._item_id() for item in search_results]
def test_closing_context_manager(self) -> None: with closing(dbus_init()) as connection: self.assertTrue(check_service_availability(connection)) collection = get_any_collection(connection) self.assertIsNotNone(collection) label = collection.get_label() self.assertIsNotNone(label)
def create_item(label, attributes, secret, unlock=True): """Creates an item with given `label`, `attributes` and `secret` in the default collection. Returns id of the created item.""" bus = dbus_init() collection = get_any_collection(bus) if unlock and collection.is_locked(): collection.unlock() item = collection.create_item(label, attributes, secret) return item._item_id()
def get_item_object(item_id, unlock=True): """Returns the item with given id and unlocks it if `unlock` is `True`.""" bus = dbus_init() collection = get_any_collection(bus) item = Item(bus, join(collection.collection_path, str(item_id))) if unlock and collection.is_locked(): collection.unlock() return item
def get_items(search_attributes, unlock_all=True): """Returns tuples for all items in the default collection matching `search_attributes`.""" bus = dbus_init() collection = get_any_collection(bus) if unlock_all and collection.is_locked(): collection.unlock() search_results = collection.search_items(search_attributes) return [item.to_tuple() for item in search_results]
def get_item_attributes(item_id): """Returns item attributes for item with given id.""" bus = dbus_init() collection = get_any_collection(bus) item = Item(bus, join(collection.collection_path, str(item_id))) return item.get_attributes()