Bulk create database records from all csv files found within a directory.

def load_all_csvs_to_model(path, model, field_names=None, delimiter=None, batch_len=10000,
                           dialect=None, num_header_rows=1, mode='rUb',
                           strip=True, clear=False, dry_run=True, ignore_errors=True,
                           sort_files=True, recursive=False, ext='',
                           min_mod_date=None, max_mod_date=None,
                           verbosity=2):
    """Bulk create database records from all csv files found within a directory."""
    if min_mod_date and isinstance(min_mod_date, basestring):
        min_mod_date = parse_date(min_mod_date)
    if isinstance(min_mod_date, datetime.date):
        min_mod_date = datetime.datetime.combine(min_mod_date, datetime.datetime.min.time())

    if max_mod_date and isinstance(max_mod_date, basestring):
        max_mod_date = parse_date(max_mod_date)
    if isinstance(max_mod_date, datetime.date):
        max_mod_date = datetime.datetime.combine(max_mod_date, datetime.datetime.min.time())

    path = path or './'
    batch_len = batch_len or 1000
    if verbosity > 0:
        if dry_run:
            print 'DRY_RUN: actions will not modify the database.'
        else:
            print 'THIS IS NOT A DRY RUN, THESE ACTIONS WILL MODIFY THE DATABASE!!!!!!!!!'

    if clear:
        clear_model(model, dry_run=dry_run, verbosity=verbosity)

    file_dicts = util.find_files(path, ext=ext, level=None if recursive else 0, verbosity=verbosity)
    file_bytes = reduce(lambda a,b: a+b['size'], file_dicts, 0)

    if sort_files:
        file_dicts = sorted(file_dicts, key=itemgetter('path'))
    if verbosity > 1:
        print file_dicts
    if verbosity > 0:
        widgets = [pb.Counter(), '/%d bytes for all files: ' % file_bytes, pb.Percentage(), ' ', pb.RotatingMarker(), ' ', pb.Bar(),' ', pb.ETA()]
        i, pbar = 0, pb.ProgressBar(widgets=widgets, maxval=file_bytes)
        pbar.start()
    N = 0
    file_bytes_done = 0
    for meta in file_dicts:
        if (min_mod_date and meta['modified'] < min_mod_date) or (max_mod_date and meta['modified'] > max_mod_date):
            if verbosity > 1:
                print("Skipping {0} because it's mdate is not between {1} and {2}".format(meta['path'], min_mod_date, max_mod_date))
            continue
        if verbosity > 0:
            print
            print 'Loading "%s"...' % meta['path']
        N += load_csv_to_model(path=meta['path'], model=model, field_names=field_names, delimiter=delimiter, batch_len=batch_len, 
                               dialect=dialect, num_header_rows=num_header_rows, mode=mode,
                               strip=strip, clear=False, dry_run=dry_run, 
                               ignore_errors=ignore_errors, verbosity=verbosity)
        if verbosity > 0:
            file_bytes_done += meta['size']
            pbar.update(file_bytes_done)
    if verbosity > 0:
        pbar.finish()
    return N