Esempio n. 1
0
    def __init__(self, completer, model_completer, docs,
                 input=None, output=None):
        self.completer = completer
        self.model_completer = model_completer
        self.history = InMemoryHistory()
        self.file_history = FileHistory(build_config_file_path('history'))
        self._cli = None
        self._docs = docs
        self.current_docs = u''
        self.refresh_cli = False
        self.key_manager = None
        self._dot_cmd = DotCommandHandler()
        self._env = os.environ.copy()
        self._profile = None
        self._input = input
        self._output = output

        # These attrs come from the config file.
        self.config_obj = None
        self.config_section = None
        self.enable_vi_bindings = None
        self.show_completion_columns = None
        self.show_help = None
        self.theme = None

        self.load_config()
Esempio n. 2
0
    def __init__(self,
                 completer,
                 model_completer,
                 docs,
                 input=None,
                 output=None):
        self.completer = completer
        self.model_completer = model_completer
        self.history = InMemoryHistory()
        self.file_history = FileHistory(build_config_file_path('history'))
        self._cli = None
        self._docs = docs
        self.current_docs = u''
        self.refresh_cli = False
        self.key_manager = None
        self._dot_cmd = DotCommandHandler()
        self._env = os.environ.copy()
        self._profile = None
        self._input = input
        self._output = output
        self.prompt_tokens = u'aws > '

        # These attrs come from the config file.
        self.config_obj = None
        self.config_section = None
        self.enable_vi_bindings = None
        self.show_completion_columns = None
        self.show_help = None
        self.theme = None

        self.load_config()
Esempio n. 3
0
 def __init__(self, completer, model_completer, docs):
     self.completer = completer
     self.model_completer = model_completer
     self.history = InMemoryHistory()
     self.file_history = FileHistory(build_config_file_path('history'))
     self._cli = None
     self._docs = docs
     self.current_docs = u''
     self.refresh_cli = False
     self._dot_cmd = DotCommandHandler()
     self.load_config()
Esempio n. 4
0
 def __init__(self, completer, model_completer, docs):
     self.completer = completer
     self.model_completer = model_completer
     self.history = InMemoryHistory()
     self.file_history = FileHistory(build_config_file_path('history'))
     self._cli = None
     self._docs = docs
     self.current_docs = u''
     self.refresh_cli = False
     self._dot_cmd = DotCommandHandler()
     self.load_config()
Esempio n. 5
0
 def test_config_off(self):
     try:
         os.remove(build_config_file_path('test-awsshellrc'))
     except OSError:
         pass
     self.aws_shell = AWSShell(None, mock.Mock(), mock.Mock())
     self.aws_shell.model_completer.match_fuzzy = False
     self.aws_shell.enable_vi_bindings = False
     self.aws_shell.show_completion_columns = False
     self.aws_shell.show_help = False
     self.aws_shell.theme = 'none'
     self.aws_shell.save_config()
     self.aws_shell.load_config()
     assert self.aws_shell.model_completer.match_fuzzy == False
     assert self.aws_shell.enable_vi_bindings == False
     assert self.aws_shell.show_completion_columns == False
     assert self.aws_shell.show_help == False
     assert self.aws_shell.theme == 'none'
Esempio n. 6
0
 def test_config_off(self):
     try:
         os.remove(build_config_file_path('test-awsshellrc'))
     except OSError:
         pass
     self.aws_shell = AWSShell(None, mock.Mock(), mock.Mock())
     self.aws_shell.model_completer.match_fuzzy = False
     self.aws_shell.enable_vi_bindings = False
     self.aws_shell.show_completion_columns = False
     self.aws_shell.show_help = False
     self.aws_shell.theme = 'none'
     self.aws_shell.save_config()
     self.aws_shell.load_config()
     assert self.aws_shell.model_completer.match_fuzzy == False
     assert self.aws_shell.enable_vi_bindings == False
     assert self.aws_shell.show_completion_columns == False
     assert self.aws_shell.show_help == False
     assert self.aws_shell.theme == 'none'
Esempio n. 7
0
    def load(self, config_template, config_file=None):
        """Reads the config file if it exists, else reads the default config.

        Creates the user config file if it doesn't exist using the template.

        :type config_template: str
        :param config_template: The config template file name.

        :type config_file: str
        :param config_file: (Optional) The config file name.
            If None, the config_file name will be set to the config_template.

        :rtype: :class:`configobj.ConfigObj`
        :return: The config information for reading and writing.
        """
        if config_file is None:
            config_file = config_template
        config_path = build_config_file_path(config_file)
        template_path = os.path.join(os.path.dirname(__file__), config_template)
        self._copy_template_to_config(template_path, config_path)
        return self._load_template_or_config(template_path, config_path)
Esempio n. 8
0
    def load(self, config_template, config_file=None):
        """Read the config file if it exists, else read the default config.

        Creates the user config file if it doesn't exist using the template.

        :type config_template: str
        :param config_template: The config template file name.

        :type config_file: str
        :param config_file: (Optional) The config file name.
            If None, the config_file name will be set to the config_template.

        :rtype: :class:`configobj.ConfigObj`
        :return: The config information for reading and writing.
        """
        if config_file is None:
            config_file = config_template
        config_path = build_config_file_path(config_file)
        template_path = os.path.join(os.path.dirname(__file__),
                                     config_template)
        self._copy_template_to_config(template_path, config_path)
        return self._load_template_or_config(template_path, config_path)
Esempio n. 9
0
class CompletionIndex(object):
    """Handles working with the local commmand completion index.

    :type commands: list
    :param commands: ec2, s3, elb...

    :type subcommands: list
    :param subcommands: start-instances, stop-instances, terminate-instances...

    :type global_opts: list
    :param global_opts: --profile, --region, --output...

    :type args_opts: set, to filter out duplicates
    :param args_opts: ec2 start-instances: --instance-ids, --dry-run...
    """

    # The completion index can read/write to a cache dir
    # so that it doesn't have to recompute the completion cache
    # every time the CLI starts up.
    DEFAULT_CACHE_DIR = build_config_file_path('cache')

    def __init__(self, cache_dir=DEFAULT_CACHE_DIR, fslayer=None):
        self._cache_dir = cache_dir
        if fslayer is None:
            fslayer = FSLayer()
        self._fslayer = fslayer
        self.commands = []
        self.subcommands = []
        self.global_opts = []
        self.args_opts = set()

    def load_index(self, version_string):
        """Load the completion index for a given CLI version.

        :type version_string: str
        :param version_string: The AWS CLI version, e.g "1.9.2".

        :raises: :class:`IndexLoadError <exceptions.IndexLoadError>`
        """
        filename = self._filename_for_version(version_string)
        try:
            contents = self._fslayer.file_contents(filename)
        except FileReadError as e:
            raise IndexLoadError(str(e))
        return contents

    def _filename_for_version(self, version_string):
        return os.path.join(
            self._cache_dir, 'completions-%s.json' % version_string)

    def load_completions(self):
        """Load completions from the completion index.

        Updates the following attributes:
            * commands
            * subcommands
            * global_opts
            * args_opts
        """
        try:
            index_str = self.load_index(utils.AWSCLI_VERSION)
        except IndexLoadError:
            return
        index_str = self.load_index(utils.AWSCLI_VERSION)
        index_data = json.loads(index_str)
        index_root = index_data['aws']
        # ec2, s3, elb...
        self.commands = index_root['commands']
        # --profile, --region, --output...
        self.global_opts = index_root['arguments']
        for command in self.commands:
            # ec2: start-instances, stop-instances, terminate-instances...
            subcommands_current = index_root['children'] \
                .get(command)['commands']
            self.subcommands.extend(subcommands_current)
            for subcommand_current in subcommands_current:
                # start-instances: --instance-ids, --dry-run...
                args_opts_current = index_root['children'] \
                    .get(command)['children'] \
                    .get(subcommand_current)['arguments']
                self.args_opts.update(args_opts_current)
Esempio n. 10
0
 def index_filename(version_string, type_name='completions'):
     return build_config_file_path('%s-%s.json' %
                                   (version_string, type_name))
Esempio n. 11
0
 def index_filename(version_string, type_name='completions'):
     return build_config_file_path(
         '%s-%s.json' % (version_string, type_name))
Esempio n. 12
0
 def index_filename(version_string, type_name="completions"):
     return build_config_file_path("%s-%s.json" % (version_string, type_name))