Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement project metadata feature through WireTapCom. #34

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions client/ayon_flame/api/scripts/wiretap_com.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
import subprocess
import json
import tempfile
import xml.dom.minidom as minidom
from copy import deepcopy
import datetime
Expand Down Expand Up @@ -459,6 +460,76 @@ def _set_project_colorspace(self, project_name, color_policy):
color_policy, project_name
))

@staticmethod
def get_project_metadata(project_name):
"""Retrieve project metadata as XML.

Args:
project_name (str): name of the project.

Returns:
str. The metadata formatted as XML.

Raises:
RuntimeError. When metadata could not be fetched.
"""
wiretap_tools_dir = os.getenv("AYON_WIRETAP_TOOLS")
get_metadata_cmd = os.path.join(
wiretap_tools_dir,
"wiretap_get_metadata",
)

cmd = [
get_metadata_cmd,
"-n", f"/projects/{project_name}",
"-s", "XML"
]

try:
return subprocess.check_output(cmd)

except subprocess.CalledProcessError as error:
raise RuntimeError(
f"Cannot retrieve metadata for {project_name}"
) from error

@staticmethod
def set_project_metadata(project_name, xml_metadata):
"""Retrieve project metadata as XML.

Args:
project_name (str): name of the project.
xml_metadata (str): new metadata formatted as XML.

Returns:
bool. Has the metadata been edited.
"""
wiretap_tools_dir = os.getenv("AYON_WIRETAP_TOOLS")
set_metadata_cmd = os.path.join(
wiretap_tools_dir,
"wiretap_set_metadata",
)

with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
tmp_file.write(xml_metadata.encode())

cmd = [
set_metadata_cmd,
"-n", f"/projects/{project_name}",
"-s", "XML",
"-f", tmp_file.name
]

try:
subprocess.check_output(cmd)
return True

except subprocess.CalledProcessError:
return False

finally:
os.remove(tmp_file.name)


def _subprocess_preexec_fn():
""" Helper function
Expand Down