Skip to content

Commit

Permalink
Shotgrid pyblish plugin: reuse existing version
Browse files Browse the repository at this point in the history
  • Loading branch information
jlorrain authored and ClementHector committed Feb 7, 2022
1 parent bd892a6 commit 62d43d6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ def process(self, context):
self.log.info("Collected correspondig shotgrid entity : {}".format(sg_entity))


def _find_existing_version(self, code, context):

filters = [
["project", "is", context.data.get("shotgridProject")],
["sg_task", "is", context.data.get("shotgridTask")],
["entity", "is", context.data.get("shotgridEntity")],
["code", "is", code]
]

sg = context.data.get("shotgridSession")
return sg.find_one("Version", filters, [])


def _get_shotgrid_collection(project):
mongo_url = os.getenv("OPENPYPE_MONGO")
client = MongoClient(mongo_url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,53 @@ class IntegrateShotgridVersion(pyblish.api.ContextPlugin):
order = pyblish.api.IntegratorOrder+0.497
label = "Shotgrid Version"

sg = None

def process(self, context):

sg = context.data.get("shotgridSession")
self.sg = context.data.get("shotgridSession")

code = os.path.splitext(os.path.basename(context.data.get("currentFile")))[0]

version = self._find_existing_version(code, context)

if not version:
version = self._create_version(code, context)
self.log.info("Create Shotgrid version: {}".format(version))
else:
self.log.info("Use existing Shotgrid version: {}".format(version))

context.data["shotgridVersion"] = version

def _find_existing_version(self, code, context):

filters = [
["project", "is", context.data.get("shotgridProject")],
["sg_task", "is", context.data.get("shotgridTask")],
["entity", "is", context.data.get("shotgridEntity")],
["code", "is", code]
]
return self.sg.find_one("Version", filters, [])

def _create_version(self, code, context):

version_data = {
"project": context.data.get("shotgridProject"),
"code": code,
"sg_task": context.data.get("shotgridTask"),
"entity": context.data.get("shotgridEntity")
"entity": context.data.get("shotgridEntity"),
"code": code,
}
print(version_data)
version = sg.create("Version", version_data)
context.data["shotgridVersion"] = version

self.log.info("Created Shotgrid version: {}".format(version))
version_data = {**version_data, **_additional_version_data(context)}

return self.sg.create("Version", version_data)


def _additional_version_data(context):
data = {}

status = context.data.get("intent", {}).get("value")
if status:
data["sg_status_list"] = status

return data

0 comments on commit 62d43d6

Please sign in to comment.