diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-11 16:19:59 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-11 16:19:59 +0100 |
commit | 1e05946531d237dc954f46ddfc25a6b61c084a74 (patch) | |
tree | 8b9137dd9b68121db86e4e22dfdb7b7016a6f1ad /ishtar_common/management/commands/ishtar_import.py | |
parent | 4779acd3006e6d6b17babd13585a4d83fb8d2332 (diff) | |
parent | 9eced41d76545bd2921605b7b81bd14b875ce541 (diff) | |
download | Ishtar-1e05946531d237dc954f46ddfc25a6b61c084a74.tar.bz2 Ishtar-1e05946531d237dc954f46ddfc25a6b61c084a74.zip |
Merge branch 'develop'
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): |