class BaseHelpCommand(object): def __init__(self): self.doc = Document() self._cli_data = Loader() def _get_document_handler(self): pass def _get_service_version(self, parsed_globals): pass def _service_version(self, service_name, parsed_globals): if hasattr(parsed_globals, "action_version"): version = vars(parsed_globals)["action_version"] if version is None: version = self._cli_data.get_service_default_version(service_name) available_version_list = self._cli_data.get_available_services()[service_name] if version not in available_version_list: raise Exception("available versions: %s" % " ".join(available_version_list)) self._version = version def __call__(self, args, parsed_globals): if args: raise UnknownArgumentError("Unknown options: %s" % ', '.join(args)) self._get_service_version(parsed_globals) document_handle = self._get_document_handler() document_handle.doc_help(parsed_globals.detail) sys.stdout.write(self.doc.getvalue())
def _generate_input_skeleton(self, **kwargs): cli_data = Loader() outfile = sys.stdout skeleton = cli_data.generate_param_skeleton(self._service_name, self._version, self._action_name) json.dump(skeleton, outfile, indent=4, default=json_encoder) outfile.write('\n') return 0
def __init__(self): super(BasicConfigure, self).__init__() self.config_list = [OptionsDefine.Region, OptionsDefine.Output] self.cred_list = [OptionsDefine.SecretId, OptionsDefine.SecretKey] self.conf_service_list = [ OptionsDefine.Version, OptionsDefine.Endpoint ] self.cli_path = os.path.join(os.path.expanduser("~"), ".tccli") self._cli_data = Loader()
def __init__(self): super(BasicConfigure, self).__init__() self.config_list = [ OptionsDefine.Region, OptionsDefine.Output, OptionsDefine.ArrayCount, OptionsDefine.Warnings ] self.cred_list = [ OptionsDefine.SecretId, OptionsDefine.SecretKey, OptionsDefine.Token, OptionsDefine.RoleArn, OptionsDefine.RoleSessionName ] self.conf_service_list = [ OptionsDefine.Version, OptionsDefine.Endpoint ] self.cli_path = os.path.join(os.path.expanduser("~"), ".tccli") self._cli_data = Loader()
class BasicConfigure(BasicCommand): NAME = '' DESCRIPTION = '' USEAGE = '' OPTIONS = { "help": "show the tccli configure help info", "--profile": "specify a profile name" } EXAMPLES = '' def __init__(self): super(BasicConfigure, self).__init__() self.config_list = [ OptionsDefine.Region, OptionsDefine.Output, OptionsDefine.ArrayCount, OptionsDefine.Warnings ] self.cred_list = [ OptionsDefine.SecretId, OptionsDefine.SecretKey, OptionsDefine.Token, OptionsDefine.RoleArn, OptionsDefine.RoleSessionName ] self.conf_service_list = [ OptionsDefine.Version, OptionsDefine.Endpoint ] self.cli_path = os.path.join(os.path.expanduser("~"), ".tccli") self._cli_data = Loader() def _run_main(self, parsed_args, parsed_globals): raise NotImplementedError("_run_main") def _init_configure(self, profile_name, input_data, extra={}): conf_data = {} is_exist, config_path = self._profile_existed(profile_name) if is_exist: conf_data = Utils.load_json_msg(config_path) for k in input_data.keys(): conf_data[k] = input_data[k] if profile_name.endswith(".configure"): for mod in self._cli_data.get_available_services().keys(): # we have to check autoscaling because we did it wrong in 3.0.30.1 # consider remove it in 3.1.x if mod in conf_data and mod != 'autoscaling': continue conf_data[mod] = {} conf_data[mod]["endpoint"] = "%s.tencentcloudapi.com" % mod # we have to do this because as is a keyword in python # as has been changed to autoscaling only in python sdk & cli if mod == 'autoscaling': conf_data[mod]["endpoint"] = "as.tencentcloudapi.com" versions = self._cli_data.get_service_all_version_actions( mod).keys() version = sorted(versions)[-1] conf_data[mod]["version"] = version for k in extra.keys(): try: ks = k.split(".") conf_data[ks[0]][ks[1]] = extra[k] except Exception as err: raise ConfigurationError( "Unexpected format: %s\n " "Received input format: %s\n " "Valid input format eg. set cvm.version 2017-03-12" % (err, k)) Utils.dump_json_msg(config_path, conf_data) def _checkout_config(self, profile_name): is_conexit, config_path = self._profile_existed(profile_name + ".configure") is_creexit, cred_path = self._profile_existed(profile_name + ".credential") if not is_conexit and not is_creexit: raise ConfigurationError( "not exist config file: %s or %s " % (profile_name + ".configure", profile_name + ".credential")) conf = Utils.load_json_msg(config_path) cred = Utils.load_json_msg(cred_path) if not (isinstance(conf, dict) and isinstance(cred, dict)): raise ConfigurationError( "not exist config file: %s or %s " % (profile_name + ".configure", profile_name + ".credential")) def _profile_existed(self, profile_name): return Utils.file_existed(self.cli_path, profile_name) def create_help_command(self): return ConfigureHelp(self.NAME, self)
def __init__(self, doc): self.doc = doc self._cli_data = Loader()
#! /usr/bin/env python import os import re import tccli.options_define as OptionsDefine from tccli.utils import Utils from tccli.loaders import Loader loader = Loader() services = sorted(loader.get_available_services().keys()) services.append("configure") if os.environ.get('LC_CTYPE', '') == 'UTF-8': os.environ['LC_CTYPE'] = 'en_US.UTF-8' def pre_print(result, cur): if cur: mathch_list = [x for x in result if x.startswith(cur)] if not mathch_list: mathch_list = [x for x in result if re.match(cur, x, re.I)] print(' \n'.join(mathch_list)) return print(' \n'.join(result)) def comp_one_arg(): pre_print(services, None) def comp_two_arg(arg): if arg not in services: pre_print(services, arg)
def __init__(self): self._cli_data = Loader()
def __init__(self): self.doc = Document() self._cli_data = Loader()