<commit_before>__all__ = ('run', 'terminate', 'use_translation', 'load_database', 'break_init', 'set_ui_handler', 'load_menu')

import sys, os, argparse

from pydispatch import dispatcher
import logging
logger = logging.getLogger(__name__)

import cbpos

cbpos.config.set_default('app', 'fullscreen', '')
cbpos.config.set_default('app', 'first_run', '1')
cbpos.config.set_default('app', 'ui_module', 'base')

def parse_args():
    # TODO: Careful!! We are using another version of argparse that does not ship with Python2.7
    # (I think it does with Python3.1) So there is a file called argparse.py
    # You will not be able to run the app without it.
    logger.debug('Parsing arguments. argparse is version ' + argparse.__version__)
    logger.debug('Loaded from ' + argparse.__file__)
    
    cbpos.parser = argparse.ArgumentParser(description=cbpos.description)
    
    cbpos.subparsers = cbpos.parser.add_subparsers(dest='subparser_name')
    
    # Load module-specific command-line arguments
    cbpos.modules.parse_args()
    
    cbpos.args = cbpos.parser.parse_args()
    
    if hasattr(cbpos.args, "handle"):
        ret = cbpos.args.handle(cbpos.args)
        return (ret is None or ret)
    return True

def init_translation(use=True):
    if not use:
        tr_builder = cbpos.DummyTranslatorBuilder()
        
        logger.info("Translation disabled.")
    else:
        localedir = cbpos.config['locale', 'localedir']
        languages = cbpos.config['locale', 'languages']
        fallback = cbpos.config['locale', 'fallback'] == '1'
        codeset = cbpos.config['locale', 'codeset']
        class_ = None # No need for a custom GNUTranslation class
        
        logger.debug("Using [%s](codeset:%s) for translation with fallback=%s in %s" % (languages, codeset, fallback, localedir))
        
        tr_builder = cbpos.TranslatorBuilder(localedir=os.path.abspath(localedir),
                                           languages=None if languages == "" else languages.split(","),
                                           class_=class_,
                                           fallback=fallback,
                                           codeset=codeset)
    
    cbpos.modules.init_translators(tr_builder)
    tr_builder.install()

def terminate():
    try:
        logger.info('Terminating application...')
    except:
        pass

def run():
    """
    Main function to run the application.
    """
    global _ui_handler, _use_translation, _load_database, _load_menu, _break_init
    
    logger.info('Python: %s' % (sys.version,))

    logger.debug('Importing menu...')
    import cbpos.menu

    logger.debug('Importing database...')
    import cbpos.database
<commit_msg>cbpos.terminate() now actually terminates the app, not just cleanup<commit_after>__all__ = ('run', 'terminate', 'use_translation', 'load_database', 'break_init', 'set_ui_handler', 'load_menu')

import sys, os, argparse

from pydispatch import dispatcher
import logging
logger = logging.getLogger(__name__)

import cbpos

cbpos.config.set_default('app', 'fullscreen', '')
cbpos.config.set_default('app', 'first_run', '1')
cbpos.config.set_default('app', 'ui_module', 'base')

def parse_args():
    # TODO: Careful!! We are using another version of argparse that does not ship with Python2.7
    # (I think it does with Python3.1) So there is a file called argparse.py
    # You will not be able to run the app without it.
    logger.debug('Parsing arguments. argparse is version ' + argparse.__version__)
    logger.debug('Loaded from ' + argparse.__file__)
    
    cbpos.parser = argparse.ArgumentParser(description=cbpos.description)
    
    cbpos.subparsers = cbpos.parser.add_subparsers(dest='subparser_name')
    
    # Load module-specific command-line arguments
    cbpos.modules.parse_args()
    
    cbpos.args = cbpos.parser.parse_args()
    
    if hasattr(cbpos.args, "handle"):
        ret = cbpos.args.handle(cbpos.args)
        return (ret is None or ret)
    return True

def init_translation(use=True):
    if not use:
        tr_builder = cbpos.DummyTranslatorBuilder()
        
        logger.info("Translation disabled.")
    else:
        localedir = cbpos.config['locale', 'localedir']
        languages = cbpos.config['locale', 'languages']
        fallback = cbpos.config['locale', 'fallback'] == '1'
        codeset = cbpos.config['locale', 'codeset']
        class_ = None # No need for a custom GNUTranslation class
        
        logger.debug("Using [%s](codeset:%s) for translation with fallback=%s in %s" % (languages, codeset, fallback, localedir))
        
        tr_builder = cbpos.TranslatorBuilder(localedir=os.path.abspath(localedir),
                                           languages=None if languages == "" else languages.split(","),
                                           class_=class_,
                                           fallback=fallback,
                                           codeset=codeset)
    
    cbpos.modules.init_translators(tr_builder)
    tr_builder.install()

def terminate(retcode=1):
    try:
        logger.info('Terminating application...')
    except:
        pass
    return sys.exit(retcode)

def run():
    """
    Main function to run the application.
    """
    global _ui_handler, _use_translation, _load_database, _load_menu, _break_init
    
    logger.info('Python: %s' % (sys.version,))

    logger.debug('Importing menu...')
    import cbpos.menu

    logger.debug('Importing database...')
    import cbpos.database

{'fraction_non_alphanumeric': 0.11432706222865413, 'fraction_numerical': 0.0023516642547033286, 'mean_word_length': 2.6786427145708585, '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': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1011323', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1604, 'n_words': 394}