saws package

Submodules

saws.commands module

class saws.commands.AwsCommands

Bases: object

Encapsulates AWS commands.

Attributes:
  • AWS_COMMAND: A string representing the ‘aws’ command.

  • AWS_CONFIGURE: A string representing the ‘configure’ command.

  • AWS_HELP: A string representing the ‘help’ command.

  • AWS_DOCS: A string representing the ‘docs’ command.

  • COMMANDS_HEADER: A string denoting the start of

    commands in data/SOURCES.txt.

  • SUB_COMMANDS_HEADER: A string denoting the start of

    subcommands in data/SOURCES.txt.

  • GLOBAL_OPTIONS_HEADER: A string denoting the start of

    global options in data/SOURCES.txt.

  • RESOURCE_OPTIONS_HEADER: A string denoting the start of

    resource options in data/SOURCES.txt.

  • EC2_STATES_HEADER: A string denoting the start of

    ec2 states in data/SOURCES.txt.

  • SOURCES_DIR: A string representing the directory containing

    data/SOURCES.txt.

  • SOURCES_PATH: A string representing the full file path of

    data/SOURCES.txt.

AWS_COMMAND = u'aws'
AWS_CONFIGURE = u'configure'
AWS_DOCS = u'docs'
AWS_HELP = u'help'
COMMANDS_HEADER = u'[commands]: '
class CommandType

Bases: enum.Enum

Enum specifying the command type.

Attributes:
  • AWS_COMMAND: A string representing the ‘aws’ command.
  • AWS_CONFIGURE: A string representing the ‘configure’ command.
  • AWS_HELP: A string representing the ‘help’ command.
  • AWS_DOCS: A string representing the ‘docs’ command.
  • COMMANDS: An int representing commands.
  • SUB_COMMANDS: An int representing subcommands.
  • GLOBAL_OPTIONS: An int representing global options.
  • RESOURCE_OPTIONS: An int representing resource options.
  • EC2_STATES: An int representing ec2 running states.
AwsCommands.EC2_STATES_HEADER = u'[ec2_states]: '
AwsCommands.GLOBAL_OPTIONS_HEADER = u'[global_options]: '
AwsCommands.RESOURCE_OPTIONS_HEADER = u'[resource_options]: '
AwsCommands.SOURCES_DIR = '/Users/donnemartin/Dev/github/sources/wip/saws'
AwsCommands.SOURCES_PATH = u'/Users/donnemartin/Dev/github/sources/wip/saws/data/SOURCES.txt'
AwsCommands.SUB_COMMANDS_HEADER = u'[sub_commands]: '
AwsCommands.generate_all_commands()

Generates all commands from the data/SOURCES.txt file.

Args:
  • None.
Returns:
A tuple, where each tuple element is a list of:
  • commands
  • sub_commands
  • global_options
  • resource_options
  • ec2_states

saws.completer module

class saws.completer.AwsCompleter(aws_completer, config_obj, log_exception, ec2_states=[], fuzzy_match=False, shortcut_match=False)

Bases: prompt_toolkit.completion.Completer

Completer for AWS commands, subcommands, options, and parameters.

Attributes:
  • aws_completer: An instance of the official awscli Completer.

  • aws_completions: A set of completions to show the user.

  • config_obj: An instance of ConfigObj, reads from ~/.sawsrc.

  • log_exception: A callable log_exception from SawsLogger.

  • ec2_states: A list of the possible instance states.

  • text_utils: An instance of TextUtils.

  • fuzzy_match: A boolean that determines whether to use fuzzy matching.

  • shortcut_match: A boolean that determines whether to match shortcuts.

  • BASE_COMMAND: A string representing the ‘aws’ command.

  • DOCS_COMMAND: A string representing the ‘docs’ command.

  • resources: An instance of AwsResources.

  • shortcuts: An OrderedDict containing shortcuts commands as keys

    and their corresponding full commands as values.

__init__(aws_completer, config_obj, log_exception, ec2_states=[], fuzzy_match=False, shortcut_match=False)

Initializes AwsCompleter.

Args:
  • aws_completer: The official aws cli completer module.

  • config_obj: An instance of ConfigObj, reads from ~/.sawsrc.

  • log_exception: A callable log_exception from SawsLogger.

  • ec2_states: A list of the possible instance states.

  • fuzzy_match: A boolean that determines whether to use

    fuzzy matching.

  • shortcut_match: A boolean that determines whether to

    match shortcuts.

Returns:
None.
create_resource_map()

Creates a mapping of resource keywords and resources to complete.

Example:
Key: ‘–instance-ids’. Value: List of instance ids.
Args:
  • None.
Returns:
None.
get_all_resource_completions(words, word_before_cursor)

Description.

Args:
  • words: A list of strings for each word in the command text.

  • word_before_cursor: A string representing the word before

    the cursor.

Returns:
A generator of prompt_toolkit’s Completion objects, containing matched completions.
get_aws_cli_completions(document)

Get completions from the official AWS CLI for the current scope.

Args:
  • document: An instance of prompt_toolkit’s Document.
Returns:
A list of string completions.
get_completions(document, _)

Get completions for the current scope.

Args:
  • document: An instance of prompt_toolkit’s Document.
  • _: An instance of prompt_toolkit’s CompleteEvent (not used).
Returns:
A generator of prompt_toolkit’s Completion objects, containing matched completions.
get_resource_completions(words, word_before_cursor, option_text, resource)

Get completions for enabled AWS resources.

Args:
  • words: A list of words that represent the input command text.

  • word_before_cursor: A string representing the word before the

    cursor.

  • option_text: A string to match that represents the resource’s

    option text, such as ‘–ec2-state’. For example, if option_text is ‘–ec2-state’ and it is the word before the cursor, then display associated resource completions found in the resource parameter such as pending, running, etc.

  • resource: A list that represents the resource completions to

    display if option_text is matched. For example, instance ids, instance tags, etc.

Returns:
A generator of prompt_toolkit’s Completion objects, containing matched completions.
refresh_resources(force_refresh=False)

Convenience function to refresh resources for completion.

Args:
  • force_refresh: A boolean determines whether to force a cache

    refresh. This value is set to True when the user presses F5.

Returns:
None.
replace_shortcut(text)

Replaces matched shortcut commands with their full command.

Currently, only one shortcut is replaced before shortcut replacement terminates, although this function could potentially be extended to replace mutliple shortcuts.

Args:
  • text: A string representing the input command text to replace.
Returns:
A string representing input command text with a shortcut
replaced, if one has been found.
replace_substitution(text)

Replaces a %s with the word immediately following it.

Currently, only one substitution is done before replacement terminates, although this function could potentially be extended to do multiple subsitutions.

Args:
  • text: A string representing the input command text to replace.
Returns:
A string representing input command text with a substitution, if one has been found.

saws.config module

class saws.config.Config

Bases: object

Reads and writes the config file sawsrc.

Attributes:
  • None
get_shortcuts(config)

Gets the shortcuts from the specified config.

Args:
  • config: An instance of ConfigObj.
Returns:
An OrderedDict containing the shortcut commands as the keys and their corresponding full commands as the values.
read_configuration()

Reads the config file if it exists, else reads the default config.

Args:
  • None.
Returns:
An instance of a ConfigObj.
write_default_config(source, destination, overwrite=False)

Writes the default config from a template.

Args:
  • source: A string that specifies the path to the template.
  • destination: A string that specifies the path to write.
  • overwite: A boolean that specifies whether to overwite the file.
Returns:
None.

saws.keys module

class saws.keys.KeyManager(set_color, get_color, set_fuzzy_match, get_fuzzy_match, set_shortcut_match, get_shortcut_match, refresh_resources, handle_docs)

Bases: object

Creates a Key Manager.

Attributes:
  • manager: An instance of a prompt_toolkit’s KeyBindingManager.
__init__(set_color, get_color, set_fuzzy_match, get_fuzzy_match, set_shortcut_match, get_shortcut_match, refresh_resources, handle_docs)

Initializes KeyManager.

Args:
  • set_color: A function that sets the color output config.
  • get_color: A function that gets the color output config.
  • set_fuzzy_match: A function that sets the fuzzy match config.
  • get_fuzzy_match: A function that gets the fuzzy match config.
  • set_shortcut_match: A function that sets the shortcut match config.
  • get_shortcut_match: A function that gets the shortcut match config.
Returns:
None.
create_key_manager(set_color, get_color, set_fuzzy_match, get_fuzzy_match, set_shortcut_match, get_shortcut_match, refresh_resources, handle_docs)

Creates and initializes the keybinding manager.

Args:
  • set_color: A function that sets the color output config.
  • get_color: A function that gets the color output config.
  • set_fuzzy_match: A function that sets the fuzzy match config.
  • get_fuzzy_match: A function that gets the fuzzy match config.
  • set_shortcut_match: A function that sets the shortcut match config.
  • get_shortcut_match: A function that gets the shortcut match config.
Returns:
A KeyBindingManager.

saws.lexer module

class saws.lexer.CommandLexer(**options)

Bases: pygments.lexer.RegexLexer

Provides highlighting for commands.

Custom Pygments Lexers seem to require a specific class structure, samples:
http://pygments.org/docs/lexerdevelopment/

TODO: Investigate how to clean this up while still keeping Pygments happy.

Attributes:
  • config_obj: An instance of ConfigObj.

  • shortcuts: An OrderedDict containing the shortcut commands as the

    keys and their corresponding full commands as the values.

  • shortcut_tokens: A list containing words for each shortcut key:

    key: ‘aws ec2 ls’ -> shortcut_tokens: [‘aws’, ‘ec2’, ‘ls’].

  • aws_commands: An instance of AwsCommands.

  • commands: A tuple, where each tuple element is a list of:
    • commands
    • sub_commands
    • global_options
    • resource_options
    • ec2_states
  • tokens: A dictionary of pygments tokens.

aws_commands = <saws.commands.AwsCommands object>
commands = ([u'autoscaling', u'cloudformation', u'cloudfront', u'cloudhsm', u'cloudsearch', u'cloudsearchdomain', u'cloudtrail', u'cloudwatch', u'codecommit', u'codepipeline', u'cognito-identity', u'cognito-sync', u'configservice', u'configure', u'datapipeline', u'deploy', u'devicefarm', u'directconnect', u'ds', u'dynamodb', u'dynamodbstreams', u'ec2', u'ecs', u'efs', u'elasticache', u'elasticbeanstalk', u'elastictranscoder', u'elb', u'emr', u'glacier', u'iam', u'importexport', u'kinesis', u'kms', u'lambda', u'logs', u'machinelearning', u'opsworks', u'rds', u'redshift', u'route53', u'route53domains', u's3', u's3api', u'sdb', u'ses', u'sns', u'sqs', u'ssm', u'storagegateway', u'sts', u'support', u'swf', u'workspaces'], [u'abort-environment-update', u'abort-multipart-upload', u'abort-vault-lock', u'accept-vpc-peering-connection', u'acknowledge-job', u'acknowledge-third-party-job', u'activate-gateway', u'activate-pipeline', u'add-attachments-to-set', u'add-cache', u'add-client-id-to-open-id-connect-provider', u'add-communication-to-case', u'add-instance-groups', u'add-option-to-option-group', u'add-permission', u'add-role-to-instance-profile', u'add-source-identifier-to-subscription', u'add-steps', u'add-tags', u'add-tags-to-on-premises-instances', u'add-tags-to-resource', u'add-tags-to-stream', u'add-tags-to-vault', u'add-upload-buffer', u'add-user-to-group', u'add-working-storage', u'allocate-address', u'allocate-connection-on-interconnect', u'allocate-private-virtual-interface', u'allocate-public-virtual-interface', u'apply-pending-maintenance-action', u'apply-security-groups-to-load-balancer', u'assign-instance', u'assign-private-ip-addresses', u'assign-volume', u'associate-address', u'associate-dhcp-options', u'associate-elastic-ip', u'associate-route-table', u'associate-vpc-with-hosted-zone', u'assume-role', u'assume-role-with-saml', u'assume-role-with-web-identity', u'attach-classic-link-vpc', u'attach-elastic-load-balancer', u'attach-group-policy', u'attach-instances', u'attach-internet-gateway', u'attach-load-balancer-to-subnets', u'attach-load-balancers', u'attach-network-interface', u'attach-role-policy', u'attach-user-policy', u'attach-volume', u'attach-vpn-gateway', u'authorize-cache-security-group-ingress', u'authorize-cluster-security-group-ingress', u'authorize-db-security-group-ingress', u'authorize-security-group-egress', u'authorize-security-group-ingress', u'authorize-snapshot-access', u'batch-delete-attributes', u'batch-get-applications', u'batch-get-deployments', u'batch-get-item', u'batch-get-on-premises-instances', u'batch-get-repositories', u'batch-put-attributes', u'batch-write-item', u'build-suggesters', u'bulk-publish', u'bundle-instance', u'cancel-archival', u'cancel-bundle-task', u'cancel-conversion-task', u'cancel-export-task', u'cancel-import-task', u'cancel-job', u'cancel-reserved-instances-listing', u'cancel-retrieval', u'cancel-spot-fleet-requests', u'cancel-spot-instance-requests', u'cancel-update-stack', u'change-message-visibility', u'change-message-visibility-batch', u'change-password', u'change-resource-record-sets', u'change-tags-for-resource', u'check-dns-availability', u'check-domain-availability', u'clone-stack', u'complete-lifecycle-action', u'complete-multipart-upload', u'complete-vault-lock', u'configure-health-check', u'confirm-connection', u'confirm-private-virtual-interface', u'confirm-product-instance', u'confirm-public-virtual-interface', u'confirm-subscription', u'connect-directory', u'copy-cluster-snapshot', u'copy-db-cluster-snapshot', u'copy-db-parameter-group', u'copy-db-snapshot', u'copy-image', u'copy-object', u'copy-option-group', u'copy-snapshot', u'count-closed-workflow-executions', u'count-open-workflow-executions', u'count-pending-activity-tasks', u'count-pending-decision-tasks', u'cp', u'create-access-key', u'create-account-alias', u'create-alias', u'create-app', u'create-app-cookie-stickiness-policy', u'create-application', u'create-application-version', u'create-association', u'create-association-batch', u'create-auto-scaling-group', u'create-batch-prediction', u'create-branch', u'create-bucket', u'create-cache-cluster', u'create-cache-parameter-group', u'create-cache-security-group', u'create-cache-subnet-group', u'create-cached-iscsi-volume', u'create-case', u'create-cloud-front-origin-access-identity', u'create-cluster', u'create-cluster-parameter-group', u'create-cluster-security-group', u'create-cluster-snapshot', u'create-cluster-subnet-group', u'create-computer', u'create-configuration-template', u'create-connection', u'create-custom-action-type', u'create-customer-gateway', u'create-data-source-from-rds', u'create-data-source-from-redshift', u'create-data-source-from-s3', u'create-db-cluster', u'create-db-cluster-parameter-group', u'create-db-cluster-snapshot', u'create-db-instance', u'create-db-instance-read-replica', u'create-db-parameter-group', u'create-db-security-group', u'create-db-snapshot', u'create-db-subnet-group', u'create-default-roles', u'create-deployment', u'create-deployment-config', u'create-deployment-group', u'create-device-pool', u'create-dhcp-options', u'create-directory', u'create-distribution', u'create-document', u'create-domain', u'create-environment', u'create-evaluation', u'create-event-source-mapping', u'create-event-subscription', u'create-file-system', u'create-flow-logs', u'create-function', u'create-grant', u'create-group', u'create-hapg', u'create-hbase-backup', u'create-health-check', u'create-hosted-zone', u'create-hsm', u'create-hsm-client-certificate', u'create-hsm-configuration', u'create-identity-pool', u'create-image', u'create-instance', u'create-instance-export-task', u'create-instance-profile', u'create-interconnect', u'create-internet-gateway', u'create-invalidation', u'create-job', u'create-key', u'create-key-pair', u'create-launch-configuration', u'create-layer', u'create-lb-cookie-stickiness-policy', u'create-load-balancer', u'create-load-balancer-listeners', u'create-load-balancer-policy', u'create-log-group', u'create-log-stream', u'create-login-profile', u'create-luna-client', u'create-ml-model', u'create-mount-target', u'create-multipart-upload', u'create-network-acl', u'create-network-acl-entry', u'create-network-interface', u'create-open-id-connect-provider', u'create-option-group', u'create-or-update-tags', u'create-pipeline', u'create-placement-group', u'create-platform-application', u'create-platform-endpoint', u'create-policy', u'create-policy-version', u'create-preset', u'create-private-virtual-interface', u'create-project', u'create-public-virtual-interface', u'create-queue', u'create-realtime-endpoint', u'create-replication-group', u'create-repository', u'create-reserved-instances-listing', u'create-reusable-delegation-set', u'create-role', u'create-route', u'create-route-table', u'create-saml-provider', u'create-security-group', u'create-service', u'create-snapshot', u'create-snapshot-copy-grant', u'create-snapshot-from-volume-recovery-point', u'create-spot-datafeed-subscription', u'create-stack', u'create-storage-location', u'create-stored-iscsi-volume', u'create-stream', u'create-streaming-distribution', u'create-subnet', u'create-subscription', u'create-table', u'create-tags', u'create-tapes', u'create-topic', u'create-trail', u'create-upload', u'create-user', u'create-user-profile', u'create-vault', u'create-virtual-mfa-device', u'create-volume', u'create-vpc', u'create-vpc-endpoint', u'create-vpc-peering-connection', u'create-vpn-connection', u'create-vpn-connection-route', u'create-vpn-gateway', u'create-workspaces', u'credential-helper', u'deactivate-mfa-device', u'deactivate-pipeline', u'decode-authorization-message', u'decrypt', u'define-analysis-scheme', u'define-expression', u'define-index-field', u'define-suggester', u'delete-access-key', u'delete-account-alias', u'delete-account-password-policy', u'delete-alarms', u'delete-alias', u'delete-analysis-scheme', u'delete-app', u'delete-application', u'delete-application-version', u'delete-archive', u'delete-association', u'delete-attributes', u'delete-auto-scaling-group', u'delete-bandwidth-rate-limit', u'delete-batch-prediction', u'delete-bucket', u'delete-bucket-cors', u'delete-bucket-lifecycle', u'delete-bucket-policy', u'delete-bucket-replication', u'delete-bucket-tagging', u'delete-bucket-website', u'delete-cache-cluster', u'delete-cache-parameter-group', u'delete-cache-security-group', u'delete-cache-subnet-group', u'delete-chap-credentials', u'delete-cloud-front-origin-access-identity', u'delete-cluster', u'delete-cluster-parameter-group', u'delete-cluster-security-group', u'delete-cluster-snapshot', u'delete-cluster-subnet-group', u'delete-configuration-template', u'delete-connection', u'delete-custom-action-type', u'delete-customer-gateway', u'delete-data-source', u'delete-dataset', u'delete-db-cluster', u'delete-db-cluster-parameter-group', u'delete-db-cluster-snapshot', u'delete-db-instance', u'delete-db-parameter-group', u'delete-db-security-group', u'delete-db-snapshot', u'delete-db-subnet-group', u'delete-delivery-channel', u'delete-deployment-config', u'delete-deployment-group', u'delete-destination', u'delete-dhcp-options', u'delete-directory', u'delete-distribution', u'delete-document', u'delete-domain', u'delete-endpoint', u'delete-environment-configuration', u'delete-evaluation', u'delete-event-source-mapping', u'delete-event-subscription', u'delete-expression', u'delete-file-system', u'delete-flow-logs', u'delete-function', u'delete-gateway', u'delete-group', u'delete-group-policy', u'delete-hapg', u'delete-health-check', u'delete-hosted-zone', u'delete-hsm', u'delete-hsm-client-certificate', u'delete-hsm-configuration', u'delete-identities', u'delete-identity', u'delete-identity-policy', u'delete-identity-pool', u'delete-index-field', u'delete-instance', u'delete-instance-profile', u'delete-interconnect', u'delete-internet-gateway', u'delete-item', u'delete-key-pair', u'delete-launch-configuration', u'delete-layer', u'delete-lifecycle-hook', u'delete-load-balancer', u'delete-load-balancer-listeners', u'delete-load-balancer-policy', u'delete-log-group', u'delete-log-stream', u'delete-login-profile', u'delete-luna-client', u'delete-message', u'delete-message-batch', u'delete-metric-filter', u'delete-ml-model', u'delete-mount-target', u'delete-network-acl', u'delete-network-acl-entry', u'delete-network-interface', u'delete-notification-configuration', u'delete-object', u'delete-objects', u'delete-open-id-connect-provider', u'delete-option-group', u'delete-pipeline', u'delete-placement-group', u'delete-platform-application', u'delete-policy', u'delete-policy-version', u'delete-preset', u'delete-queue', u'delete-realtime-endpoint', u'delete-replication-group', u'delete-repository', u'delete-retention-policy', u'delete-reusable-delegation-set', u'delete-role', u'delete-role-policy', u'delete-route', u'delete-route-table', u'delete-saml-provider', u'delete-scheduled-action', u'delete-security-group', u'delete-server-certificate', u'delete-service', u'delete-signing-certificate', u'delete-snapshot', u'delete-snapshot-copy-grant', u'delete-snapshot-schedule', u'delete-spot-datafeed-subscription', u'delete-ssh-public-key', u'delete-stack', u'delete-stream', u'delete-streaming-distribution', u'delete-subnet', u'delete-subscription-filter', u'delete-suggester', u'delete-table', u'delete-tags', u'delete-tags-for-domain', u'delete-tape', u'delete-tape-archive', u'delete-topic', u'delete-trail', u'delete-user', u'delete-user-policy', u'delete-user-profile', u'delete-vault', u'delete-vault-access-policy', u'delete-vault-notifications', u'delete-virtual-interface', u'delete-virtual-mfa-device', u'delete-volume', u'delete-vpc', u'delete-vpc-endpoints', u'delete-vpc-peering-connection', u'delete-vpn-connection', u'delete-vpn-connection-route', u'delete-vpn-gateway', u'deliver-config-snapshot', u'deprecate-activity-type', u'deprecate-domain', u'deprecate-workflow-type', u'deregister', u'deregister-container-instance', u'deregister-ecs-cluster', u'deregister-elastic-ip', u'deregister-image', u'deregister-instance', u'deregister-instances-from-load-balancer', u'deregister-on-premises-instance', u'deregister-rds-db-instance', u'deregister-task-definition', u'deregister-volume', u'describe-account-attributes', u'describe-account-limits', u'describe-activity-type', u'describe-addresses', u'describe-adjustment-types', u'describe-agent-versions', u'describe-alarm-history', u'describe-alarms', u'describe-alarms-for-metric', u'describe-analysis-schemes', u'describe-application-versions', u'describe-applications', u'describe-apps', u'describe-association', u'describe-attachment', u'describe-auto-scaling-groups', u'describe-auto-scaling-instances', u'describe-auto-scaling-notification-types', u'describe-availability-options', u'describe-availability-zones', u'describe-bandwidth-rate-limit', u'describe-batch-predictions', u'describe-bundle-tasks', u'describe-cache', u'describe-cache-clusters', u'describe-cache-engine-versions', u'describe-cache-parameter-groups', u'describe-cache-parameters', u'describe-cache-security-groups', u'describe-cache-subnet-groups', u'describe-cached-iscsi-volumes', u'describe-cases', u'describe-certificates', u'describe-chap-credentials', u'describe-classic-link-instances', u'describe-cluster', u'describe-cluster-parameter-groups', u'describe-cluster-parameters', u'describe-cluster-security-groups', u'describe-cluster-snapshots', u'describe-cluster-subnet-groups', u'describe-cluster-versions', u'describe-clusters', u'describe-commands', u'describe-communications', u'describe-configuration-options', u'describe-configuration-recorder-status', u'describe-configuration-recorders', u'describe-configuration-settings', u'describe-connections', u'describe-connections-on-interconnect', u'describe-container-instances', u'describe-conversion-tasks', u'describe-customer-gateways', u'describe-data-sources', u'describe-dataset', u'describe-db-cluster-parameter-groups', u'describe-db-cluster-parameters', u'describe-db-cluster-snapshots', u'describe-db-clusters', u'describe-db-engine-versions', u'describe-db-instances', u'describe-db-log-files', u'describe-db-parameter-groups', u'describe-db-parameters', u'describe-db-security-groups', u'describe-db-snapshots', u'describe-db-subnet-groups', u'describe-default-cluster-parameters', u'describe-delivery-channel-status', u'describe-delivery-channels', u'describe-deployments', u'describe-destinations', u'describe-dhcp-options', u'describe-directories', u'describe-document', u'describe-domain', u'describe-domains', u'describe-ecs-clusters', u'describe-elastic-ips', u'describe-elastic-load-balancers', u'describe-engine-default-cluster-parameters', u'describe-engine-default-parameters', u'describe-environment-health', u'describe-environment-resources', u'describe-environments', u'describe-evaluations', u'describe-event-categories', u'describe-event-subscriptions', u'describe-events', u'describe-export-tasks', u'describe-expressions', u'describe-file-systems', u'describe-flow-logs', u'describe-gateway-information', u'describe-hapg', u'describe-hsm', u'describe-hsm-client-certificates', u'describe-hsm-configurations', u'describe-identity', u'describe-identity-pool', u'describe-identity-pool-usage', u'describe-identity-usage', u'describe-image-attribute', u'describe-images', u'describe-import-image-tasks', u'describe-import-snapshot-tasks', u'describe-index-fields', u'describe-instance-attribute', u'describe-instance-health', u'describe-instance-status', u'describe-instances', u'describe-instances-health', u'describe-interconnects', u'describe-internet-gateways', u'describe-job', u'describe-key', u'describe-key-pairs', u'describe-launch-configurations', u'describe-layers', u'describe-lifecycle-hook-types', u'describe-lifecycle-hooks', u'describe-load-balancer-attributes', u'describe-load-balancer-policies', u'describe-load-balancer-policy-types', u'describe-load-balancers', u'describe-load-based-auto-scaling', u'describe-locations', u'describe-log-groups', u'describe-log-streams', u'describe-logging-status', u'describe-luna-client', u'describe-maintenance-start-time', u'describe-metric-collection-types', u'describe-metric-filters', u'describe-ml-models', u'describe-mount-target-security-groups', u'describe-mount-targets', u'describe-moving-addresses', u'describe-my-user-profile', u'describe-network-acls', u'describe-network-interface-attribute', u'describe-network-interfaces', u'describe-notification-configurations', u'describe-objects', u'describe-option-group-options', u'describe-option-groups', u'describe-orderable-cluster-options', u'describe-orderable-db-instance-options', u'describe-pending-maintenance-actions', u'describe-permissions', u'describe-pipelines', u'describe-placement-groups', u'describe-policies', u'describe-prefix-lists', u'describe-raid-arrays', u'describe-rds-db-instances', u'describe-regions', u'describe-replication-groups', u'describe-reserved-cache-nodes', u'describe-reserved-cache-nodes-offerings', u'describe-reserved-db-instances', u'describe-reserved-db-instances-offerings', u'describe-reserved-instances', u'describe-reserved-instances-listings', u'describe-reserved-instances-modifications', u'describe-reserved-instances-offerings', u'describe-reserved-node-offerings', u'describe-reserved-nodes', u'describe-resize', u'describe-route-tables', u'describe-scaling-activities', u'describe-scaling-parameters', u'describe-scaling-process-types', u'describe-scheduled-actions', u'describe-security-groups', u'describe-service-access-policies', u'describe-service-errors', u'describe-services', u'describe-severity-levels', u'describe-snapshot-attribute', u'describe-snapshot-copy-grants', u'describe-snapshot-schedule', u'describe-snapshots', u'describe-spot-datafeed-subscription', u'describe-spot-fleet-instances', u'describe-spot-fleet-request-history', u'describe-spot-fleet-requests', u'describe-spot-instance-requests', u'describe-spot-price-history', u'describe-stack-events', u'describe-stack-provisioning-parameters', u'describe-stack-resource', u'describe-stack-resources', u'describe-stack-summary', u'describe-stacks', u'describe-step', u'describe-stored-iscsi-volumes', u'describe-stream', u'describe-subnets', u'describe-subscription-filters', u'describe-suggesters', u'describe-table', u'describe-tags', u'describe-tape-archives', u'describe-tape-recovery-points', u'describe-tapes', u'describe-task-definition', u'describe-tasks', u'describe-termination-policy-types', u'describe-time-based-auto-scaling', u'describe-trails', u'describe-trusted-advisor-check-refresh-statuses', u'describe-trusted-advisor-check-result', u'describe-trusted-advisor-check-summaries', u'describe-trusted-advisor-checks', u'describe-upload-buffer', u'describe-user-profiles', u'describe-vault', u'describe-virtual-gateways', u'describe-virtual-interfaces', u'describe-volume-attribute', u'describe-volume-status', u'describe-volumes', u'describe-vpc-attribute', u'describe-vpc-classic-link', u'describe-vpc-endpoint-services', u'describe-vpc-endpoints', u'describe-vpc-peering-connections', u'describe-vpcs', u'describe-vpn-connections', u'describe-vpn-gateways', u'describe-vtl-devices', u'describe-workflow-execution', u'describe-workflow-type', u'describe-working-storage', u'describe-workspace-bundles', u'describe-workspace-directories', u'describe-workspaces', u'detach-classic-link-vpc', u'detach-elastic-load-balancer', u'detach-group-policy', u'detach-instances', u'detach-internet-gateway', u'detach-load-balancer-from-subnets', u'detach-load-balancers', u'detach-network-interface', u'detach-role-policy', u'detach-user-policy', u'detach-volume', u'detach-vpn-gateway', u'disable-alarm-actions', u'disable-availability-zones-for-load-balancer', u'disable-domain-auto-renew', u'disable-domain-transfer-lock', u'disable-gateway', u'disable-hbase-backups', u'disable-key', u'disable-key-rotation', u'disable-logging', u'disable-metrics-collection', u'disable-radius', u'disable-snapshot-copy', u'disable-sso', u'disable-stage-transition', u'disable-vgw-route-propagation', u'disable-vpc-classic-link', u'disassociate-address', u'disassociate-elastic-ip', u'disassociate-route-table', u'disassociate-vpc-from-hosted-zone', u'discover-poll-endpoint', u'domain-metadata', u'download-db-log-file-portion', u'enable-alarm-actions', u'enable-availability-zones-for-load-balancer', u'enable-domain-auto-renew', u'enable-domain-transfer-lock', u'enable-key', u'enable-key-rotation', u'enable-logging', u'enable-metrics-collection', u'enable-mfa-device', u'enable-radius', u'enable-snapshot-copy', u'enable-sso', u'enable-stage-transition', u'enable-vgw-route-propagation', u'enable-volume-io', u'enable-vpc-classic-link', u'encrypt', u'enter-standby', u'evaluate-expression', u'execute-policy', u'exit-standby', u'failover-db-cluster', u'filter-log-events', u'generate-credential-report', u'generate-data-key', u'generate-data-key-without-plaintext', u'generate-random', u'get', u'get-access-key-last-used', u'get-account-authorization-details', u'get-account-password-policy', u'get-account-settings', u'get-account-summary', u'get-application', u'get-application-revision', u'get-attributes', u'get-batch-prediction', u'get-branch', u'get-bucket-acl', u'get-bucket-cors', u'get-bucket-lifecycle', u'get-bucket-lifecycle-configuration', u'get-bucket-location', u'get-bucket-logging', u'get-bucket-notification', u'get-bucket-notification-configuration', u'get-bucket-policy', u'get-bucket-replication', u'get-bucket-request-payment', u'get-bucket-tagging', u'get-bucket-versioning', u'get-bucket-website', u'get-bulk-publish-details', u'get-change', u'get-checker-ip-ranges', u'get-cloud-front-origin-access-identity', u'get-cloud-front-origin-access-identity-config', u'get-cognito-events', u'get-config', u'get-console-output', u'get-context-keys-for-custom-policy', u'get-context-keys-for-principal-policy', u'get-credential-report', u'get-credentials-for-identity', u'get-data-retrieval-policy', u'get-data-source', u'get-deployment', u'get-deployment-config', u'get-deployment-group', u'get-deployment-instance', u'get-device', u'get-device-pool', u'get-device-pool-compatibility', u'get-directory-limits', u'get-distribution', u'get-distribution-config', u'get-document', u'get-domain-detail', u'get-endpoint-attributes', u'get-evaluation', u'get-event-source-mapping', u'get-federation-token', u'get-function', u'get-function-configuration', u'get-geo-location', u'get-group', u'get-group-policy', u'get-health-check', u'get-health-check-count', u'get-health-check-last-failure-reason', u'get-health-check-status', u'get-hosted-zone', u'get-hosted-zone-count', u'get-hostname-suggestion', u'get-id', u'get-identity-dkim-attributes', u'get-identity-notification-attributes', u'get-identity-policies', u'get-identity-pool-configuration', u'get-identity-pool-roles', u'get-identity-verification-attributes', u'get-instance-profile', u'get-invalidation', u'get-item', u'get-job', u'get-job-details', u'get-job-output', u'get-key-policy', u'get-key-rotation-status', u'get-log-events', u'get-login-profile', u'get-metric-statistics', u'get-ml-model', u'get-object', u'get-object-acl', u'get-object-torrent', u'get-on-premises-instance', u'get-open-id-connect-provider', u'get-open-id-token', u'get-open-id-token-for-developer-identity', u'get-operation-detail', u'get-password-data', u'get-pipeline', u'get-pipeline-definition', u'get-pipeline-state', u'get-platform-application-attributes', u'get-policy', u'get-policy-version', u'get-project', u'get-queue-attributes', u'get-queue-url', u'get-records', u'get-repository', u'get-resource-config-history', u'get-reusable-delegation-set', u'get-role', u'get-role-policy', u'get-run', u'get-saml-provider', u'get-send-quota', u'get-send-statistics', u'get-server-certificate', u'get-session-token', u'get-shard-iterator', u'get-shipping-label', u'get-snapshot-limits', u'get-ssh-public-key', u'get-stack-policy', u'get-status', u'get-streaming-distribution', u'get-streaming-distribution-config', u'get-subscription-attributes', u'get-suite', u'get-template', u'get-template-summary', u'get-test', u'get-third-party-job-details', u'get-topic-attributes', u'get-trail-status', u'get-upload', u'get-user', u'get-user-policy', u'get-vault-access-policy', u'get-vault-lock', u'get-vault-notifications', u'get-workflow-execution-history', u'grant-access', u'head-bucket', u'head-object', u'import-image', u'import-key-pair', u'import-snapshot', u'index-documents', u'initiate-job', u'initiate-multipart-upload', u'initiate-vault-lock', u'install', u'install-applications', u'invoke', u'invoke-async', u'list', u'list-access-keys', u'list-account-aliases', u'list-action-types', u'list-activity-types', u'list-aliases', u'list-application-revisions', u'list-applications', u'list-artifacts', u'list-associations', u'list-attached-group-policies', u'list-attached-role-policies', u'list-attached-user-policies', u'list-available-solution-stacks', u'list-available-zones', u'list-branches', u'list-buckets', u'list-closed-workflow-executions', u'list-cloud-front-origin-access-identities', u'list-clusters', u'list-container-instances', u'list-datasets', u'list-dead-letter-source-queues', u'list-deployment-configs', u'list-deployment-groups', u'list-deployment-instances', u'list-deployments', u'list-device-pools', u'list-devices', u'list-discovered-resources', u'list-distributions', u'list-documents', u'list-domain-names', u'list-domains', u'list-endpoints-by-platform-application', u'list-entities-for-policy', u'list-event-source-mappings', u'list-functions', u'list-gateways', u'list-geo-locations', u'list-grants', u'list-group-policies', u'list-groups', u'list-groups-for-user', u'list-hapgs', u'list-health-checks', u'list-hosted-zones', u'list-hosted-zones-by-name', u'list-hsms', u'list-identities', u'list-identity-policies', u'list-identity-pool-usage', u'list-identity-pools', u'list-instance-profiles', u'list-instance-profiles-for-role', u'list-instances', u'list-invalidations', u'list-jobs', u'list-jobs-by-pipeline', u'list-jobs-by-status', u'list-key-policies', u'list-keys', u'list-local-disks', u'list-luna-clients', u'list-metrics', u'list-mfa-devices', u'list-multipart-uploads', u'list-object-versions', u'list-objects', u'list-on-premises-instances', u'list-open-id-connect-providers', u'list-open-workflow-executions', u'list-operations', u'list-parts', u'list-pipelines', u'list-platform-applications', u'list-policies', u'list-policy-versions', u'list-presets', u'list-projects', u'list-queues', u'list-records', u'list-repositories', u'list-resource-record-sets', u'list-reusable-delegation-sets', u'list-role-policies', u'list-roles', u'list-runs', u'list-saml-providers', u'list-samples', u'list-server-certificates', u'list-services', u'list-signing-certificates', u'list-ssh-public-keys', u'list-stack-resources', u'list-stacks', u'list-steps', u'list-streaming-distributions', u'list-streams', u'list-subscriptions', u'list-subscriptions-by-topic', u'list-suites', u'list-tables', u'list-tags-for-domain', u'list-tags-for-resource', u'list-tags-for-resources', u'list-tags-for-stream', u'list-tags-for-vault', u'list-task-definition-families', u'list-task-definitions', u'list-tasks', u'list-tests', u'list-topics', u'list-unique-problems', u'list-uploads', u'list-user-policies', u'list-users', u'list-vaults', u'list-virtual-mfa-devices', u'list-volume-initiators', u'list-volume-recovery-points', u'list-volumes', u'list-workflow-types', u'lookup-developer-identity', u'lookup-events', u'ls', u'mb', u'merge-developer-identities', u'merge-shards', u'modify-cache-cluster', u'modify-cache-parameter-group', u'modify-cache-subnet-group', u'modify-cluster', u'modify-cluster-attributes', u'modify-cluster-parameter-group', u'modify-cluster-subnet-group', u'modify-db-cluster', u'modify-db-cluster-parameter-group', u'modify-db-instance', u'modify-db-parameter-group', u'modify-db-subnet-group', u'modify-event-subscription', u'modify-hapg', u'modify-hsm', u'modify-image-attribute', u'modify-instance-attribute', u'modify-instance-groups', u'modify-load-balancer-attributes', u'modify-luna-client', u'modify-mount-target-security-groups', u'modify-network-interface-attribute', u'modify-replication-group', u'modify-reserved-instances', u'modify-snapshot-attribute', u'modify-snapshot-copy-retention-period', u'modify-subnet-attribute', u'modify-volume-attribute', u'modify-vpc-attribute', u'modify-vpc-endpoint', u'monitor-instances', u'move-address-to-vpc', u'mv', u'poll-for-activity-task', u'poll-for-decision-task', u'poll-for-jobs', u'poll-for-task', u'poll-for-third-party-jobs', u'predict', u'promote-read-replica', u'publish', u'purchase-reserved-cache-nodes-offering', u'purchase-reserved-db-instances-offering', u'purchase-reserved-instances-offering', u'purchase-reserved-node-offering', u'purge-queue', u'push', u'put', u'put-action-revision', u'put-attributes', u'put-bucket-acl', u'put-bucket-cors', u'put-bucket-lifecycle', u'put-bucket-lifecycle-configuration', u'put-bucket-logging', u'put-bucket-notification', u'put-bucket-notification-configuration', u'put-bucket-policy', u'put-bucket-replication', u'put-bucket-request-payment', u'put-bucket-tagging', u'put-bucket-versioning', u'put-bucket-website', u'put-configuration-recorder', u'put-delivery-channel', u'put-destination', u'put-destination-policy', u'put-group-policy', u'put-identity-policy', u'put-item', u'put-job-failure-result', u'put-job-success-result', u'put-key-policy', u'put-lifecycle-hook', u'put-log-events', u'put-metric-alarm', u'put-metric-data', u'put-metric-filter', u'put-notification-configuration', u'put-object', u'put-object-acl', u'put-pipeline-definition', u'put-record', u'put-records', u'put-retention-policy', u'put-role-policy', u'put-scaling-policy', u'put-scheduled-update-group-action', u'put-subscription-filter', u'put-third-party-job-failure-result', u'put-third-party-job-success-result', u'put-user-policy', u'query', u'query-objects', u'rb', u're-encrypt', u'read-job', u'read-pipeline', u'read-preset', u'reboot-cache-cluster', u'reboot-cluster', u'reboot-db-instance', u'reboot-instance', u'reboot-instances', u'reboot-workspaces', u'rebuild-environment', u'rebuild-workspaces', u'receive-message', u'record-activity-task-heartbeat', u'record-lifecycle-action-heartbeat', u'refresh-trusted-advisor-check', u'register', u'register-activity-type', u'register-application-revision', u'register-container-instance', u'register-device', u'register-domain', u'register-ecs-cluster', u'register-elastic-ip', u'register-image', u'register-instance', u'register-instances-with-load-balancer', u'register-on-premises-instance', u'register-rds-db-instance', u'register-task-definition', u'register-volume', u'register-workflow-type', u'reject-vpc-peering-connection', u'release-address', u'remove-client-id-from-open-id-connect-provider', u'remove-option-from-option-group', u'remove-permission', u'remove-role-from-instance-profile', u'remove-source-identifier-from-subscription', u'remove-tags', u'remove-tags-from-on-premises-instances', u'remove-tags-from-resource', u'remove-tags-from-stream', u'remove-tags-from-vault', u'remove-user-from-group', u'replace-network-acl-association', u'replace-network-acl-entry', u'replace-route', u'replace-route-table-association', u'report-instance-status', u'report-task-progress', u'report-task-runner-heartbeat', u'request-cancel-workflow-execution', u'request-environment-info', u'request-spot-fleet', u'request-spot-instances', u'reset-cache', u'reset-cache-parameter-group', u'reset-cluster-parameter-group', u'reset-db-cluster-parameter-group', u'reset-db-parameter-group', u'reset-image-attribute', u'reset-instance-attribute', u'reset-network-interface-attribute', u'reset-snapshot-attribute', u'resolve-case', u'respond-activity-task-canceled', u'respond-activity-task-completed', u'respond-activity-task-failed', u'respond-decision-task-completed', u'restart-app-server', u'restore-address-to-classic', u'restore-db-cluster-from-snapshot', u'restore-db-cluster-to-point-in-time', u'restore-db-instance-from-db-snapshot', u'restore-db-instance-to-point-in-time', u'restore-from-cluster-snapshot', u'restore-from-hbase-backup', u'restore-from-snapshot', u'restore-object', u'resume-processes', u'resync-mfa-device', u'retire-grant', u'retrieve-domain-auth-code', u'retrieve-environment-info', u'retrieve-tape-archive', u'retrieve-tape-recovery-point', u'revoke-cache-security-group-ingress', u'revoke-cluster-security-group-ingress', u'revoke-db-security-group-ingress', u'revoke-grant', u'revoke-security-group-egress', u'revoke-security-group-ingress', u'revoke-snapshot-access', u'rm', u'rotate-encryption-key', u'run-instances', u'run-task', u'scan', u'schedule-hbase-backup', u'schedule-run', u'search', u'select', u'send-email', u'send-message', u'send-message-batch', u'send-raw-email', u'set', u'set-alarm-state', u'set-cognito-events', u'set-data-retrieval-policy', u'set-default-policy-version', u'set-desired-capacity', u'set-endpoint-attributes', u'set-identity-dkim-enabled', u'set-identity-feedback-forwarding-enabled', u'set-identity-notification-topic', u'set-identity-pool-configuration', u'set-identity-pool-roles', u'set-instance-health', u'set-load-balancer-listener-ssl-certificate', u'set-load-balancer-policies-for-backend-server', u'set-load-balancer-policies-of-listener', u'set-load-based-auto-scaling', u'set-permission', u'set-platform-application-attributes', u'set-queue-attributes', u'set-stack-policy', u'set-status', u'set-subscription-attributes', u'set-task-status', u'set-time-based-auto-scaling', u'set-topic-attributes', u'set-vault-access-policy', u'set-vault-notifications', u'shutdown-gateway', u'signal-resource', u'signal-workflow-execution', u'simulate-custom-policy', u'simulate-principal-policy', u'socks', u'split-shard', u'ssh', u'start-configuration-recorder', u'start-gateway', u'start-instance', u'start-instances', u'start-logging', u'start-pipeline-execution', u'start-stack', u'start-task', u'start-workflow-execution', u'stop-configuration-recorder', u'stop-deployment', u'stop-instance', u'stop-instances', u'stop-logging', u'stop-stack', u'stop-task', u'submit-container-state-change', u'submit-task-state-change', u'subscribe', u'subscribe-to-dataset', u'suggest', u'suspend-processes', u'swap-environment-cnames', u'sync', u'terminate-clusters', u'terminate-environment', u'terminate-instance-in-auto-scaling-group', u'terminate-instances', u'terminate-workflow-execution', u'terminate-workspaces', u'test-metric-filter', u'test-role', u'transfer-domain', u'unassign-instance', u'unassign-private-ip-addresses', u'unassign-volume', u'uninstall', u'unlink-developer-identity', u'unlink-identity', u'unmonitor-instances', u'unsubscribe', u'unsubscribe-from-dataset', u'update-access-key', u'update-account-password-policy', u'update-alias', u'update-app', u'update-application', u'update-application-version', u'update-association-status', u'update-assume-role-policy', u'update-auto-scaling-group', u'update-availability-options', u'update-bandwidth-rate-limit', u'update-batch-prediction', u'update-chap-credentials', u'update-cloud-front-origin-access-identity', u'update-configuration-template', u'update-container-agent', u'update-data-source', u'update-default-branch', u'update-deployment-group', u'update-distribution', u'update-domain-contact', u'update-domain-contact-privacy', u'update-domain-nameservers', u'update-elastic-ip', u'update-environment', u'update-evaluation', u'update-event-source-mapping', u'update-function-code', u'update-function-configuration', u'update-gateway-information', u'update-gateway-software-now', u'update-group', u'update-health-check', u'update-hosted-zone-comment', u'update-identity-pool', u'update-instance', u'update-item', u'update-job', u'update-key-description', u'update-layer', u'update-login-profile', u'update-maintenance-start-time', u'update-ml-model', u'update-my-user-profile', u'update-open-id-connect-provider-thumbprint', u'update-pipeline', u'update-pipeline-notifications', u'update-pipeline-status', u'update-radius', u'update-rds-db-instance', u'update-records', u'update-repository-description', u'update-repository-name', u'update-saml-provider', u'update-scaling-parameters', u'update-server-certificate', u'update-service', u'update-service-access-policies', u'update-signing-certificate', u'update-snapshot-schedule', u'update-ssh-public-key', u'update-stack', u'update-streaming-distribution', u'update-subscription', u'update-table', u'update-tags-for-domain', u'update-trail', u'update-user', u'update-user-profile', u'update-volume', u'update-vtl-device-type', u'upload-archive', u'upload-documents', u'upload-multipart-part', u'upload-part', u'upload-part-copy', u'upload-server-certificate', u'upload-signing-certificate', u'upload-ssh-public-key', u'validate-configuration-settings', u'validate-pipeline-definition', u'validate-template', u'verify-domain-dkim', u'verify-domain-identity', u'verify-email-identity', u'wait', u'website'], [u'--color', u'--debug', u'--endpoint-url', u'--no-paginate', u'--no-sign-request', u'--no-verify-ssl', u'--output', u'--profile', u'--query', u'--region', u'--version'], [u'--bucket', u'--instance-ids'], [u'pending', u'running', u'shutting-down', u'stopped', u'stopping', u'terminated'])
config = <saws.config.Config object>
config_obj = ConfigObj({'main': {'color_output': 'True', 'fuzzy_match': 'True', 'shortcut_match': 'True', 'log_file': '~/.saws.log', 'log_level': 'INFO', 'refresh_instance_ids': 'True', 'refresh_instance_tags': 'True', 'refresh_bucket_names': 'True'}, 'shortcuts': {'ec2 ls --instance-ids': 'ec2 describe-instances --instance-ids', 'ec2 start-instances --instance-ids': 'ec2 start-instances --instance-ids', 'ec2 stop-instances --instance-ids': 'ec2 stop-instances --instance-ids', 'ec2 ls --ec2-tag-key': 'ec2 describe-instances --filters "Name=tag-key,Values=%s"', 'ec2 ls --ec2-tag-value': 'ec2 describe-instances --filters "Name=tag-value,Values=%s"', 'ec2 ls --ec2-state': 'ec2 describe-instances --filters "Name=instance-state-name,Values=%s"', 'ec2 ls': 'ec2 describe-instances', 'emr ls': 'emr list-clusters', 'elb ls': 'elb describe-load-balancers', 'dynamodb ls': 'dynamodb list-tables', 's3 ls s3://': 's3 ls s3://'}})
shortcut = 's3 ls s3://'
shortcut_tokens = ['ec2', 'ls', '--instance-ids', 'ec2', 'start-instances', '--instance-ids', 'ec2', 'stop-instances', '--instance-ids', 'ec2', 'ls', '--ec2-tag-key', 'ec2', 'ls', '--ec2-tag-value', 'ec2', 'ls', '--ec2-state', 'ec2', 'ls', 'emr', 'ls', 'elb', 'ls', 'dynamodb', 'ls', 's3', 'ls', 's3://']
shortcuts = OrderedDict([('ec2 ls --instance-ids', 'ec2 describe-instances --instance-ids'), ('ec2 start-instances --instance-ids', 'ec2 start-instances --instance-ids'), ('ec2 stop-instances --instance-ids', 'ec2 stop-instances --instance-ids'), ('ec2 ls --ec2-tag-key', 'ec2 describe-instances --filters "Name=tag-key,Values=%s"'), ('ec2 ls --ec2-tag-value', 'ec2 describe-instances --filters "Name=tag-value,Values=%s"'), ('ec2 ls --ec2-state', 'ec2 describe-instances --filters "Name=instance-state-name,Values=%s"'), ('ec2 ls', 'ec2 describe-instances'), ('emr ls', 'emr list-clusters'), ('elb ls', 'elb describe-load-balancers'), ('dynamodb ls', 'dynamodb list-tables'), ('s3 ls s3://', 's3 ls s3://')])
token = 's3://'
tokens = {'root': [(<pygments.lexer.words object at 0x10650ad10>, Token.Literal.String), (<pygments.lexer.words object at 0x10650ad50>, Token.Literal.Number), (<pygments.lexer.words object at 0x10650ad90>, Token.Name.Class), (<pygments.lexer.words object at 0x10650add0>, Token.Keyword.Declaration), (<pygments.lexer.words object at 0x10650ae10>, Token.Generic.Output), (<pygments.lexer.words object at 0x10650ae50>, Token.Operator.Word), (<pygments.lexer.words object at 0x10650ae90>, Token.Generic.Output), (<pygments.lexer.words object at 0x10650aed0>, Token.Name.Exception)]}

saws.logger module

class saws.logger.SawsLogger(name, log_file, log_level)

Bases: object

Handles Saws logging.

Attributes:
  • logger: An instance of Logger.
__init__(name, log_file, log_level)

Initializes a Logger for Saws.

Args:
  • name: A string that represents the logger’s name.
  • log_file: A string that represents the log file name.
  • log_level: A string that represents the logging level.
Returns:
None.

saws.main module

saws.resources module

class saws.resources.AwsResources(log_exception, refresh_instance_ids=True, refresh_instance_tags=True, refresh_bucket_names=True)

Bases: object

Loads and stores AWS resources.

Attributes:
  • instance_ids: A list of instance ids.

  • instance_tag_keys: A set of instance tag keys.

  • instance_tag_values: A set of isntance tag values.

  • bucket_names: A list of bucket names.

  • refresh_instance_ids: A boolean that determines whether to

    refresh instance ids by querying AWS.

  • refresh_instance_tags: A boolean that determines whether to

    refresh instance tags by querying AWS.

  • refresh_bucket_names: A boolean that determines whether to

    refresh bucket names by querying AWS.

  • INSTANCE_IDS_MARKER: A string marking the start of

    instance ids in data/RESOURCES.txt.

  • INSTANCE_TAG_KEYS_MARKER: A string marking the start of

    instance tag keys in data/RESOURCES.txt.

  • INSTANCE_TAG_VALUES_MARKER: A string marking the start of

    instance tag values in data/RESOURCES.txt.

  • BUCKET_NAMES_MARKER: A string marking the start of i

    bucket names in data/RESOURCES.txt.

QUERY_INSTANCE_IDS_CMD: A string representing the AWS query to
list all instance ids
QUERY_INSTANCE_TAG_KEYS_CMD: A string representing the AWS query to
list all instance tag keys
QUERY_INSTANCE_TAG_VALUES_CMD: A string representing the AWS query to
list all instance tag values
QUERY_BUCKET_NAMES_CMD: A string representing the AWS query to
list all bucket names
  • log_exception: A callable log_exception from SawsLogger.
class ResType

Bases: enum.Enum

Enum specifying the resource type.

Attributes:
  • INSTANCE_IDS: An int representing instance ids.
  • INSTANCE_TAG_KEYS: An int representing instance tag keys.
  • INSTANCE_TAG_VALUES: An int representing instance tag values.
  • BUCKET_NAMES: An int representing bucket names.
AwsResources.__init__(log_exception, refresh_instance_ids=True, refresh_instance_tags=True, refresh_bucket_names=True)

Initializes AwsResources.

Args:
  • log_exception: A callable log_exception from SawsLogger.

  • refresh_instance_ids: A boolean that determines whether to

    refresh instance ids by querying AWS.

  • refresh_instance_tags: A boolean that determines whether to

    refresh instance tags by querying AWS.

  • refresh_bucket_names: A boolean that determines whether to

    refresh bucket names by querying AWS.

Returns:
None.
AwsResources.add_bucket_name(bucket_name)

Adds the bucket name to our bucket resources.

Args:
  • bucket_name: A string representing the bucket name.
Returns:
None.
AwsResources.clear_bucket_names()

Clears bucket all bucket names.

Long description.

Args:
  • None.
Returns:
None.
AwsResources.query_aws(command)
AwsResources.query_bucket_names()

Queries and stores bucket names from AWS.

Args:
  • None
Returns:
None
AwsResources.query_instance_ids()

Queries and stores instance ids from AWS.

Args:
  • None.
Returns:
None.
AwsResources.query_instance_tag_keys()

Queries and stores instance tag keys from AWS.

Args:
  • None.
Returns:
None.
AwsResources.query_instance_tag_values()

Queries and stores instance tag values from AWS.

Args:
  • None
Returns:
None.
AwsResources.refresh(force_refresh=False)

Refreshes the AWS resources and caches them to a file.

This function is called on startup. If no cache exists, it queries AWS to build the resource lists. Pressing the F5 key will set force_refresh to True, which proceeds to refresh the list regardless of whether a cache exists. Before returning, it saves the resource lists to cache.

Args:
  • force_refresh: A boolean determines whether to force a cache

    refresh. This value is set to True when the user presses F5.

Returns:
None.
AwsResources.refresh_resources_from_file(file_path)

Refreshes the AWS resources from data/RESOURCES.txt.

Args:
  • file_path: A string representing the resource file path.
Returns:
None.
AwsResources.save_resources_to_file(file_path)

Saves the AWS resources to data/RESOURCES.txt.

Args:
  • file_path: A string representing the resource file path.
Returns:
None.

saws.saws module

class saws.saws.Saws

Bases: object

Encapsulates the Saws CLI.

Attributes:
  • aws_cli: An instance of prompt_toolkit’s CommandLineInterface.

  • config: An instance of Config.

  • config_obj: An instance of ConfigObj, reads from ~/.sawsrc.

  • aws_commands: An instance of AwsCommands

  • commands: A list of commands from data/SOURCES.txt.

  • sub_commands: A list of sub_commands from data/SOURCES.txt.

  • global_options: A list of global_options from data/SOURCES.txt.

  • resource_options: A list of resource_options from data/SOURCES.txt,

    used for syntax coloring.

  • ec2_states: A list of ec2_states from data/SOURCES.txt.

  • completer: An instance of AwsCompleter.

  • key_manager: An instance of KeyManager

  • logger: An instance of SawsLogger.

  • theme: A string representing the lexer theme.

    Currently only ‘vim’ is supported.

__init__()

Inits Saws.

Args:
  • None.
Returns:
None.
colorize_output(text)

Highlights output with pygments.

Only highlights the output if all of the following conditions are True:

  • The color option is enabled

  • The text does not contain the configure command

  • The text does not contain the help command, which already does

    output highlighting

Args:
  • text: A string that represents the input command text.
Returns:
A string that represents:
  • The original command text if no highlighting was performed.
  • The pygments highlighted command text otherwise.
create_cli()

Creates the prompt_toolkit’s CommandLineInterface.

Long description.

Args:
  • None.
Returns:
None.
get_color()

Getter for color output mode.

Used by prompt_toolkit’s KeyBindingManager. KeyBindingManager expects this function to be callable so we can’t use @property and @attrib.setter.

Args:
  • None.
Returns:
A boolean that represents the color flag.
get_fuzzy_match()

Getter for fuzzy matching mode

Used by prompt_toolkit’s KeyBindingManager. KeyBindingManager expects this function to be callable so we can’t use @property and @attrib.setter.

Args:
  • None.
Returns:
A boolean that represents the fuzzy flag.
get_shortcut_match()

Getter for shortcut matching mode

Used by prompt_toolkit’s KeyBindingManager. KeyBindingManager expects this function to be callable so we can’t use @property and @attrib.setter.

Args:
  • None.
Returns:
A boolean that represents the shortcut flag.
handle_cd(text)

Handles a cd shell command by calling python’s os.chdir.

Simply passing in the cd command to subprocess.call doesn’t work. Note: Changing the directory within Saws will only be in effect while running Saws. Exiting the program will return you to the directory you were in prior to running Saws.

Attributes:
  • text: A string representing the input command text.
Returns:
A boolean representing a cd command was found and handled.
handle_docs(text=None, from_fkey=False)

Displays contextual web docs for F9 or the docs command.

Displays the web docs specific to the currently entered:

  • (optional) command
  • (optional) subcommand

If no command or subcommand is present, the docs index page is shown.

Docs are only displayed if:

  • from_fkey is True
  • from_fkey is False and docs is found in text
Args:
  • text: A string representing the input command text.

  • from_fkey: A boolean representing whether this function is

    being executed from an F9 key press.

Returns:
A boolean representing whether the web docs were shown.
log_exception(e, traceback, echo=False)

Logs the exception and traceback to the log file ~/.saws.log.

Args:
  • e: A Exception that specifies the exception.

  • traceback: A Traceback that specifies the traceback.

  • echo: A boolean that specifies whether to echo the exception

    to the console using click.

Returns:
None.
process_command(text)

Processes the input command, called by the cli event loop

Args:
  • text: A string that represents the input command text.
Returns:
None.
refresh_resources()

Convenience function to refresh resources for completion.

Used by prompt_toolkit’s KeyBindingManager.

Args:
  • None.
Returns:
None.
run_cli()

Runs the main loop.

Args:
  • None.
Returns:
None.
set_color(color)

Setter for color output mode.

Used by prompt_toolkit’s KeyBindingManager. KeyBindingManager expects this function to be callable so we can’t use @property and @attrib.setter.

Args:
  • color: A boolean that represents the color flag.
Returns:
None.
set_fuzzy_match(fuzzy)

Setter for fuzzy matching mode

Used by prompt_toolkit’s KeyBindingManager. KeyBindingManager expects this function to be callable so we can’t use @property and @attrib.setter.

Args:
  • color: A boolean that represents the fuzzy flag.
Returns:
None.
set_shortcut_match(shortcut)

Setter for shortcut matching mode

Used by prompt_toolkit’s KeyBindingManager. KeyBindingManager expects this function to be callable so we can’t use @property and @attrib.setter.

Args:
  • color: A boolean that represents the shortcut flag.
Returns:
None.

saws.style module

class saws.style.StyleFactory(name)

Bases: object

Creates a custom saws style.

Provides styles for the completions menu and toolbar.

Attributes:
  • None.
__init__(name)

Initializes StyleFactory.

Args:
  • name: A string representing the pygments style.
Returns:
An instance of CliStyle.
style_factory(name)

Retrieves the specified pygments style.

If the specified style is not found, the native style is returned.

Args:
  • name: A string representing the pygments style.
Returns:
An instance of CliStyle.

saws.toolbar module

class saws.toolbar.Toolbar(color_cfg, fuzzy_cfg, shortcuts_cfg)

Bases: object

Encapsulates the bottom toolbar.

Attributes:
  • handler: A callable get_toolbar_items.
__init__(color_cfg, fuzzy_cfg, shortcuts_cfg)

Initializes ToolBar.

Args:
  • color_cfg: A boolean that spedifies whether to color the output.
  • fuzzy_cfg: A boolean that spedifies whether to do fuzzy matching.
  • shortcuts_cfg: A boolean that spedifies whether to match shortcuts.
Returns:
None
create_toolbar_handler(color_cfg, fuzzy_cfg, shortcuts_cfg)

Creates the toolbar handler.

Args:
  • color_cfg: A boolean that spedifies whether to color the output.
  • fuzzy_cfg: A boolean that spedifies whether to do fuzzy matching.
  • shortcuts_cfg: A boolean that spedifies whether to match shortcuts.
Returns:
A callable get_toolbar_items.

saws.utils module

class saws.utils.TextUtils

Bases: object

Utilities for parsing and matching text.

Attributes:
  • None.
find_collection_matches(word, collection, fuzzy)

Yields all matching names in list.

Args:
  • word: A string representing the word before

    the cursor.

  • collection: A collection of words to match.

  • fuzzy: A boolean that specifies whether to use fuzzy matching.

Yields:
A generator of prompt_toolkit’s Completions.
find_matches(word, collection, fuzzy)

Finds all matches in collection for word.

Args:
  • word: A string representing the word before

    the cursor.

  • collection: A collection of words to match.

  • fuzzy: A boolean that specifies whether to use fuzzy matching.

Yields:
A generator of prompt_toolkit’s Completions.
get_tokens(text)

Parses out all tokens.

Args:
  • text: A string to split into tokens.
Returns:
A list of strings for each word in the text.
last_token(text)

Finds the last word in text.

Args:
  • text: A string to parse and obtain the last word.
Returns:
A string representing the last word in the text.
safe_split(text)

Safely splits the input text.

Shlex can’t always split. For example, “” crashes the completer.

Args:
  • text: A string to split.
Returns:
A list that contains words for each split element of text.
shlex_split(text)

Wrapper for shlex, because it does not seem to handle unicode in 2.6.

Args:
  • text: A string to split.
Returns:
A list that contains words for each split element of text.

Module contents