<commit_before>import os, sys

from twisted.python import usage
from twisted.internet import defer, reactor

from renamer import application, logging



def main():
    def _run():
        d = defer.maybeDeferred(r.run)
        d.addErrback(logging.err)
        d.addBoth(lambda ignored: reactor.stop())
        return d

    try:
        r = application.Renamer()
    except usage.UsageError, e:
        prog = os.path.basename(sys.argv[0])
        print '%s: %s' % (prog, e)
        print '%s: Consult --help for usage details' % (prog)
        sys.exit(1)
    else:
        reactor.callWhenRunning(_run)
        reactor.run()<commit_msg>Rework renamer.main.<commit_after>import os, sys

from twisted.python import usage
from twisted.internet import defer, reactor

from renamer import application, logging



def main():
    status = 0

    def logError(f):
        logging.err(f)
        global status
        status = 1

    def usageError(f):
        f.trap(usage.UsageError)
        prog = os.path.basename(sys.argv[0])
        sys.stderr.write('%s: %s\n' % (prog, f.value))
        sys.stderr.write('Consult --help for usage information\n')
        global status
        status = 1

    def run():
        d = defer.maybeDeferred(application.Renamer)
        d.addCallback(lambda r: r.run())
        d.addErrback(usageError)
        d.addErrback(logError)
        d.addBoth(lambda ign: reactor.stop())

    reactor.callWhenRunning(run)
    reactor.run()
    sys.exit(status)
{'fraction_non_alphanumeric': 0.11605937921727395, 'fraction_numerical': 0.004048582995951417, 'mean_word_length': 2.4249422632794455, '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': '6294527', 'n_tokens_mistral': 490, 'n_tokens_neox': 459, 'n_words': 115}