reimplement dumpmap and checkmap
This commit is contained in:
parent
bca976af11
commit
6e65f8b8bd
9 changed files with 158 additions and 120 deletions
|
@ -2,9 +2,12 @@ import os
|
|||
import tempfile
|
||||
|
||||
from django.core.management import call_command
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db import connections, router
|
||||
|
||||
from c3nav.mapdata.packageio.read import MapdataReader
|
||||
from c3nav.mapdata.packageio.write import MapdataWriter
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Check if there are errors in the map package files'
|
||||
|
@ -30,7 +33,17 @@ class Command(BaseCommand):
|
|||
|
||||
try:
|
||||
call_command('migrate', database='tmpdb')
|
||||
call_command('loadmap', yes=True)
|
||||
call_command('dumpmap', prettify=options['prettify'], check_only=True)
|
||||
|
||||
reader = MapdataReader()
|
||||
reader.read_packages()
|
||||
reader.apply_to_db()
|
||||
|
||||
writer = MapdataWriter()
|
||||
count = writer.prepare_write_packages(prettify=options['prettify'], diff=True)
|
||||
|
||||
if count:
|
||||
raise CommandError('%s files affected.' % count)
|
||||
else:
|
||||
print('Everything ok!')
|
||||
finally:
|
||||
os.remove(tmp)
|
||||
|
|
|
@ -1,23 +1,33 @@
|
|||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from ...packageio import write_packages
|
||||
from ...packageio import MapdataWriter
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Dump the map database into the map package files'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--yes', '-y', action='store_const', const=True, default=False,
|
||||
help='don\'t ask for confirmation')
|
||||
parser.add_argument('--no-prettify', dest='prettify', action='store_const', const=False, default=True,
|
||||
help='dont\'t prettify existing files')
|
||||
help='don\'t prettify existing files')
|
||||
parser.add_argument('--diff', action='store_const', const=True, default=False,
|
||||
help='show changes as diff')
|
||||
parser.add_argument('--check-only', action='store_const', const=True, default=False,
|
||||
help='check if there are files to update')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
count = write_packages(prettify=options['prettify'], check_only=options['check_only'])
|
||||
writer = MapdataWriter()
|
||||
count = writer.prepare_write_packages(prettify=options['prettify'], diff=options['diff'])
|
||||
|
||||
if options['check_only']:
|
||||
if count == 0:
|
||||
print('No errors found!')
|
||||
else:
|
||||
raise CommandError('Found errors in %s file(s)' % count)
|
||||
if count:
|
||||
raise CommandError('Check resulted in files to update.')
|
||||
print('Nothing to do.')
|
||||
else:
|
||||
print('%s file(s) affected' % count)
|
||||
if not count:
|
||||
print('Nothing to do.')
|
||||
else:
|
||||
if not options['yes'] and input('Confirm (y/N): ') != 'y':
|
||||
raise CommandError('Aborted.')
|
||||
writer.do_write_packages()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue