<commit_before>#!/usr/bin/env python
#coding: UTF-8
#
# Copyright (c) 2013 <NAME>
#

from crash import Crash
from analyzer import CrashAnalyzer
import argparse
import os


parser = argparse.ArgumentParser(prog='iCrashalyzer', description='Analyze iOS crash reports.')
parser.add_argument('f', nargs='+', metavar='file', help='file(s) to analyze')
parser.add_argument('-o', '--output', metavar='file', help='write the result to a file instead of stdout')
parser.add_argument('-u', '--unique', action='store_true', help='only output unique crashes')
parser.add_argument('-v', '--verbose', action='count', help='increases the verbosity level')
args = parser.parse_args()


analyzer = CrashAnalyzer()
crashes  = []
curr     = 1
for entry in args.f:
    if os.path.isfile(entry):
        with open(entry, 'r') as file:
            print("[*] processing file %i of %i" % (curr, len(args.f)))
            curr += 1
            crashes.append(analyzer.process(file))
    else:
        print("[!] could not open file %s, skipping" % entry)

if args.unique:
    unique_crashes = []
    for crash in crashes:
        if not crash in unique_crashes:
            unique_crashes.append(crash)
        else:
            print("[*] %s is (likely) a duplicate of %s" % (crash.id, unique_crashes[unique_crashes.index(crash)].id))

    crashes = unique_crashes

if args.verbose:
    Crash.verbosity += args.verbose

out = None
if args.output:
    out = open(args.output, 'w+')

for crash in crashes:
    if out:
        out.write(str(crash))
    else:
        print('\n' + str(crash))

if out:
    out.close()<commit_msg>Added missing newline when outputting to file<commit_after>#!/usr/bin/env python
#coding: UTF-8
#
# Copyright (c) 2013 <NAME>
#

from crash import Crash
from analyzer import CrashAnalyzer
import argparse
import os


parser = argparse.ArgumentParser(prog='iCrashalyzer', description='Analyze iOS crash reports.')
parser.add_argument('f', nargs='+', metavar='file', help='file(s) to analyze')
parser.add_argument('-o', '--output', metavar='file', help='write the result to a file instead of stdout')
parser.add_argument('-u', '--unique', action='store_true', help='only output unique crashes')
parser.add_argument('-v', '--verbose', action='count', help='increases the verbosity level')
args = parser.parse_args()


analyzer = CrashAnalyzer()
crashes  = []
curr     = 1
for entry in args.f:
    if os.path.isfile(entry):
        with open(entry, 'r') as file:
            print("[*] processing file %i of %i" % (curr, len(args.f)))
            curr += 1
            crashes.append(analyzer.process(file))
    else:
        print("[!] could not open file %s, skipping" % entry)

if args.unique:
    unique_crashes = []
    for crash in crashes:
        if not crash in unique_crashes:
            unique_crashes.append(crash)
        else:
            print("[*] %s is (likely) a duplicate of %s" % (crash.id, unique_crashes[unique_crashes.index(crash)].id))

    crashes = unique_crashes

if args.verbose:
    Crash.verbosity += args.verbose

out = None
if args.output:
    out = open(args.output, 'w+')

for crash in crashes:
    if out:
        out.write(str(crash) + '\n')
    else:
        print('\n' + str(crash))

if out:
    out.close()
{'fraction_non_alphanumeric': 0.14739438791242676, 'fraction_numerical': 0.004316990440949738, 'mean_word_length': 3.3485254691689006, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3410530', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1080, 'n_words': 298}