Example #1
0
def score_log_from_contents(contents):
    """Score a log file given its contents, instead of opening it from a file."""
    log = LogFile(contents.split('\n'))
    try:
        log = score_wrapper(log)
    except UnicodeDecodeError:
        log.unrecognized = 'Could not decode log file.'
    return log.to_dict()
Example #2
0
def translate_log_from_contents(contents):
    """Translate a log file given its contents."""
    log = LogFile(contents.split('\n'))
    try:
        return translate_wrapper(log)
    except UnicodeDecodeError:
        return {'unrecognized': 'Could not decode log'}
Example #3
0
def split_combined(log):
    """Split a combined log into an array of logs. If there is a single
    log, return a list with one log inside it. Not relevant for XLD.
    """
    logs = []

    # Create a list of indices for combined log markers. By default # includes indices 0 and len()
    log_indices = ([0] + [
        i + 2 for i, line in enumerate(log.full_contents)
        if re.match(r'-{60}', line)
    ] + [len(log.full_contents)])

    # Split the log files. Create new log object for each log.
    for i, line in enumerate(log_indices):
        new_log = LogFile(log.full_contents[line:(log_indices[i + 1])],
                          ripper=log.ripper)

        for prop in ['check_checksum', 'no_sub_zero']:
            setattr(new_log, prop, getattr(log, prop))

        logs.append(new_log)

        # Return the array of logs if the end index of section is
        # equivalent to the length of the original log.
        if log_indices[i + 1] == max(log_indices):
            break

    return logs
Example #4
0
def translate_log(log_file):
    """Initialize and capture all logs."""
    try:
        contents = get_log_contents(log_file)
        log = LogFile(contents)
        return translate_wrapper(log)
    except UnicodeDecodeError:
        return {'unrecognized': 'Could not decode log'}
Example #5
0
def score_log(log_file, args):
    try:
        contents = get_log_contents(log_file)
        log = LogFile(contents)
        log.check_checksum = args.check_checksum
        log.no_sub_zero = args.no_sub_zero
        log = score_wrapper(log, args.markup)
    except UnicodeDecodeError:
        log = LogFile('')
        log.unrecognized = 'Could not decode log file.'
    return log.to_dict()
Example #6
0
def score_log(log_file, markup=False):
    try:
        contents = get_log_contents(log_file)
        log = LogFile(contents)
        log = score_wrapper(log, markup)
    except UnicodeDecodeError:
        log = LogFile('')
        log.unrecognized = 'Could not decode log file.'
    return log.to_dict()