diff options
Diffstat (limited to 'ishtar_common/management/commands')
| -rw-r--r-- | ishtar_common/management/commands/ishtar_import.py | 38 | 
1 files changed, 38 insertions, 0 deletions
| diff --git a/ishtar_common/management/commands/ishtar_import.py b/ishtar_common/management/commands/ishtar_import.py new file mode 100644 index 000000000..49a7a0e64 --- /dev/null +++ b/ishtar_common/management/commands/ishtar_import.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from django.core.management.base import BaseCommand, CommandError + +from ishtar_common import models + + +class Command(BaseCommand): +    help = "./manage.py ishtar_import <command> <import_id>\n\n"\ +           "Launch the importation a configured import.\n"\ +           "<command> must be: \"analyse\", \"import\" or \"archive\"." + +    def handle(self, *args, **options): +        if not args or len(args) < 2: +            raise CommandError("<command> and <import_id> are mandatory") +        command = args[0] +        if args[0] not in ["analyse", "import", "archive"]: +            raise CommandError( +                "<command> must be: \"analyse\", \"import\" or \"archive\"." +            ) +        try: +            imp = models.Import.objects.get(pk=args[1]) +        except (ValueError, models.Import.DoesNotExist): +            raise CommandError("{} is not a valid import ID".format(args[0])) +        if command == 'analyse': +            imp.initialize() +            self.stdout.write("* {} analysed\n".format(imp)) +            self.stdout.flush() +        elif command == 'import': +            self.stdout.write("* import {}\n".format(imp)) +            imp.importation(output='cli') +            self.stdout.write("* {} imported\n".format(imp)) +            self.stdout.flush() +        elif command == 'archive': +            imp.archive() +            self.stdout.write("*{} archived\n".format(imp)) +            self.stdout.flush() | 
