source: src/django_gheat/gheat/management/commands/clear_tile_cache.py@ 9823

Last change on this file since 9823 was 9187, checked in by rick, 14 years ago

... and some way to clean the cache files if needed.

  • Property svn:executable set to *
File size: 1.2 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Clean/Clear the cached tiles
5#
6# Rick van der Zwet <info@rickvanderzwet.nl>
7#
8from django.core.management.base import BaseCommand, CommandError
9from optparse import OptionParser, make_option
10from gheat.models import TileCache
11import datetime
12import sys
13
14class Command(BaseCommand):
15 option_list = BaseCommand.option_list + (
16 make_option('-d', '--datum', dest='datum', default=None, help="""Provide date
17 in following format: %Y-%m-%d[-%H%M], to delete all time generated before
18 this time the filename"""),)
19
20 def handle(self, *args, **options):
21 if options['datum'] == None:
22 datum = datetime.datetime.now()
23 else:
24 # Try parsing different formats
25 for fmt in ['%Y-%m-%d-%H%M', '%Y-%m-%d']:
26 try:
27 datum = datetime.datetime.strptime(options['datum'],fmt)
28 break
29 except ValueError:
30 datum = None
31 if not datum:
32 raise CommandError("Invalid date '%s'\n" % options['datum'])
33
34 obj = TileCache.objects.filter(creation_time__range=(datetime.datetime.fromtimestamp(0), datum))
35 print "#INFO: Deleting '%s' objects" % obj.count()
36 obj.delete()
37
Note: See TracBrowser for help on using the repository browser.