From eca3ecec33c2d3699e3c7f9f4cc57ceda2f762ca Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Fri, 5 Jun 2020 19:11:40 +0200 Subject: [PATCH 1/4] first shot of possible version for updating to equivalent version to master --- avalon/tools/sceneinventory/app.py | 79 ++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 5 deletions(-) diff --git a/avalon/tools/sceneinventory/app.py b/avalon/tools/sceneinventory/app.py index 07357ef5e..30ce49379 100644 --- a/avalon/tools/sceneinventory/app.py +++ b/avalon/tools/sceneinventory/app.py @@ -123,7 +123,76 @@ def build_item_menu_for_selection(self, items, menu): if has_outdated: break - updatetolatest_action = None + update_to_versioned = None + if has_loaded_master_versions: + def _on_update_to_versioned(items): + repre_ids = [] + for item in items: + item_id = io.ObjectId(item["representation"]) + if item_id not in repre_ids: + repre_ids.append(item_id) + + repre_entities = io.find({ + "type": "representation", + "_id": {"$in": repre_ids} + }) + + version_ids = [] + master_version_id_by_repre_id = {} + for repre in repre_entities: + version_id = repre["parent"] + master_version_id_by_repre_id[repre["_id"]] = version_id + if version_id not in parent_ids: + version_ids.append(version_id) + + master_versions = list(io.find({ + "_id": {"$in": version_ids}, + "type": "master_version" + })) + + version_ids = set() + version_id_by_repre_id = {} + for master_version in master_versions: + version_id = master_version["version_id"] + version_ids.set(version_id) + master_version_id = master_version["_id"] + for _repre_id, _master_version_id in ( + master_version_id_by_repre_id.items() + ): + if _master_version_id == master_version_id: + version_id_by_repre_id[_repre_id] = version_id + + version_docs = io.find({ + "_id": {"$in": list(version_ids)}, + "type": "version" + }) + version_name_by_id = {} + for version in version_docs: + version_name_by_id[version["_id"]] = version["name"] + + for item in items: + repre_id = io.ObjectId(item["representation"]) + version_id = version_id_by_repre_id.get(repre_id) + version_name = version_name_by_id.get(version_id) + if version_name is None: + continue + api.update(item, version_name) + self.data_changed.emit() + + update_icon = qtawesome.icon( + "fa.asterisk", + color=DEFAULT_COLOR + ) + update_to_versioned = QtWidgets.QAction( + update_icon, + "Update to versioned", + menu + ) + update_to_versioned.triggered.connect( + lambda: _on_update_to_versioned(items) + ) + + update_to_latest_action = None if has_outdated or has_loaded_master_versions: # update to latest version def _on_update_to_latest(items): @@ -135,12 +204,12 @@ def _on_update_to_latest(items): "fa.angle-double-up", color=DEFAULT_COLOR ) - updatetolatest_action = QtWidgets.QAction( + update_to_latest_action = QtWidgets.QAction( update_icon, "Update to latest", menu ) - updatetolatest_action.triggered.connect( + update_to_latest_action.triggered.connect( lambda: _on_update_to_latest(items) ) @@ -193,8 +262,8 @@ def _on_update_to_master(items): lambda: self.show_remove_warning_dialog(items)) # add the actions - if updatetolatest_action: - menu.addAction(updatetolatest_action) + if update_to_latest_action: + menu.addAction(update_to_latest_action) if change_to_master: menu.addAction(change_to_master) From f291fffadceb2b475aa25e00fea22e966a398abd Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Mon, 20 Jul 2020 12:23:36 +0200 Subject: [PATCH 2/4] renamed update_to_versioned to switch_to_versioned --- avalon/tools/sceneinventory/app.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/avalon/tools/sceneinventory/app.py b/avalon/tools/sceneinventory/app.py index 9e3890016..63ac67e9e 100644 --- a/avalon/tools/sceneinventory/app.py +++ b/avalon/tools/sceneinventory/app.py @@ -121,9 +121,9 @@ def build_item_menu_for_selection(self, items, menu): if has_outdated: break - update_to_versioned = None + switch_to_versioned = None if has_loaded_master_versions: - def _on_update_to_versioned(items): + def _on_switch_to_versioned(items): repre_ids = [] for item in items: item_id = io.ObjectId(item["representation"]) @@ -181,13 +181,13 @@ def _on_update_to_versioned(items): "fa.asterisk", color=DEFAULT_COLOR ) - update_to_versioned = QtWidgets.QAction( + switch_to_versioned = QtWidgets.QAction( update_icon, - "Update to versioned", + "Switch to versioned", menu ) - update_to_versioned.triggered.connect( - lambda: _on_update_to_versioned(items) + switch_to_versioned.triggered.connect( + lambda: _on_switch_to_versioned(items) ) update_to_latest_action = None From 79d179eabeedfdf4ff1f374ac09b7528201d00a2 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Mon, 20 Jul 2020 12:23:50 +0200 Subject: [PATCH 3/4] added switch to versioned to menu(to see it) --- avalon/tools/sceneinventory/app.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/avalon/tools/sceneinventory/app.py b/avalon/tools/sceneinventory/app.py index 63ac67e9e..93179def8 100644 --- a/avalon/tools/sceneinventory/app.py +++ b/avalon/tools/sceneinventory/app.py @@ -260,6 +260,9 @@ def _on_update_to_master(items): lambda: self.show_remove_warning_dialog(items)) # add the actions + if switch_to_versioned: + menu.addAction(switch_to_versioned) + if update_to_latest_action: menu.addAction(update_to_latest_action) From a32afc565715b8c7580764a4cd5dbd13aec33307 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Mon, 20 Jul 2020 14:24:33 +0200 Subject: [PATCH 4/4] fix logic --- avalon/tools/sceneinventory/app.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/avalon/tools/sceneinventory/app.py b/avalon/tools/sceneinventory/app.py index 93179def8..dffe89b7d 100644 --- a/avalon/tools/sceneinventory/app.py +++ b/avalon/tools/sceneinventory/app.py @@ -136,11 +136,11 @@ def _on_switch_to_versioned(items): }) version_ids = [] - master_version_id_by_repre_id = {} + version_id_by_repre_id = {} for repre in repre_entities: version_id = repre["parent"] - master_version_id_by_repre_id[repre["_id"]] = version_id - if version_id not in parent_ids: + version_id_by_repre_id[repre["_id"]] = version_id + if version_id not in version_ids: version_ids.append(version_id) master_versions = list(io.find({ @@ -149,15 +149,14 @@ def _on_switch_to_versioned(items): })) version_ids = set() - version_id_by_repre_id = {} for master_version in master_versions: version_id = master_version["version_id"] - version_ids.set(version_id) + version_ids.add(version_id) master_version_id = master_version["_id"] - for _repre_id, _master_version_id in ( - master_version_id_by_repre_id.items() + for _repre_id, _version_id in ( + version_id_by_repre_id.items() ): - if _master_version_id == master_version_id: + if _version_id == master_version_id: version_id_by_repre_id[_repre_id] = version_id version_docs = io.find({ @@ -172,9 +171,9 @@ def _on_switch_to_versioned(items): repre_id = io.ObjectId(item["representation"]) version_id = version_id_by_repre_id.get(repre_id) version_name = version_name_by_id.get(version_id) - if version_name is None: - continue - api.update(item, version_name) + if version_name is not None: + api.update(item, version_name) + self.data_changed.emit() update_icon = qtawesome.icon(