本文整理汇总了Python中config.Configuration.set_environment方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.set_environment方法的具体用法?Python Configuration.set_environment怎么用?Python Configuration.set_environment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类config.Configuration
的用法示例。
在下文中一共展示了Configuration.set_environment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import set_environment [as 别名]
def main():
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)
fmt = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
handler.setFormatter(fmt)
logger.addHandler(handler)
usage='Usage: %s [options] subcommand [args]' % commands.progname
parser = OptionParser(usage=usage, add_help_option=False)
parser.add_option("--debug", dest="debug", action="store_true", help="Enable debug output")
parser.add_option("-c", "--config-path", dest="base_path", default=None, help="Path to configuration files")
parser.add_option("-i", "--key-id", dest="key_id", default=None, help="Scalr API key ID")
parser.add_option("-a", "--access-key", dest="key", default=None, help="Scalr API access key")
parser.add_option("-l", "--login", dest="ldap_login", default=None, help="Login for LDAP authentication")
parser.add_option("-p", "--password", dest="ldap_password", default=None, help="Password for LDAP authentication")
parser.add_option("-u", "--api-url", dest="api_url", default=None, help="Scalr API URL (IF you use open source Scalr installation)")
parser.add_option("-e", "--env-id", dest="env_id", default=None, help="Scalr Environment ID")
parser.add_option("-h", "--help", dest="help", action="store_true", help="Help")
args, cmd, subargs = split_options(sys.argv)
subcommands = sorted([command.name for command in get_commands() if not command.name.startswith('_')])
help = parser.format_help() + \
'\nAvailable subcommands:\n\n' + '\n'.join(subcommands) + \
"\n\nFor more information try '%s help <subcommand>'" % commands.progname
options = parser.parse_args(args)[0]
if not cmd or options.help:
print help
sys.exit(1)
try:
c = Configuration(options.base_path)
c.set_environment(options.key, options.key_id, options.api_url, options.env_id, options.ldap_login, options.ldap_password)
if options.debug:
c.set_logger(logger)
except ScalrEnvError, e:
if not cmd.startswith('configure') and cmd != 'help':
print "\nNo login information found."
print "Please specify options -i -a and -u, or run '%s help configure' to find out how to set login information permanently.\n" % commands.progname
#print help
sys.exit(1)