summaryrefslogtreecommitdiff
path: root/archaeological_operations/management/commands
diff options
context:
space:
mode:
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
commitef51425037b9da9ecf2c80a94188bebebe9c6da1 (patch)
tree15a333ff68d74ff597b75cc09786831b8f22fdd8 /archaeological_operations/management/commands
parent48041d8a27859dc82a634fecf2ed8249c6eb539a (diff)
downloadIshtar-ef51425037b9da9ecf2c80a94188bebebe9c6da1.tar.bz2
Ishtar-ef51425037b9da9ecf2c80a94188bebebe9c6da1.zip
Work on DBF imports
Diffstat (limited to 'archaeological_operations/management/commands')
-rwxr-xr-xarchaeological_operations/management/commands/import_operations.py33
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))