Open maximcapra opened 4 years ago
Hi, we need to update the readme to cover this, but I'll answer here first.
$SHOTGUN_INFO is set to point to a json file, which contains some information about project paths and id's, here's an example:
{
"install":
{
"s118": "/proj/s118",
"s119": "/proj/s119",
"s120": "/proj/s120"
},
"platform":
{
"windows": "win32",
"linux": "linux2",
"osx": "darwin"
},
"id":
{
"s118": "129",
"s119": "164",
"s120": "167"
}
}
The idea is the user decided when to set this env var on their system. We actually set all this via rez packages, however the idea behind this env var / json file was to make it not dependant on the package manager we use in any way.
Hope that helps,
cheers
turret_resolver also relies on an env var being set called $SG_API_KEY, which specifies your own API key (keep that out of public source control obviously).
I'll try to update the documentation to cover these env vars soon.
Oh and one more, we mostly use a shared tk config across all our shotgun projects, so we use this env var to point to the "tank" module location in that shared config.
turret_resolver also relies on an env var being set called $SG_API_KEY, which specifies your own API key (keep that out of public source control obviously).
I'll try to update the documentation to cover these env vars soon.
I see. The authentification is pretty straight forward, I was just wondering about the other custom stuff. Is there a reason, why you did not choose to authenticate and get the project, tank and sgtk via the shotgun_api3 python module? This seems pretty complicated to me and maybe I don't fully understand why it is done this way, but I would like to avoid creating additional files (and update them) just for project and path information ... btw, using conda here as a package manager instead of rez ....
Thanks so much for the json example and the explanation, wasn't obvious for me what's going on in the background, this helps a lot!
Generally as something developed at a university with a very small crew, there's probably some areas that could be improved such as authentication as you suggested. We had a pretty aggressive timeframe to put all of this into a working state for student projects, so it's entirely possible there's a better way to handle the authentication. If you have any examples of the shotgun_api3 approach I'd be keen to adopt that approach, cheers.
You did an absolute outstanding job! Even better, you put it on Github for others, I would not be able to pull this off by myself. I'm currently rewriting the resolver to fit our needs here in our studio. Basically you can get a lot of info about your projects with the api3 module like this:
import shotgun_api3
import os
sg = shotgun_api3.Shotgun(os.environ["SG_SITE"], script_name=os.environ["SG_SCRIPT_NAME"], api_key=os.environ["SG_SCRIPT_KEY"])
# Find all projects
fields = [
"id",
"code",
"windows_path",
"linux_path",
"mac_path",
"project",
"project.Project.tank_name",
"project.Project.code",
]
projects = sg.find("PipelineConfiguration",[],fields)
for project in projects:
print project
So I am basically trying to get the sgtk and the tank paths from there. We have no shared tank setup here, every Project has it's own sgtk and pipeline configuration. Like this:
import shotgun_api3
import os
class Shotgun_Data():
def __init__(self):
self.sg = shotgun_api3.Shotgun(os.environ["SG_SITE"], script_name=os.environ["SG_SCRIPT_NAME"], api_key=os.environ["SG_SCRIPT_KEY"])
def close_connection(self):
self.sg.close()
def get_pipeline_config(self, tank_name):
filters = [["project.Project.tank_name", "is", tank_name]]
fields = ["id",
"code",
"windows_path",
"linux_path",
"mac_path",
"project",
"project.Project.tank_name",
"project.Project.code",
"project.Project.sg_resolution"]
pipeline_config = self.sg.find_one("PipelineConfiguration", filters, fields)
return pipeline_config
def import_sgtk():
sg_connection = Shotgun_Data()
# get pipeline config
pipeline_path = None
project_config = sg_connection.get_pipeline_config("INSERT_tank_name_HERE")
# Generate Pipeline Path
if project_config:
windows_path = project_config["windows_path"]
linux_path = project_config["linux_path"]
mac_path = project_config["mac_path"]
os_name = platform.system()
if os_name == "Windows":
pipeline_path = windows_path
if os_name == "Linux":
pipeline_path = linux_path
if os_name == "Darwin":
pipeline_path = mac_path
else:
return
# Add SGTK-Module path to sys
sgtk_module_path = os.path.join(os.path.normpath(pipeline_path), "install", "core", "python")
if not sgtk_module_path in sys.path:
sys.path.insert(0, sgtk_module_path)
# Import Module and Create TANK Instance
import sgtk
When is this environment variable set and what is the content of this file? Is this a custom file or does it come with the shotgun installation?