本文整理汇总了Python中api.API.projects方法的典型用法代码示例。如果您正苦于以下问题:Python API.projects方法的具体用法?Python API.projects怎么用?Python API.projects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api.API
的用法示例。
在下文中一共展示了API.projects方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FrontEnd
# 需要导入模块: from api import API [as 别名]
# 或者: from api.API import projects [as 别名]
class FrontEnd(object):
def config_get(self, key):
config = ConfigParser.ConfigParser()
config.read((GLOBAL, LOCAL)) # local will override global
try:
value = config.get(CONFIG_SECTION, key)
except ConfigParser.NoOptionError:
value = False
return value
def config_set(self, key, data):
config = ConfigParser.ConfigParser()
config.read(GLOBAL)
if not config.has_section(CONFIG_SECTION):
config.add_section(CONFIG_SECTION)
config.set(CONFIG_SECTION, key, data)
with open(GLOBAL, 'wb') as config_file:
config.write(config_file)
def env(self, args):
self.preflight()
if args.env and not args.all:
env = self.config_get('env')
if env:
print(env)
else:
print('No env set')
if args.all:
try:
for env in self.api.envs():
print(env['name'])
except requests.HTTPError:
self.exit_with_error(BASE_HTTP_ERROR_MESSAGE)
def env_does_not_exist(self, project, env):
print('"{0}" isn\'t an environment for "{1}", try:'.format(env, project))
for env in self.api.projects(project)['envs']:
print(' * {0}'.format(env))
sys.exit(1)
def exit_with_error(self, msg, args=()):
sys.stderr.write(colored(msg.format(*args) + '\n', 'red'))
sys.exit(1)
def get(self, args):
self.preflight()
project = self.get_var('project', args.project)
env = self.get_var('env', args.env)
try:
pairs = self.api.pairs(project, env)
except requests.HTTPError:
self.exit_with_error(BASE_HTTP_ERROR_MESSAGE)
except NoDeploymentVars:
msg = '"{0}: {1}" has no environment variables.'
print(msg.format(project, env))
except ProjectDoesNotExist:
self.project_does_not_exist(project)
except EnvDoesNotExist:
self.env_does_not_exist(project, env)
else:
for pair in pairs.items():
print('{0}={1}'.format(*pair))
def get_var(self, var, cli_arg):
v = cli_arg if cli_arg else self.config_get(var)
if not v:
self.exit_with_error('No {0} specified. Use --{0} or set it in your local .hoard'.format(var))
return v
def login(self, args=None):
url = self.config_get('url')
if not url:
self.set_url()
print('hoard needs to request an access token.')
print('Your username and password never stored. (Check ~/.hoardrc).\n')
username = raw_input('Username: ')
password = getpass.getpass()
try:
token = get_token(url, username, password)
except requests.HTTPError:
self.exit_with_error(BASE_HTTP_ERROR_MESSAGE)
self.config_set('token', token)
self.api = API(url, token)
print('You have successfully logged in')
def logout(self, args):
config = ConfigParser.ConfigParser()
config.read(GLOBAL)
config.remove_option(CONFIG_SECTION, 'token')
with open(GLOBAL, 'wb') as config_file:
config.write(config_file)
def preflight(self):
#.........这里部分代码省略.........