<commit_before># -*- coding: utf-8 -*-
u"""?

:copyright: Copyright (c) 2017 RadiaSoft LLC.  All Rights Reserved.
:license: http://www.apache.org/licenses/LICENSE-2.0.html
"""
from __future__ import absolute_import, division, print_function


def purge_users(days=180, dry_run=True):
    """Remove old users from db which have not registered.

    Args:
        days (int): maximum days of untouched files (old is mtime > days)
        dry_run (bool): delete the directories if false (else don't delete) [True]

    Returns:
        list: directories removed (or to remove if dry_run)
    """
    from pykern import pkio
    from sirepo import server
    from sirepo import simulation_db
    import datetime

    days = int(days)
    assert days >= 1, \
        '{}: days must be a positive integer'
    server.init()
    uids = server.all_uids()
    now = datetime.datetime.utcnow()
    to_remove = []
    for d in pkio.sorted_glob(simulation_db.user_dir_name('*')):
        if simulation_db.uid_from_dir_name(d) in uids:
            continue
        for f in pkio.walk_tree(d):
            if (now - now.fromtimestamp(f.mtime())).days <= days:
                break
        else:
            to_remove.append(d)
    if not dry_run:
        for d in to_remove:
            pkio.unchecked_remove(*to_remove)
    return to_remove<commit_msg>See #756: unnecessary loop in unchecked_remove<commit_after># -*- coding: utf-8 -*-
u"""?

:copyright: Copyright (c) 2017 RadiaSoft LLC.  All Rights Reserved.
:license: http://www.apache.org/licenses/LICENSE-2.0.html
"""
from __future__ import absolute_import, division, print_function


def purge_users(days=180, dry_run=True):
    """Remove old users from db which have not registered.

    Args:
        days (int): maximum days of untouched files (old is mtime > days)
        dry_run (bool): delete the directories if false (else don't delete) [True]

    Returns:
        list: directories removed (or to remove if dry_run)
    """
    from pykern import pkio
    from sirepo import server
    from sirepo import simulation_db
    import datetime

    days = int(days)
    assert days >= 1, \
        '{}: days must be a positive integer'
    server.init()
    uids = server.all_uids()
    now = datetime.datetime.utcnow()
    to_remove = []
    for d in pkio.sorted_glob(simulation_db.user_dir_name('*')):
        if simulation_db.uid_from_dir_name(d) in uids:
            continue
        for f in pkio.walk_tree(d):
            if (now - now.fromtimestamp(f.mtime())).days <= days:
                break
        else:
            to_remove.append(d)
    if not dry_run:
        pkio.unchecked_remove(*to_remove)
    return to_remove
{'fraction_non_alphanumeric': 0.1040656471465871, 'fraction_numerical': 0.009324878776575904, 'mean_word_length': 2.6243243243243244, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6776108', 'n_tokens_mistral': 868, 'n_tokens_neox': 827, 'n_words': 252}