|
Last change
on this file was 9187, checked in by rick, 15 years ago |
|
... and some way to clean the cache files if needed.
|
-
Property svn:executable
set to
*
|
|
File size:
1.2 KB
|
| Rev | Line | |
|---|
| [9120] | 1 | #!/usr/bin/env python
|
|---|
| [9140] | 2 | # -*- coding: utf-8 -*-
|
|---|
| [9120] | 3 | #
|
|---|
| [9187] | 4 | # Clean/Clear the cached tiles
|
|---|
| [9120] | 5 | #
|
|---|
| [9170] | 6 | # Rick van der Zwet <info@rickvanderzwet.nl>
|
|---|
| [9120] | 7 | #
|
|---|
| [9163] | 8 | from django.core.management.base import BaseCommand, CommandError
|
|---|
| [9120] | 9 | from optparse import OptionParser, make_option
|
|---|
| [9187] | 10 | from gheat.models import TileCache
|
|---|
| [9120] | 11 | import datetime
|
|---|
| [9163] | 12 | import sys
|
|---|
| [9120] | 13 |
|
|---|
| 14 | class Command(BaseCommand):
|
|---|
| 15 | option_list = BaseCommand.option_list + (
|
|---|
| [9187] | 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"""),)
|
|---|
| [9120] | 19 |
|
|---|
| 20 | def handle(self, *args, **options):
|
|---|
| [9187] | 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'])
|
|---|
| [9178] | 33 |
|
|---|
| [9187] | 34 | obj = TileCache.objects.filter(creation_time__range=(datetime.datetime.fromtimestamp(0), datum))
|
|---|
| 35 | print "#INFO: Deleting '%s' objects" % obj.count()
|
|---|
| 36 | obj.delete()
|
|---|
| [9178] | 37 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.