Esempio n. 1
0
def parse_config():
    config = configparser.ConfigParser()
    config.read('config.ini')

    # Check for required sections.

    if 'General' not in config:
        gen_sec_msg = 'Invalid format for config.ini. Missing "[{0}]" section.'
        fatal_error(gen_sec_msg.format('General'))

    # Check for required keys.

    if 'database_name' not in config['General']:
        gen_key_msg = 'Invalid format for config.ini. Missing key "{0}" under "[{1}]" section.'
        fatal_error(gen_key_msg.format('database_name', 'General'))

    if 'base_directory' not in config['General']:
        gen_key_msg = 'Invalid format for config.ini. Missing key "{0}" under "[{1}]" section.'
        fatal_error(gen_key_msg.format('base_directory', 'General'))

    # Check for invalid values

    if not config['General']['database_name']:
        gen_val_msg = 'Invalid format for config.ini. Invalid value for "{1}" key under "[{2}]" section.'
        fatal_error(gen_val_msg.format('database_name', 'General'))

    return config
Esempio n. 2
0
def parse_config():
    config = configparser.ConfigParser()
    config.read('config.ini')

    # Check for required sections.

    if 'General' not in config:
        gen_sec_msg = 'Invalid format for config.ini. Missing "[{0}]" section.'
        fatal_error(gen_sec_msg.format('General'))

    # Check for required keys.

    if 'database_name' not in config['General']:
        gen_key_msg = 'Invalid format for config.ini. Missing key "{0}" under "[{1}]" section.'
        fatal_error(gen_key_msg.format('database_name', 'General'))

    if 'base_directory' not in config['General']:
        gen_key_msg = 'Invalid format for config.ini. Missing key "{0}" under "[{1}]" section.'
        fatal_error(gen_key_msg.format('base_directory', 'General'))

    # Check for invalid values

    if not config['General']['database_name']:
        gen_val_msg = 'Invalid format for config.ini. Invalid value for "{1}" key under "[{2}]" section.'
        fatal_error(gen_val_msg.format('database_name', 'General'))

    return config
Esempio n. 3
0
def search_file(filepath):
    print('Searching database for {0}'.format(filepath), end='\n\n')

    file_info = None
    try:
        file_info = get_fileinfo(filepath)
    except FileNotFoundError:
        fatal_error('Check file path; Unable to find file at {0}'.format())
    except PermissionError:
        fatal_error('Insufficient permissions to access {0}'.format(filepath))
    except BlockingIOError:
        fatal_error('Unable to access, another process has opened {0}'.format(filepath))

    row = check_file_exists_in_database(4, file_info['hashes']['sha1b32'])

    if row[0] is not '':
        print('\033[94mFile found! See {0}\033[0m'.format(os.path.join(settings.base_directory, row[0])))
        pass
    else:
        print('\033[94mFile not found in database.\033[0m')
Esempio n. 4
0
def search_file(filepath):
    print('Searching database for {0}'.format(filepath), end='\n\n')

    file_info = None
    try:
        file_info = get_fileinfo(filepath)
    except FileNotFoundError:
        fatal_error('Check file path; Unable to find file at {0}'.format())
    except PermissionError:
        fatal_error('Insufficient permissions to access {0}'.format(filepath))
    except BlockingIOError:
        fatal_error('Unable to access, another process has opened {0}'.format(
            filepath))

    row = check_file_exists_in_database(4, file_info['hashes']['sha1b32'])

    if row[0] is not '':
        print('\033[94mFile found! See {0}\033[0m'.format(
            os.path.join(settings.base_directory, row[0])))
        pass
    else:
        print('\033[94mFile not found in database.\033[0m')