<commit_before># -*- encoding: utf-8 -*-

import fnmatch
import re
import shutil
import os

from datetime import datetime


def rotate(filename, targetdir, max_versions=None, archive_dir=None):
    """ Rotates a file.
        moves original file.ext to targetdir/YYYY-MM-DD-THH:MM:SS-file.ext

        deletes all older files matching the same pattern in targetdir that 
        exceed the amount of max_versions.
        if versions = None, no old versions are deleted.

        if archive_dir is set, old versions are not deleted but moved to
        archive_dir

    """
    dtimeformat = '%Y-%m-%d-%H:%M:%S'

    now = datetime.now().strftime(dtimeformat)
    old_path, old_filename = os.path.split(filename)

    new_filename = now +'-'+ old_filename
    new_filepath = os.path.join(targetdir, new_filename)

    if max_versions:
        # find all files with same pattern that already exist in targetdir
        old_files = {}
        for file in os.listdir(targetdir):
            pattern = re.compile(
                '^(?P<date>\d{4}-\d{2}-\d{2}-\d{2}:\d{2}:\d{2})-%s'
                % old_filename)
            if pattern.match(file):
                d = re.search(pattern, file).group('date')
                old_files[d] = file

        delkeys = old_files.keys()
        # sort delkeys by date, newest first
        delkeys.sort(key=lambda x: datetime.strptime(x, dtimeformat),
            reverse=True)
        
        # delete all keys, that should not be deleted
        del delkeys[0 : max_versions -1]
        
        # delete all not needed files
        for k in delkeys:
            fname = old_files[k]
            fpath = os.path.join(targetdir, fname)

            if archive_dir:
                shutil.move(fpath, os.path.join(archive_dir, fname))
            else:
                os.remove(fpath)


        shutil.move(filename, new_filepath)

        pass
    else:
        shutil.move(filename, new_filepath)

    # print old_path
    # print old_filename
    # print new_filename

    return True<commit_msg>cleanup print statements<commit_after># -*- encoding: utf-8 -*-

import fnmatch
import re
import shutil
import os

from datetime import datetime


def rotate(filename, targetdir, max_versions=None, archive_dir=None):
    """ Rotates a file.
        moves original file.ext to targetdir/YYYY-MM-DD-THH:MM:SS-file.ext

        deletes all older files matching the same pattern in targetdir that 
        exceed the amount of max_versions.
        if versions = None, no old versions are deleted.

        if archive_dir is set, old versions are not deleted but moved to
        archive_dir

    """
    dtimeformat = '%Y-%m-%d-%H:%M:%S'

    now = datetime.now().strftime(dtimeformat)
    old_path, old_filename = os.path.split(filename)

    new_filename = now +'-'+ old_filename
    new_filepath = os.path.join(targetdir, new_filename)

    if max_versions:
        # find all files with same pattern that already exist in targetdir
        old_files = {}
        for file in os.listdir(targetdir):
            pattern = re.compile(
                '^(?P<date>\d{4}-\d{2}-\d{2}-\d{2}:\d{2}:\d{2})-%s'
                % old_filename)
            if pattern.match(file):
                d = re.search(pattern, file).group('date')
                old_files[d] = file

        delkeys = old_files.keys()
        # sort delkeys by date, newest first
        delkeys.sort(key=lambda x: datetime.strptime(x, dtimeformat),
            reverse=True)
        
        # delete all keys, that should not be deleted
        del delkeys[0 : max_versions -1]
        
        # delete all not needed files
        for k in delkeys:
            fname = old_files[k]
            fpath = os.path.join(targetdir, fname)

            if archive_dir:
                shutil.move(fpath, os.path.join(archive_dir, fname))
            else:
                os.remove(fpath)


        shutil.move(filename, new_filepath)

        pass
    else:
        shutil.move(filename, new_filepath)

    return True
    
{'fraction_non_alphanumeric': 0.10054617676266137, 'fraction_numerical': 0.004468718967229395, 'mean_word_length': 2.0569044006069803, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2076046', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1191, 'n_words': 329}