def sgwi(): """ Shotgun with authentification""" import sgtk from tank_vendor.shotgun_authentication import ShotgunAuthenticator cdm = sgtk.util.CoreDefaultsManager() authenticator = ShotgunAuthenticator(cdm) user = authenticator.create_script_user(api_script="Toolkit",api_key="cdeb3545052b2afeec449c43deda7c857558a067658b52033ce489d0789d6aff") sgtk.set_authenticated_user(user) return sgtk.sgtk_from_path(cf.get_primary_data_root())
def tk_connect(api_script, api_key): # Import Toolkit so we can access to Toolkit specific features. # Import the ShotgunAuthenticator from the tank_vendor.shotgun_authentication # module. This class allows you to authenticate either interactively or, in this # case, programmatically. from tank_vendor.shotgun_authentication import ShotgunAuthenticator # Instantiate the CoreDefaultsManager. This allows the ShotgunAuthenticator to # retrieve the site, proxy and optional script_user credentials from shotgun.yml cdm = sgtk.util.CoreDefaultsManager() # Instantiate the authenticator object, passing in the defaults manager. authenticator = ShotgunAuthenticator(cdm) # Create a user programmatically using the script"s key. user = authenticator.create_script_user(api_script, api_key) # print "User is "%s"" % user # Tells Toolkit which user to use for connecting to Shotgun. sgtk.set_authenticated_user(user)
def publish_preview(src_path): # src_path = 'D:/work/amg/projects/dev/sequences/EP001/SH001/Anim/work/maya/scene1.mb'.replace('/','\\') trg_path = 'D:/work/amg/projects/dev/sequences/EP001/SH001/Anim/work/maya/scene1.mb'.replace( '/', '\\') sa = ShotgunAuthenticator() user = sa.create_script_user(api_script="Toolkit", api_key="", host="https://animagrad.shotgunstudio.com") sgtk.set_authenticated_user(user) tk = sgtk.sgtk_from_path(trg_path) ctx = tk.context_from_path(trg_path) publish_name = os.path.splitext(os.path.basename(src_path))[0] # thumbnail_path = path (545x300) try: sgtk.util.register_publish(tk, ctx, src_path, publish_name, 3) return True except: return False
def authenticate(self): """ Args: sgtk: Returns: """ if self.sgtk.get_authenticated_user(): if not self.sgtk.get_authenticated_user().are_credentials_expired( ): if VERBOSE: print "Credentials already exist." return if VERBOSE: print "Authenticating credentials." # Import the ShotgunAuthenticator from the tank_vendor.shotgun_authentication # module. This class allows you to authenticate either interactively or, in this # case, programmatically. from tank_vendor.shotgun_authentication import ShotgunAuthenticator # Instantiate the CoreDefaultsManager. This allows the ShotgunAuthenticator to # retrieve the site, proxy and optional script_user credentials from shotgun.yml cdm = self.sgtk.util.CoreDefaultsManager() # Instantiate the authenticator object, passing in the defaults manager. authenticator = ShotgunAuthenticator(cdm) # Create a user programmatically using the script's key. user = authenticator.create_script_user( api_script="toolkit_user", api_key=os.getenv('SG_API_KEY')) # Tells Toolkit which user to use for connecting to Shotgun. self.sgtk.set_authenticated_user(user)