How do I update my Project's core programmatically with the API?

If you want to update your Project's core version from a script in order to run it non-interactively, you can do so using the following code:

import sys
sys.path.append("<path_to_your_config>/install/core/python")
import sgtk

# substitute your Project id here or alternatively use sgtk_from_path()
tk = sgtk.sgtk_from_entity('Project', 161)
c=tk.get_command("core")

# setup authentication
if hasattr(sgtk, "set_authenticated_user"): 
     from tank_vendor.shotgun_authentication import ShotgunAuthenticator
     user = ShotgunAuthenticator(sgtk.util.CoreDefaultsManager()).get_default_user() 
     sgtk.set_authenticated_user(user)

# finally, execute the command
c.execute({})

This will update the Toolkit core to the latest version without any further interaction or confirmation. If the core you are running this from is a shared core, this will update the core version that is used by all projects sharing this core version! Just be sure you're aware of this before proceeding.

 

See also:

Follow

0 Comments

Please sign in to leave a comment.