From b32db39c58b45bd655875f3165015ab9d5cee6a0 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 27 Nov 2018 12:21:50 +0100 Subject: Commands: import management fix --- ishtar_common/management/commands/ishtar_import.py | 37 ++++++++++++++++------ 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'ishtar_common/management') 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 \n\n"\ "Launch the importation a configured import.\n"\ - " must be: \"analyse\", \"import\" or \"archive\"." + " 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(" and are mandatory") - command = args[0] - if args[0] not in ["analyse", "import", "archive"]: - raise CommandError( - " must be: \"analyse\", \"import\" or \"archive\"." - ) + command = options['command'] + import_id = options['import_id'] + if command != "list" and not import_id: + raise CommandError("With {} 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): -- cgit v1.2.3