diff options
Diffstat (limited to 'ishtar_common/management/commands/ishtar_import.py')
| -rw-r--r-- | ishtar_common/management/commands/ishtar_import.py | 37 | 
1 files changed, 28 insertions, 9 deletions
| diff --git a/ishtar_common/management/commands/ishtar_import.py b/ishtar_common/management/commands/ishtar_import.py index aba1e45d5..3b04528f0 100644 --- a/ishtar_common/management/commands/ishtar_import.py +++ b/ishtar_common/management/commands/ishtar_import.py @@ -3,22 +3,41 @@  from django.core.management.base import BaseCommand, CommandError -from ishtar_common import models +from ishtar_common import models, models_imports  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\"." +           "<command> must be: \"list\", \"analyse\", \"import\" or " \ +           "\"archive\"." + +    def add_arguments(self, parser): +        parser.add_argument('command', choices=["list", "analyse", "import", +                                                "archive"]) +        parser.add_argument('import_id', nargs='?', default=None)      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\"." -            ) +        command = options['command'] +        import_id = options['import_id'] +        if command != "list" and not import_id: +            raise CommandError("With {} <import_id> is mandatory".format( +                command)) +        if command == 'list': +            state = dict(models_imports.IMPORT_STATE) +            self.stdout.write("*" * 80 + "\n") +            self.stdout.write( +                "|  pk  |               type               |     state    " +                "|        name\n") +            self.stdout.write("*" * 80 + "\n") +            for imp in models.Import.objects.exclude(state="AC").all(): +                self.stdout.write(u"|{: ^6}| {: ^32} | {: ^12} | {}\n".format( +                    imp.pk, unicode(imp.importer_type)[:32], +                    state[imp.state][:12], +                    imp.name[:128])) +            self.stdout.write("*" * 80 + "\n") +            self.stdout.flush() +            return          try:              imp = models.Import.objects.get(pk=args[1])          except (ValueError, models.Import.DoesNotExist): | 
