# Path: awsshell/utils.py
# class FSLayer(object):
#     """Abstraction over common OS commands.
# 
#     Provides a simpler interface given the operations needed
#     by the AWS Shell.
# 
#     """
#     def file_contents(self, filename, binary=False):
#         """Return the file for a given filename.
# 
#         If you want binary content use ``mode='rb'``.
# 
#         """
#         if binary:
#             mode = 'rb'
#         else:
#             mode = 'r'
#         try:
#             with open(filename, mode) as f:
#                 return f.read()
#         except (OSError, IOError) as e:
#             raise FileReadError(str(e))
# 
#     def file_exists(self, filename):
#         """Check if a file exists.
# 
#         This method returns true if:
# 
#             * The file exists.
#             * The filename is a file (not a directory).
# 
#         """
#         return os.path.isfile(filename)
# 
# class FileReadError(Exception):
#     pass
# 
# def build_config_file_path(file_name):
#     return os.path.join(os.path.expanduser('~'), '.aws', 'shell', file_name)
# 
# Path: awsshell/utils.py
# AWSCLI_VERSION = awscli.__version__
# class FileReadError(Exception):
# class DataOnly(HTMLParser):
# class FSLayer(object):
# class InMemoryFSLayer(object):
# def remove_html(html):
# def build_config_file_path(file_name):
# def temporary_file(mode):
#     def __init__(self):
#     def handle_data(self, data):
#     def get_data(self):
#     def file_contents(self, filename, binary=False):
#     def file_exists(self, filename):
#     def __init__(self, file_mapping):
#     def file_contents(self, filename, binary=False):
#     def file_exists(self, filename):


import os
import json
from awsshell.utils import FSLayer, FileReadError, build_config_file_path
from awsshell import utils


class IndexLoadError(Exception):
    """Raised when an index could not be loaded."""


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:

# Path: awsshell/utils.py
# class FSLayer(object):
#     """Abstraction over common OS commands.
# 
#     Provides a simpler interface given the operations needed
#     by the AWS Shell.
# 
#     """
#     def file_contents(self, filename, binary=False):
#         """Return the file for a given filename.
# 
#         If you want binary content use ``mode='rb'``.
# 
#         """
#         if binary:
#             mode = 'rb'
#         else:
#             mode = 'r'
#         try:
#             with open(filename, mode) as f:
#                 return f.read()
#         except (OSError, IOError) as e:
#             raise FileReadError(str(e))
# 
#     def file_exists(self, filename):
#         """Check if a file exists.
# 
#         This method returns true if:
# 
#             * The file exists.
#             * The filename is a file (not a directory).
# 
#         """
#         return os.path.isfile(filename)
# 
# class FileReadError(Exception):
#     pass
# 
# def build_config_file_path(file_name):
#     return os.path.join(os.path.expanduser('~'), '.aws', 'shell', file_name)
# 
# Path: awsshell/utils.py
# AWSCLI_VERSION = awscli.__version__
# class FileReadError(Exception):
# class DataOnly(HTMLParser):
# class FSLayer(object):
# class InMemoryFSLayer(object):
# def remove_html(html):
# def build_config_file_path(file_name):
# def temporary_file(mode):
#     def __init__(self):
#     def handle_data(self, data):
#     def get_data(self):
#     def file_contents(self, filename, binary=False):
#     def file_exists(self, filename):
#     def __init__(self, file_mapping):
#     def file_contents(self, filename, binary=False):
#     def file_exists(self, filename):


# Path: awsshell/index/completion.py
import os
import json
from awsshell.utils import FSLayer, FileReadError, build_config_file_path
from awsshell import utils



class IndexLoadError(Exception):
    """Raised when an index could not be loaded."""


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()