Created
June 9, 2010 02:34
-
-
Save djsutherland/430962 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.management.base import NoArgsCommand | |
from gazjango.misc.management.commands.backup_db import DUMP_DIRECTORY, DUMP_PATTERN | |
import os, re | |
DUMP_MATCHER = re.compile(r"^%s$" % re.sub(r'\\%[a-zA-Z]', | |
r'.+', | |
re.escape(DUMP_PATTERN))) | |
NUM_TO_SAVE = 8 | |
class Command(NoArgsCommand): | |
def handle_noargs(self, **options): | |
dumps = [f for f in os.listdir(DUMP_DIRECTORY) if DUMP_MATCHER.match(f)] | |
dumps.sort(reverse=True) | |
for f in dumps[NUM_TO_SAVE:]: | |
if options['verbosity'] == 2: | |
print "removing %s" % f | |
os.remove(os.path.join(DUMP_DIRECTORY, f)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment