<commit_before>'''
Read in a vm map file. The map file contains a mapping of profiles to names
allowing for individual vms to be created in a more stateful way
'''

# Import python libs
import os
import copy
import multiprocessing

# Import salt libs
import saltcloud.cloud
import salt.client

# Import third party libs
import yaml


class Map(object):
    '''
    Create a vm stateful map execution object
    '''
    def __init__(self, opts):
        self.opts = opts
        self.cloud = saltcloud.cloud.Cloud(self.opts)
        self.map = self.read()

    def read(self):
        '''
        Read in the specified map file and return the map structure
        '''
        if not self.opts['map']:
            return {}
        if not os.path.isfile(self.opts['map']):
            return {}
        try:
            with open(self.opts['map'], 'rb') as fp_:
                map_ = yaml.loads(fb_.read())
        except Exception:
            return {}
        if 'include' in map_:
            map_ = salt.config.include_config(map_, self.opts['map'])
        return map_

    def run_map(self):
        '''
        Execute the contents of the vm map
        '''
        for profile in self.map:
            for name in self.map[profile]:
                if not profile in self.opts['vm']:
                    continue
                vm_ = copy.deepcopy(self.opts['vm'][profile])
                vm_['name'] = name
                if self.opts['parallel']:
                    multiprocessing.Process(
                            target=lambda: self.cloud.create(vm_)
                            ).start()
                else:<commit_msg>fix exceptions in yaml loading<commit_after>'''
Read in a vm map file. The map file contains a mapping of profiles to names
allowing for individual vms to be created in a more stateful way
'''

# Import python libs
import os
import copy
import multiprocessing

# Import salt libs
import saltcloud.cloud
import salt.client

# Import third party libs
import yaml


class Map(object):
    '''
    Create a vm stateful map execution object
    '''
    def __init__(self, opts):
        self.opts = opts
        self.cloud = saltcloud.cloud.Cloud(self.opts)
        self.map = self.read()

    def read(self):
        '''
        Read in the specified map file and return the map structure
        '''
        if not self.opts['map']:
            return {}
        if not os.path.isfile(self.opts['map']):
            return {}
        try:
            with open(self.opts['map'], 'rb') as fp_:
                map_ = yaml.load(fp_.read())
        except Exception:
            return {}
        if 'include' in map_:
            map_ = salt.config.include_config(map_, self.opts['map'])
        return map_

    def run_map(self):
        '''
        Execute the contents of the vm map
        '''
        for profile in self.map:
            for name in self.map[profile]:
                if not profile in self.opts['vm']:
                    continue
                vm_ = copy.deepcopy(self.opts['vm'][profile])
                vm_['name'] = name
                if self.opts['parallel']:
                    multiprocessing.Process(
                            target=lambda: self.cloud.create(vm_)
                            ).start()
                else:
{'fraction_non_alphanumeric': 0.09872804360993337, 'fraction_numerical': 0.0, 'mean_word_length': 1.6701697655618433, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5588789', 'n_tokens_mistral': 902, 'n_tokens_neox': 871, 'n_words': 291}