This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Add ftrack user action to deactivate invalid projects
- Loading branch information
Cyprien CAILLOT
committed
Sep 11, 2024
1 parent
d9731d0
commit 3ab0856
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
openpype/modules/ftrack/event_handlers_user/action_desactivate_obsolete_projects.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from pymongo import UpdateOne | ||
|
||
from openpype.client import get_projects | ||
from openpype.pipeline import AvalonMongoDB | ||
from openpype_modules.ftrack.lib import BaseAction, statics_icon | ||
|
||
|
||
class DeactivateObsoleteProjects(BaseAction): | ||
"""Deactivate projects on OP that no longer exist on Ftrack | ||
or that doesn't have an FtrackId | ||
""" | ||
|
||
identifier = "deactivate.obsolete.projects" | ||
show_identifier = "deactivate.obsolete.projects" | ||
label = "OpenPype Admin" | ||
variant = "- Deactivate Obsolete Projects" | ||
description = "Deactivate projects on OP that no longer exist on Ftrack or have an invalid FtrackId." | ||
icon = statics_icon("ftrack", "action_icons", "HideProjects.svg") | ||
|
||
def __init__(self, session): | ||
self.dbcon = AvalonMongoDB() | ||
super().__init__(session) | ||
|
||
def _discover(self, _event): | ||
return { | ||
"items": [{ | ||
"label": self.label, | ||
"variant": self.variant, | ||
"description": self.description, | ||
"actionIdentifier": self.discover_identifier, | ||
"icon": self.icon, | ||
}] | ||
} | ||
|
||
def _launch(self, event): | ||
self.trigger_action(self.show_identifier, event) | ||
|
||
def register(self): | ||
# Register default action callbacks | ||
super(DeactivateObsoleteProjects, self).register() | ||
|
||
# # Add show identifier | ||
show_subscription = ( | ||
"topic=ftrack.action.launch" | ||
" and data.actionIdentifier={}" | ||
" and source.user.username={}" | ||
).format( | ||
self.show_identifier, | ||
self.session.api_user | ||
) | ||
self.session.event_hub.subscribe( | ||
show_subscription, | ||
self.deactivate_obsolete_projects | ||
) | ||
|
||
def deactivate_obsolete_projects(self, event): | ||
ftrack_projects = self.session.query("Project").all() | ||
ftrack_projects_ids = [project["id"] for project in ftrack_projects] | ||
mongo_projects = get_projects() | ||
|
||
projects_to_deactivate = [] | ||
for project in mongo_projects: | ||
if "ftrackId" not in project["data"].keys(): | ||
projects_to_deactivate.append(project) | ||
elif project["data"]["ftrackId"] not in ftrack_projects_ids: | ||
projects_to_deactivate.append(project) | ||
|
||
for project in projects_to_deactivate: | ||
filter_dict = {"_id": project["_id"]} | ||
change_data = {"$set": {"data.active": False}} | ||
self.dbcon.Session["AVALON_PROJECT"] = project["name"] | ||
self.dbcon.bulk_write([UpdateOne(filter_dict, change_data)]) | ||
self.log.debug(f"No FtrackId for project {project['name']}" | ||
" or project deleted from Ftrack." | ||
" Project has been deactivated.") | ||
|
||
|
||
def register(session): | ||
DeactivateObsoleteProjects(session).register() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.