2017-11-16 20:54:59 +01:00
|
|
|
import logging
|
2017-11-10 22:50:06 +01:00
|
|
|
import os
|
|
|
|
|
2017-11-10 18:36:16 +01:00
|
|
|
from django.conf import settings
|
2017-07-05 22:42:50 +02:00
|
|
|
from django.core.management.base import BaseCommand
|
2017-11-17 20:09:29 +01:00
|
|
|
from django.db import DatabaseError
|
2022-04-03 16:33:43 +02:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2017-07-05 22:42:50 +02:00
|
|
|
|
2017-11-17 20:09:29 +01:00
|
|
|
from c3nav.mapdata.tasks import process_map_updates
|
|
|
|
|
2017-07-05 22:42:50 +02:00
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = 'clear the mapdata cache'
|
|
|
|
|
2017-11-10 22:50:06 +01:00
|
|
|
def add_arguments(self, parser):
|
|
|
|
parser.add_argument('--include-history', action='store_const', const=True, default=False,
|
|
|
|
help=_('incluce all history as well'))
|
2017-12-23 02:38:18 +01:00
|
|
|
parser.add_argument('--include-geometries', action='store_const', const=True, default=False,
|
|
|
|
help=_('incluce all geometries as well'))
|
2019-12-20 17:44:27 +01:00
|
|
|
parser.add_argument('--no-process', action='store_const', const=True, default=False,
|
|
|
|
help=_('don\'t run processupdates if celery is not setup'))
|
2017-11-10 22:50:06 +01:00
|
|
|
|
2017-07-05 22:42:50 +02:00
|
|
|
def handle(self, *args, **options):
|
|
|
|
from c3nav.mapdata.models import MapUpdate
|
2017-11-16 20:54:59 +01:00
|
|
|
|
|
|
|
logger = logging.getLogger('c3nav')
|
|
|
|
|
2017-12-23 02:38:18 +01:00
|
|
|
MapUpdate.objects.create(type='management', geometries_changed=options['include_geometries'])
|
2017-11-16 20:54:59 +01:00
|
|
|
logger.info('New management update created.')
|
2017-11-10 18:36:16 +01:00
|
|
|
|
2017-11-10 22:50:06 +01:00
|
|
|
if options['include_history']:
|
2017-11-16 20:54:59 +01:00
|
|
|
logger.info('Deleting base history...')
|
2017-11-16 02:26:04 +01:00
|
|
|
for filename in os.listdir(settings.CACHE_ROOT):
|
2017-11-20 17:25:21 +01:00
|
|
|
if filename.startswith('history_base_'):
|
2017-11-16 20:54:59 +01:00
|
|
|
logger.info('Deleting %s...' % filename)
|
2023-11-11 12:06:46 +01:00
|
|
|
os.remove(settings.CACHE_ROOT / filename)
|
2017-11-16 20:54:59 +01:00
|
|
|
logger.info('Base history deleted.')
|
2017-11-10 22:50:06 +01:00
|
|
|
|
2019-12-20 17:44:27 +01:00
|
|
|
if not settings.HAS_CELERY and not options['no_process']:
|
2017-11-17 20:09:29 +01:00
|
|
|
print(_('You don\'t have celery installed, so we will run processupdates now...'))
|
|
|
|
try:
|
|
|
|
process_map_updates()
|
|
|
|
except DatabaseError:
|
|
|
|
logger.error('Didn\'t work, there is already map update processing in progress.')
|
|
|
|
|
2017-11-10 18:36:16 +01:00
|
|
|
if not settings.HAS_REAL_CACHE:
|
|
|
|
print(_('You have no external cache configured, so don\'t forget to restart your c3nav instance!'))
|