outerjoin(MasterFinders).count()))
    logging.info('{} records with object_name IS NULL in master_images LEFT JOIN master_finders'.\
        format(session.query(MasterImages, MasterFinders).\
            outerjoin(MasterFinders).\
            filter(MasterFinders.object_name == None).count()))

    # Log the missing master_finders records
    master_finders_query = session.query(MasterImages, MasterFinders).\
            outerjoin(MasterFinders).\
            filter(MasterFinders.object_name == None).all()
    if len(master_finders_query) != 0:
        for record in master_finders_query:
            logging.error('No object_name value for {}'.\
                format(os.path.join(record.MasterImages.file_location,
                    record.MasterImages.name)))

    # Keeping this in case I need it in the future. Sorry for the mess!
    # for record in master_images_query:
    #   target_name = get_target_name(record)
    #   master_finders_count = session.query(MasterFinders).\
    #       filter(MasterFinders.master_images_id == record.id).count()
    #   if master_finders_count != MOONS_PER_PLANET_DICT[target_name]:
    #       logging.error('Expected {} moons for {} got {}'.\
    #           format(MOONS_PER_PLANET_DICT[target_name], 
    #               os.path.join(record.file_location, record.name), 
    #               master_finders_count))

if __name__ == '__main__':
    setup_logging('check_database_completeness')
    check_database_completeness_main()
            session.commit()
    session.close()

#----------------------------------------------------------------------------
# For command line execution
#----------------------------------------------------------------------------

def parse_args():
    '''
    parse the command line arguemnts.
    '''
    parser = argparse.ArgumentParser(
        description = 'Generate the ephemeride data.')
    parser.add_argument(
        '-reproc',
        required = False,
        action = 'store_true',        
        default = False,
        dest = 'reproc',
        help = 'Overwrite existing entries.')
    args = parser.parse_args()
    return args

#----------------------------------------------------------------------------

if __name__ == '__main__':
    args = parse_args()
    setup_logging('build_master_finders_table')
    logging.info('Host: {0}'.format(gethostname())) 
    run_ephem_main(args.reproc)
        '-reproc',
        required = False,
        action = 'store_true',        
        default = False,
        dest = 'reproc',
        help = 'Overwrite existing entries.')
    args = parser.parse_args()
    return args

#----------------------------------------------------------------------------
    
if __name__ == '__main__':
    
    # Set up the inputs and logging.
    args = parse_args()
    setup_logging('jpl2db')
   
    # Log the system and user information.
    logging.info('User: {0}'.format(getuser()))
    logging.info('Host: {0}'.format(gethostname())) 
    logging.info('Machine: {0}'.format(machine()))
    logging.info('Platform: {0}'.format(platform()))
    logging.info("Command-line arguments used:")
    for arg in args.__dict__:
        logging.info(arg + ": " + str(args.__dict__[arg]))

    # Create the filelist.
    if args.filelist != None:
        filelist = glob.glob(args.filelist)
        filelist = [x for x in filelist if len(os.path.basename(x)) == 18]
        assert isinstance(filelist, list), \