diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-11-27 12:21:50 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-11-28 11:40:17 +0100 |
commit | 9020e74bb8b8d49ae739a3215eeaf7861ab85bd4 (patch) | |
tree | ac38225b0ecc3cfff566c2dffafc60be592d022b | |
parent | bba3881e7f11a27ff9d2f08f92542a2d24cac7c6 (diff) | |
download | Ishtar-9020e74bb8b8d49ae739a3215eeaf7861ab85bd4.tar.bz2 Ishtar-9020e74bb8b8d49ae739a3215eeaf7861ab85bd4.zip |
Commands: import management fix
-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): |