remove loadmap/dumpmap/checkmap
This commit is contained in:
parent
8b3265e3e9
commit
abec08356e
3 changed files with 0 additions and 106 deletions
|
@ -1,49 +0,0 @@
|
||||||
import os
|
|
||||||
import tempfile
|
|
||||||
|
|
||||||
from django.core.management import call_command
|
|
||||||
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'
|
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
|
||||||
parser.add_argument('--no-prettify', dest='prettify', action='store_const', const=False, default=True,
|
|
||||||
help='ignore formatting errors')
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
|
||||||
print('Creating temporary database for checking…\n')
|
|
||||||
|
|
||||||
_, tmp = tempfile.mkstemp(suffix='.sqlite3', prefix='c3nav-checkmap-')
|
|
||||||
connections.databases['tmpdb'] = {
|
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
|
||||||
'NAME': tmp,
|
|
||||||
}
|
|
||||||
|
|
||||||
# This is not nice, but the easiest way
|
|
||||||
def tmpdb(*args, **kwargs):
|
|
||||||
return 'tmpdb'
|
|
||||||
router.db_for_read = tmpdb
|
|
||||||
router.db_for_write = tmpdb
|
|
||||||
|
|
||||||
try:
|
|
||||||
call_command('migrate', database='tmpdb')
|
|
||||||
|
|
||||||
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,33 +0,0 @@
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
|
||||||
|
|
||||||
from c3nav.mapdata.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='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):
|
|
||||||
writer = MapdataWriter()
|
|
||||||
count = writer.prepare_write_packages(prettify=options['prettify'], diff=options['diff'])
|
|
||||||
|
|
||||||
if options['check_only']:
|
|
||||||
if count:
|
|
||||||
raise CommandError('Check resulted in files to update.')
|
|
||||||
print('Nothing to do.')
|
|
||||||
else:
|
|
||||||
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()
|
|
|
@ -1,24 +0,0 @@
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
|
||||||
from django.db import transaction
|
|
||||||
|
|
||||||
from c3nav.mapdata.lastupdate import set_last_mapdata_update
|
|
||||||
from c3nav.mapdata.packageio import MapdataReader
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
|
||||||
help = 'Load the map package files into the database'
|
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
|
||||||
parser.add_argument('--yes', '-y', action='store_const', const=True, default=False,
|
|
||||||
help='don\'t ask for confirmation')
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
|
||||||
reader = MapdataReader()
|
|
||||||
reader.read_packages()
|
|
||||||
|
|
||||||
with set_last_mapdata_update():
|
|
||||||
with transaction.atomic():
|
|
||||||
reader.apply_to_db()
|
|
||||||
print()
|
|
||||||
if not options['yes'] and input('Confirm (y/N): ') != 'y':
|
|
||||||
raise CommandError('Aborted.')
|
|
Loading…
Add table
Add a link
Reference in a new issue