<commit_before>#!/usr/bin/env python
"""This script scans for apparently unused files in the upload path
and deletes them.

'unused files' are considered to be ones for which the atime is older
than 14 days (see ATIME_DEFAULT)
"""

import os
import logging
import subprocess
import sys
from optparse import OptionParser

from path import path

from pynpact import capproc
from npactweb import library_root


logger = logging.getLogger('cleanup')



def clean(path, days, verbose=False):
    "This function actually runs the find and delete."
    logger.info("Cleaning older than: %d @ %r", days, path)

    if verbose:
        #add the -v flag to rm so it prints removed files.
        cmd=["find", path, "-atime", "+" + str(days),
             "-exec", "rm", "-f", "-v", "{}", "+"]
    else:
        cmd=["find", path, "-atime", "+" + str(days),
             "-exec", "rm", "-f", "{}", "+"]
    return capproc.capturedCall(cmd, logger=logger, stdin=False, stderr_level=logging.WARNING)


if __name__ == '__main__' :
    #make sure django settings is setup; used for the path source and logging config
    if 'DJANGO_SETTINGS_MODULE' not in os.environ:<commit_msg>Improve cleanup.py so that it will delete the prediction directories intelligently.<commit_after>#!/usr/bin/env python
"""This script scans for apparently unused files in the upload path
and deletes them.

'unused files' are considered to be ones for which the atime is older
than 14 days (see ATIME_DEFAULT)
"""

import os
import logging
import subprocess
import sys
from optparse import OptionParser

from path import path

from pynpact import capproc
from npactweb import library_root


logger = logging.getLogger('cleanup')



def clean(path, days, verbose=False):
    "This function actually runs the find and delete."
    logger.info("Cleaning older than: %d @ %r", days, path)

    cmd=["find", path, "-atime", "+" + str(days), "-delete"]
    return capproc.capturedCall(cmd, logger=logger, stdin=False, stderr_level=logging.WARNING)


if __name__ == '__main__' :
    #make sure django settings is setup; used for the path source and logging config
    if 'DJANGO_SETTINGS_MODULE' not in os.environ:
{'fraction_non_alphanumeric': 0.10967741935483871, 'fraction_numerical': 0.0018433179723502304, 'mean_word_length': 4.002304147465438, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6917219', 'n_tokens_mistral': 663, 'n_tokens_neox': 645, 'n_words': 255}