<commit_before>from pwd import getpwnam
from os import path, makedirs, chown, chmod

# NGUtil Libraries
from .common import _NGUtilCommon

class _NGUtilTemplates(_NGUtilCommon):
    """
    Class for handling loading and updating template files.
    """
    def __init__(self):
        super(_NGUtilTemplates, self).__init__()
        
        # Active template / target file
        self.active = None
        self.target = None
        
        # Template contents
        self.contents = None
        
    def _mkpath(self, file):
        """
        Make sure the path to a file exists.
        """
        
        # Target directory
        target_dir = path.dirname(file)
        
        # Make sure the directory exists
        if not path.isdir(target_dir):
            makedirs(target_dir)
            self.feedback.success('Created path -> {0}'.format(target_dir))
        
    def setup(self, template_id, target_file):
        """
        Select a template to use for further processing.
        """
        if not template_id in self._TEMPLATES:
            self.die('Invalid template ID: {0}'.format(template_id))
        self.feedback.info('Preparing to deploy \'{0}\' template to: {1}'.format(template_id, target_file))
            
        # Set the active template
        self.active = template_id
        self.target = target_file
        
        # Read the template into memory
        fh = open(self._TEMPLATES[template_id], 'r')
        self.contents = fh.read()
        fh.close()
        
    def setvars(self, **kwargs):
        """
        Set template substitution variables.
        """
        for k,v in kwargs.iteritems():
            self.contents.replace('{{{{{0}}}}}'.format(k), v)
            self.feedback.success('Updated template variable \'{0}\'-> {1}'.format(k,v))
            
    def deploy(self, owner='root', mode=644):
        """
        Deploy the template file.
        """
        if path.isfile(self.target):<commit_msg>Caught an error in template.py, updated vars not being written<commit_after>from pwd import getpwnam
from os import path, makedirs, chown, chmod

# NGUtil Libraries
from .common import _NGUtilCommon

class _NGUtilTemplates(_NGUtilCommon):
    """
    Class for handling loading and updating template files.
    """
    def __init__(self):
        super(_NGUtilTemplates, self).__init__()
        
        # Active template / target file
        self.active = None
        self.target = None
        
        # Template contents
        self.contents = None
        
    def _mkpath(self, file):
        """
        Make sure the path to a file exists.
        """
        
        # Target directory
        target_dir = path.dirname(file)
        
        # Make sure the directory exists
        if not path.isdir(target_dir):
            makedirs(target_dir)
            self.feedback.success('Created path -> {0}'.format(target_dir))
        
    def setup(self, template_id, target_file):
        """
        Select a template to use for further processing.
        """
        if not template_id in self._TEMPLATES:
            self.die('Invalid template ID: {0}'.format(template_id))
        self.feedback.info('Preparing to deploy \'{0}\' template to: {1}'.format(template_id, target_file))
            
        # Set the active template
        self.active = template_id
        self.target = target_file
        
        # Read the template into memory
        fh = open(self._TEMPLATES[template_id], 'r')
        self.contents = fh.read()
        fh.close()
        
    def setvars(self, **kwargs):
        """
        Set template substitution variables.
        """
        for k,v in kwargs.iteritems():
            self.contents = self.contents.replace('{{{{{0}}}}}'.format(k), v)
            self.feedback.success('Updated template variable \'{0}\'-> {1}'.format(k,v))
            
    def deploy(self, owner='root', mode=644):
        """
        Deploy the template file.
        """
        if path.isfile(self.target):
{'fraction_non_alphanumeric': 0.1096436581111388, 'fraction_numerical': 0.0049838026414154, 'mean_word_length': 1.9601769911504425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6018299', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1109, 'n_words': 301}