def authenticate(options): """ Authenticates using the command line arguments or user input. :param options: OptionParser instance with values shotgun_host, shotgun_script_key and shotgun_script_name :returns: An authenticated ShotgunUser instance. """ # now authenticate to shotgun sg_auth = ShotgunAuthenticator() shotgun_host = options.shotgun_host or os.environ.get("SHOTGUN_HOST") if shotgun_host: script_name = options.shotgun_script_name or os.environ.get("SHOTGUN_SCRIPT_NAME") script_key = options.shotgun_script_key or os.environ.get("SHOTGUN_SCRIPT_KEY") if script_name is None or script_key is None: logger.error("Need to provide, host, script name and script key! Run with -h for more info.") return 2 logger.info("Connecting to %s using script user %s..." % (options.shotgun_host, script_name)) sg_user = sg_auth.create_script_user(script_name, script_key, shotgun_host) else: logger.info("Connect to any Shotgun site to collect AppStore keys.") # get user, prompt if necessary sg_user = sg_auth.get_user() # Make sure our session is not out of date. sg_user.refresh_credentials() return sg_user
def authenticate(options): """ Authenticates using the command line arguments or user input. :param options: OptionParser instance with values shotgun_host, shotgun_script_key and shotgun_script_name :returns: An authenticated ShotgunUser instance. """ # now authenticate to shotgun sg_auth = ShotgunAuthenticator() if options.shotgun_host: script_name = options.shotgun_script_name script_key = options.shotgun_script_key if script_name is None or script_key is None: logger.error("Need to provide, host, script name and script key! Run with -h for more info.") return 2 logger.info("Connecting to %s using script user %s..." % (options.shotgun_host, script_name)) sg_user = sg_auth.create_script_user(script_name, script_key, options.shotgun_host) else: logger.info("Connect to any Shotgun site to collect AppStore keys.") # get user, prompt if necessary sg_user = sg_auth.get_user() # Make sure our session is not out of date. sg_user.refresh_credentials() return sg_user
def main(): """ Main entry point for script. Handles argument parsing and validation and then calls the script payload. """ usage = "%prog [options] source_path target_path" desc = "Builds a standard toolkit plugin structure ready for testing and deploy" epilog = """ Details and Examples -------------------- In its simplest form, just provide a source and target folder for the build. > python build_plugin.py ~/dev/tk-maya/plugins/basic /tmp/maya-plugin For automated build setups, you can provide a specific shotgun API script name and and corresponding script key: > python build_plugin.py --shotgun-host='https://mysite.shotgunstudio.com' --shotgun-script-name='plugin_build' --shotgun-script-key='<script-key-here>' ~/dev/tk-maya/plugins/basic /tmp/maya-plugin By default, the build script will use the latest app store core for its bootstrapping. If you want to use a specific core for the bootstrap, this can be specified via the --bootstrap-core-uri option: > python build_plugin.py --bootstrap-core-uri='sgtk:descriptor:dev?path=~/dev/tk-core' ~/dev/tk-maya/plugins/basic /tmp/maya-plugin For information about the various descriptors that can be used, see http://developer.shotgunsoftware.com/tk-core/descriptor """ parser = OptionParserLineBreakingEpilog(usage=usage, description=desc, epilog=epilog) parser.add_option("-d", "--debug", default=False, action="store_true", help="Enable debug logging") parser.add_option( "-b", "--buildable", default=False, action="store_true", help= ("Don't cull config files as part of the build process. Enabling this setting " "means that the built plugin can be used as a source for another build." )) parser.add_option( "-c", "--bootstrap-core-uri", default=None, action="store", help= ("Specify which version of core to be used by the bootstrap process. " "If not specified, defaults to the most recently released core.")) group = optparse.OptionGroup( parser, "Shotgun Authentication", "In order to download content from the Toolkit app store, the script will need to authenticate " "against any shotgun site. By default, it will use the toolkit authentication APIs stored " "credentials, and if such are not found, it will prompt for site, username and password." ) group.add_option("-s", "--shotgun-host", default=None, action="store", help="Shotgun host to authenticate with.") group.add_option("-n", "--shotgun-script-name", default=None, action="store", help="Script to use to authenticate with the given host.") group.add_option( "-k", "--shotgun-script-key", default=None, action="store", help="Script key to use to authenticate with the given host.") parser.add_option_group(group) # parse cmd line (options, remaining_args) = parser.parse_args() logger.info("Welcome to the Toolkit plugin builder.") logger.info("") if options.debug: LogManager().global_debug = True if options.bootstrap_core_uri: bootstrap_core_uri = options.bootstrap_core_uri else: # default bootstrap_core_uri = None if len(remaining_args) != 2: parser.print_help() return 2 # get paths source_path = remaining_args[0] target_path = remaining_args[1] # convert any env vars and tildes source_path = os.path.expanduser(os.path.expandvars(source_path)) target_path = os.path.expanduser(os.path.expandvars(target_path)) # now authenticate to shotgun sg_auth = ShotgunAuthenticator() if options.shotgun_host: script_name = options.shotgun_script_name script_key = options.shotgun_script_key if script_name is None or script_key is None: logger.error( "Need to provide, host, script name and script key! Run with -h for more info." ) return 2 logger.info("Connecting to %s using script user %s..." % (options.shotgun_host, script_name)) sg_user = sg_auth.create_script_user(script_name, script_key, options.shotgun_host) else: # get user, prompt if necessary sg_user = sg_auth.get_user() sg_connection = sg_user.create_sg_connection() # make sure we are properly connected try: sg_connection.find_one("HumanUser", []) except Exception, e: logger.error("Could not communicate with Shotgun: %s" % e) return 3
def main(): """ Main entry point for script. Handles argument parsing and validation and then calls the script payload. """ usage = "%prog [options] source_path target_path" desc = "Builds a standard toolkit plugin structure ready for testing and deploy" epilog = """ Details and Examples -------------------- In its simplest form, just provide a source and target folder for the build. > python build_plugin.py ~/dev/tk-maya/plugins/basic /tmp/maya-plugin For automated build setups, you can provide a specific shotgun API script name and and corresponding script key: > python build_plugin.py --shotgun-host='https://mysite.shotgunstudio.com' --shotgun-script-name='plugin_build' --shotgun-script-key='<script-key-here>' ~/dev/tk-maya/plugins/basic /tmp/maya-plugin By default, the build script will use the latest app store core for its bootstrapping. If you want to use a specific core for the bootstrap, this can be specified via the --bootstrap-core-uri option: > python build_plugin.py --bootstrap-core-uri='sgtk:descriptor:dev?path=~/dev/tk-core' ~/dev/tk-maya/plugins/basic /tmp/maya-plugin For information about the various descriptors that can be used, see http://developer.shotgunsoftware.com/tk-core/descriptor """ parser = OptionParserLineBreakingEpilog(usage=usage, description=desc, epilog=epilog) parser.add_option( "-d", "--debug", default=False, action="store_true", help="Enable debug logging" ) parser.add_option( "-b", "--buildable", default=False, action="store_true", help=("Don't cull config files as part of the build process. Enabling this setting " "means that the built plugin can be used as a source for another build.") ) parser.add_option( "-c", "--bootstrap-core-uri", default=None, action="store", help=("Specify which version of core to be used by the bootstrap process. " "If not specified, defaults to the most recently released core.") ) group = optparse.OptionGroup( parser, "Shotgun Authentication", "In order to download content from the Toolkit app store, the script will need to authenticate " "against any shotgun site. By default, it will use the toolkit authentication APIs stored " "credentials, and if such are not found, it will prompt for site, username and password." ) group.add_option( "-s", "--shotgun-host", default=None, action="store", help="Shotgun host to authenticate with." ) group.add_option( "-n", "--shotgun-script-name", default=None, action="store", help="Script to use to authenticate with the given host." ) group.add_option( "-k", "--shotgun-script-key", default=None, action="store", help="Script key to use to authenticate with the given host." ) parser.add_option_group(group) # parse cmd line (options, remaining_args) = parser.parse_args() logger.info("Welcome to the Toolkit plugin builder.") logger.info("") if options.debug: LogManager().global_debug = True if options.bootstrap_core_uri: bootstrap_core_uri = options.bootstrap_core_uri else: # default bootstrap_core_uri = None if len(remaining_args) != 2: parser.print_help() return 2 # get paths source_path = remaining_args[0] target_path = remaining_args[1] # convert any env vars and tildes source_path = os.path.expanduser(os.path.expandvars(source_path)) target_path = os.path.expanduser(os.path.expandvars(target_path)) # now authenticate to shotgun sg_auth = ShotgunAuthenticator() if options.shotgun_host: script_name = options.shotgun_script_name script_key = options.shotgun_script_key if script_name is None or script_key is None: logger.error("Need to provide, host, script name and script key! Run with -h for more info.") return 2 logger.info("Connecting to %s using script user %s..." % (options.shotgun_host, script_name)) sg_user = sg_auth.create_script_user(script_name, script_key, options.shotgun_host) else: # get user, prompt if necessary sg_user = sg_auth.get_user() sg_connection = sg_user.create_sg_connection() # make sure we are properly connected try: sg_connection.find_one("HumanUser", []) except Exception, e: logger.error("Could not communicate with Shotgun: %s" % e) return 3