<commit_before>    
import sys
    
from cement import namespaces
from cement.core.controller import run_controller_command

def abort(errors):
    if namespaces['root'].config['output_engine'] == 'json':
        run_controller_command('root', 'error_json', errors=errors)
    else:
        run_controller_command('root', 'error', errors=errors)
    sys.exit(1)
    <commit_msg>Moved cement.util to the rosendale project<commit_after>    
import sys
    
from cement import namespaces
from cement.core.controller import run_controller_command

def abort(errors):
    """
    Quick way of aborting a controller command function on errors.  Used as 
    an alternative to simply raising an exception.  Calls the applications
    RootController().error command function which inturn renders the error
    output via Genshi template.
    
    Required Arguments:
    
        errors
            A dictionary of errors.
    
    Exits with a code of '1'.
    
    
    Usage:
    
    .. code-block:: python
    
        from cement.core.controller import CementController, expose
        from cement.core.util import abort
        
        class MyController(CementController):
            @expose('myapp.templates.namespace.mycmd')
            def mycmd(self, cli_opts, cli_args):
                errors = {}
                
                if something:
                    errors['MyErrorDef'] = "Something didn't work out"
                if something_else:
                    errors['MyErrorDef'] = "Something else didn't work out"
                
                if errors:
                    abort(errors)        
                ...
            
    """
    if namespaces['root'].config['output_engine'] == 'json':
        run_controller_command('root', 'error_json', errors=errors)
    else:
        run_controller_command('root', 'error', errors=errors)
    sys.exit(1)
    
{'fraction_non_alphanumeric': 0.08492569002123142, 'fraction_numerical': 0.0015923566878980893, 'mean_word_length': 2.0851063829787235, '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': '3581042', 'n_tokens_mistral': 495, 'n_tokens_neox': 482, 'n_words': 138}