33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
__author__ = 'tyrel'
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
from django.contrib.auth.models import User
|
|
from tracking.models import Track, Point
|
|
from xml.etree import ElementTree
|
|
import os
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Import a gpx file'
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument('username', help="Username to import to.")
|
|
parser.add_argument('filepath', help="File or directory to import a gpx file.")
|
|
|
|
def handle(self, *args, **options):
|
|
username = options['username']
|
|
filepath = options['filepath']
|
|
try:
|
|
user = User.objects.get(username=username)
|
|
except User.DoesNotExist:
|
|
raise CommandError("User %s does not exist" % username)
|
|
|
|
self.stdout.write("Importing for user %s" % user.username)
|
|
|
|
if os.path.isdir(filepath):
|
|
self.stdout("OK, path")
|
|
elif os.path.isfile(filepath):
|
|
self.stdout("OK, file")
|
|
else:
|
|
raise CommandError("{0} is neither an existing file, nor a path.".format(filepath))
|
|
|