summaryrefslogtreecommitdiff
path: root/archaeological_operations/management/commands/import_operations.py
diff options
context:
space:
mode:
authorroot <root@viserion.(none)>2013-03-07 19:57:25 +0000
committerroot <root@viserion.(none)>2013-03-07 19:57:25 +0000
commitb4141b9ccaf86857133903522af68e339bc6f3f3 (patch)
tree78cac7cc354e95a53e8338f22dc9c46b3c70a0b2 /archaeological_operations/management/commands/import_operations.py
parent84cdbef78b30697b8babb00978984712f81e8120 (diff)
parent4fb8a816f1eeb7074d669bbf8716e480f298a414 (diff)
downloadIshtar-b4141b9ccaf86857133903522af68e339bc6f3f3.tar.bz2
Ishtar-b4141b9ccaf86857133903522af68e339bc6f3f3.zip
Merge branch 'master' of lysithea.proxience.net:/home/proxience/git/ishtar
Diffstat (limited to 'archaeological_operations/management/commands/import_operations.py')
-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))