diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-03-03 16:12:10 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-03-03 16:12:10 +0100 |
commit | b1260f85a40905c60f3ab38e3397230efdb15e4b (patch) | |
tree | 15a333ff68d74ff597b75cc09786831b8f22fdd8 /archaeological_operations/management/commands | |
parent | 7f8e9d5fd945d57b94ba3211ad2503e27858f31e (diff) | |
download | Ishtar-b1260f85a40905c60f3ab38e3397230efdb15e4b.tar.bz2 Ishtar-b1260f85a40905c60f3ab38e3397230efdb15e4b.zip |
Work on DBF imports
Diffstat (limited to 'archaeological_operations/management/commands')
-rwxr-xr-x | archaeological_operations/management/commands/import_operations.py | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/archaeological_operations/management/commands/import_operations.py b/archaeological_operations/management/commands/import_operations.py index b43954e16..cdcbff54b 100755 --- a/archaeological_operations/management/commands/import_operations.py +++ b/archaeological_operations/management/commands/import_operations.py @@ -18,18 +18,37 @@ # See the file COPYING for details. from django.core.management.base import BaseCommand, CommandError -from archaeological_operations.utils import import_from_csv +from archaeological_operations.import_from_csv import import_from_csv +from archaeological_operations.import_from_dbf import import_from_dbf + +IMPORTERS = {'csv':import_from_csv, + 'dbf':import_from_dbf, + 'db3':import_from_dbf, + 'fp':import_from_dbf, + 'vfp':import_from_dbf} class Command(BaseCommand): - args = '<filename> [<update>]' - help = "Import archaelogical operation from a CSV file." + args = '<filename> [<update> <csv|dbf>]' + help = "Import archaelogical operations" def handle(self, *args, **options): if not args or not args[0]: - raise CommandError("No CSV file provided." % args[0]) - nb_ops, errors = import_from_csv(args[0], - update=len(args) > 1 and args[1], - stdout=self.stdout) + raise CommandError("No file provided." % args[0]) + filename = args[0] + update = len(args) > 1 and args[1] + file_type = len(args) > 1 and args[2] + if not file_type: + suffix = filename.split('.')[-1].lower() + if suffix in IMPORTERS.keys(): + file_type = suffix + else: + raise CommandError("This file extension is not managed. "\ + "Specify manualy the file type.") + elif file_type not in IMPORTERS.keys(): + raise CommandError("This file type is not managed.") + nb_ops, errors = IMPORTERS[file_type](filename, + update=update, + stdout=self.stdout) self.stdout.write('\n* %d operation treated\n' % nb_ops) if errors: self.stderr.write('\n'.join(errors)) |