<commit_before>'''
Primary interfaces for the salt-cloud system
'''
# Need to get data from 4 sources!
# CLI options
# salt cloud config - /etc/salt/cloud
# salt master config (for master integration)
# salt VM config, where VMs are defined - /etc/salt/cloud.profiles
#
# The cli, master and cloud configs will merge for opts
# the VM data will be in opts['vm']

# Import python libs
import optparse
import os

# Import salt libs
import saltcloud.config
import saltcloud.output
import salt.config
import salt.output

# Import saltcloud libs
from saltcloud.utils import parsers
from saltcloud.libcloudfuncs import libcloud_version


class SaltCloud(parsers.SaltCloudParser):
    def run(self):
        '''
        Execute the salt-cloud command line
        '''
        libcloud_version()

        # Parse shell arguments
        self.parse_args()

        # Setup log file logging
        self.setup_logfile_logger()

        # Late imports so logging works as expected
        import logging
        logging.getLogger(__name__).info('salt-cloud starting')
        import saltcloud.cloud
        mapper = saltcloud.cloud.Map(self.config)

        if self.selected_query_option is not None:
            if self.options.map:
                try:
                    query_map = mapper.interpolated_map(
                        query=self.selected_query_option
                    )
                except Exception as exc:
                    print('There was an error: {0}'.format(exc))
            else:
                try:
                    query_map = mapper.map_providers(
                        query=self.selected_query_option
                    )
                except Exception as exc:
                    print('There was an error: {0}'.format(exc))
            salt.output.display_output(query_map, '', self.config)

        if self.options.list_locations is not None:
            try:
                saltcloud.output.double_layer(
                    mapper.location_list(self.options.list_locations)
                )
            except Exception as exc:
                print('There was an error: {0}'.format(exc))
            self.exit(0)

        if self.options.list_images is not None:
            try:
                saltcloud.output.double_layer(
                    mapper.image_list(self.options.list_images)
                )
            except Exception as exc:
                print('There was an error: {0}'.format(exc))
            self.exit(0)

        if self.options.list_sizes is not None:
            try:
                saltcloud.output.double_layer(
                    mapper.size_list(self.options.list_sizes)
                )
            except Exception as exc:
                print('There was an error: {0}'.format(exc))
            self.exit(0)

        if self.options.destroy and (self.config.get('names', None) or
                                     self.options.map):
            if self.options.map:
                names = mapper.delete_map(query='list_nodes')
            else:
                names = self.config.get('names', None)

            try:
                mapper.destroy(names)
            except Exception as exc:
                print('There was an error: {0}'.format(exc))
            self.exit(0)<commit_msg>confirmation for destroying nodes fixes #219<commit_after>'''
Primary interfaces for the salt-cloud system
'''
# Need to get data from 4 sources!
# CLI options
# salt cloud config - /etc/salt/cloud
# salt master config (for master integration)
# salt VM config, where VMs are defined - /etc/salt/cloud.profiles
#
# The cli, master and cloud configs will merge for opts
# the VM data will be in opts['vm']

# Import python libs
import optparse
import os

# Import salt libs
import saltcloud.config
import saltcloud.output
import salt.config
import salt.output

# Import saltcloud libs
from saltcloud.utils import parsers
from saltcloud.libcloudfuncs import libcloud_version


class SaltCloud(parsers.SaltCloudParser):
    def run(self):
        '''
        Execute the salt-cloud command line
        '''
        libcloud_version()

        # Parse shell arguments
        self.parse_args()

        # Setup log file logging
        self.setup_logfile_logger()

        # Late imports so logging works as expected
        import logging
        logging.getLogger(__name__).info('salt-cloud starting')
        import saltcloud.cloud
        mapper = saltcloud.cloud.Map(self.config)

        if self.selected_query_option is not None:
            if self.options.map:
                try:
                    query_map = mapper.interpolated_map(
                        query=self.selected_query_option
                    )
                except Exception as exc:
                    print('There was an error: {0}'.format(exc))
            else:
                try:
                    query_map = mapper.map_providers(
                        query=self.selected_query_option
                    )
                except Exception as exc:
                    print('There was an error: {0}'.format(exc))
            salt.output.display_output(query_map, '', self.config)

        if self.options.list_locations is not None:
            try:
                saltcloud.output.double_layer(
                    mapper.location_list(self.options.list_locations)
                )
            except Exception as exc:
                print('There was an error: {0}'.format(exc))
            self.exit(0)

        if self.options.list_images is not None:
            try:
                saltcloud.output.double_layer(
                    mapper.image_list(self.options.list_images)
                )
            except Exception as exc:
                print('There was an error: {0}'.format(exc))
            self.exit(0)

        if self.options.list_sizes is not None:
            try:
                saltcloud.output.double_layer(
                    mapper.size_list(self.options.list_sizes)
                )
            except Exception as exc:
                print('There was an error: {0}'.format(exc))
            self.exit(0)

        if self.options.destroy and (self.config.get('names', None) or
                                     self.options.map):
            if self.options.map:
                names = mapper.delete_map(query='list_nodes')
            else:
                names = self.config.get('names', None)

            msg = 'The following virtual machines are set to be destroyed:\n'
            for name in names:
                msg += '  {0}\n'.format(name)
            print(msg)
            res = raw_input('Proceed? [N/y]')
            if not res.lower().startswith('y'):
                return
            print('...proceeding')

            try:
                mapper.destroy(names)
            except Exception as exc:
                print('There was an error: {0}'.format(exc))
            self.exit(0)
{'fraction_non_alphanumeric': 0.08407974573822595, 'fraction_numerical': 0.0037561398439757295, 'mean_word_length': 1.6263277693474962, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '61608', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1755, 'n_words': 491}