当前位置: 首页>>代码示例>>Python>>正文


Python API.rm方法代码示例

本文整理汇总了Python中api.API.rm方法的典型用法代码示例。如果您正苦于以下问题:Python API.rm方法的具体用法?Python API.rm怎么用?Python API.rm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在api.API的用法示例。


在下文中一共展示了API.rm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: FrontEnd

# 需要导入模块: from api import API [as 别名]
# 或者: from api.API import rm [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):
#.........这里部分代码省略.........
开发者ID:ghickman,项目名称:hoard-cli,代码行数:103,代码来源:frontend.py


注:本文中的api.API.rm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。