'The number of histories that were deleted more than the specified number of days ago, but have not yet been purged.
Also included is the number of datasets associated with the histories.'

def deleted_histories(self, trans, **kwd):

    params = util.Params(kwd)
    message = ''
    if params.deleted_histories_days:
        deleted_histories_days = int(params.deleted_histories_days)
        cutoff_time = (datetime.utcnow() - timedelta(days=deleted_histories_days))
        history_count = 0
        dataset_count = 0
        disk_space = 0
        histories = trans.sa_session.query(model.History).filter(and_((model.History.table.c.deleted == true()), (model.History.table.c.purged == false()), (model.History.table.c.update_time < cutoff_time))).options(eagerload('datasets'))
        for history in histories:
            for hda in history.datasets:
                if (not hda.dataset.purged):
                    dataset_count += 1
                    try:
                        disk_space += hda.dataset.file_size
                    except:
                        pass
            history_count += 1
        message = ('%d    histories    (    including    a    total    of    %d    datasets    )    were    deleted    more    than    %d    days    ago,    but    have    not    yet    been    purged,    disk    space:    %s.' % (history_count, dataset_count, deleted_histories_days, nice_size(disk_space, True)))
    else:
        message = 'Enter    the    number    of    days.'
    return (str(deleted_histories_days), message)
