예제 #1
0
def validate(manifest_dict, manifest, log_name_source, missing_files_list):
    '''
    Validates the files listed in the checksum manifest.
    '''
    ififuncs.generate_log(
        log_name_source,
        'Validating %s ' % manifest
    )
    error_counter = 0
    manifest_directory = os.path.dirname(manifest)
    os.chdir(manifest_directory)
    error_list = []
    for i in sorted(manifest_dict.keys()):
        print(('Validating %s' % i))
        if 'manifest-sha512.txt' in manifest:
            current_hash = ififuncs.hashlib_sha512(i)
        else:
            current_hash = ififuncs.hashlib_md5(i)
        if current_hash == manifest_dict[i]:
            print(('%s has validated' % i))
        else:
            print(('%s has mismatched checksum - %s expected - %s hashed' % (i, manifest_dict[i], current_hash)))
            ififuncs.generate_log(
                log_name_source,
                '%s has mismatched checksum - %s expected - %s hashed' % (i, manifest_dict[i], current_hash)
            )
            error_list.append('%s has mismatched checksum - %s expected - %s hashed' % (i, manifest_dict[i], current_hash))
            error_counter += 1
    if error_counter > 0:
        print(('\n\n*****ERRORS***********!!!!\n***********\nThe number of mismatched checksums is: %s\n***********\n' % error_counter))
        ififuncs.generate_log(
            log_name_source,
            'The number of mismatched checksums is: %s' % error_counter
        )
        print('***** List of mismatched files*****')
        for i in error_list:
            print(i)
    elif len(missing_files_list) == 0:
        print('All checksums have validated')
        ififuncs.generate_log(
            log_name_source,
            'All checksums have validated'
        )
    if len(missing_files_list) > 0:
        print(('ERRORS - The number of missing files: %s' % len(missing_files_list)))
        ififuncs.generate_log(
            log_name_source,
            'ERRORS - The number of mismatched checksums is: %s' % len(missing_files_list)
        )
        for i in missing_files_list:
            print((('%s is missing') % i))
    return error_counter + len(missing_files_list)
예제 #2
0
파일: validate.py 프로젝트: lsde/IFIscripts
def validate(manifest_dict, manifest, missing_files, log_name_source):
    ififuncs.generate_log(log_name_source, 'Validating %s ' % manifest)
    error_counter = 0
    manifest_directory = os.path.dirname(manifest)
    os.chdir(manifest_directory)
    error_list = []

    for i in sorted(manifest_dict.keys()):
        print 'Validating %s' % i
        if 'manifest-sha512.txt' in manifest:
            current_hash = ififuncs.hashlib_sha512(i)
        else:
            current_hash = hashlib_md5(i)
        if current_hash == manifest_dict[i]:
            print '%s has validated' % i
        else:
            print '%s has mismatched checksum - %s expected - %s hashed' % (
                i, manifest_dict[i], current_hash)
            ififuncs.generate_log(
                log_name_source,
                '%s has mismatched checksum - %s expected - %s hashed' %
                (i, manifest_dict[i], current_hash))
            error_list.append(
                '%s has mismatched checksum - %s expected - %s hashed' %
                (i, manifest_dict[i], current_hash))
            error_counter += 1
    if error_counter > 0:
        print '\n\n*****ERRORS***********!!!!\n***********\nThe number of mismatched checksums is: %s\n***********\n' % error_counter
        ififuncs.generate_log(
            log_name_source,
            'The number of mismatched checksums is: %s' % error_counter)
        print '***** List of mismatched files*****'
        for i in error_list:
            print i
    elif error_counter == 0:
        if missing_files > 0:
            print 'ERRORS - The number of missing files: %s' % missing_files
            ififuncs.generate_log(
                log_name_source,
                'ERRORS - The number of mismatched checksums is: %s' %
                missing_files)

        elif missing_files == 0:
            print 'All checksums have validated'
            ififuncs.generate_log(log_name_source,
                                  'All checksums have validated')
예제 #3
0
def log_results(manifest, log, args):
    '''
    If a sipcreator type log is found,validate will update the log with the
    results.
    '''
    updated_manifest = []
    if 'manifest-sha512.txt' in manifest:
        basename = os.path.basename(manifest).replace('_manifest-sha512.txt',
                                                      '')
    else:
        basename = os.path.basename(manifest).replace('_manifest.md5', '')
    possible_manifests = [
        basename + '_manifest-sha512.txt', basename + '_manifest.md5'
    ]
    logname = basename + '_sip_log.log'
    sip_dir = os.path.join(os.path.dirname(args.input), basename)
    logs_dir = os.path.join(sip_dir, 'logs')
    logfile = os.path.join(logs_dir, logname)
    if os.path.isfile(logfile):
        with open(log, 'r') as fo:
            validate_log = fo.readlines()
        with open(logfile, 'a') as ba:
            for lines in validate_log:
                ba.write(lines)
        for possible_manifest in possible_manifests:
            if os.path.isfile(possible_manifest):
                with open(possible_manifest, 'r') as manifesto:
                    manifest_lines = manifesto.readlines()
                    for lines in manifest_lines:
                        if logname in lines:
                            if 'manifest-sha512.txt' in possible_manifest:
                                lines = lines[:127].replace(
                                    lines[:127],
                                    ififuncs.hashlib_sha512(
                                        logfile)) + lines[128:]
                            elif '_manifest.md5' in possible_manifest:
                                lines = lines[:31].replace(
                                    lines[:31],
                                    ififuncs.hashlib_md5(logfile)) + lines[32:]
                        updated_manifest.append(lines)
                with open(possible_manifest, 'w') as fo:
                    for lines in updated_manifest:
                        fo.write(lines)
                updated_manifest = []