summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2015-12-23 07:49:59 +0100
committerÉtienne Loks <etienne.loks@proxience.com>2015-12-23 07:49:59 +0100
commit629a414f87da47641653394232ebc08c72299d11 (patch)
treee897222f388d40684c5951b5f2bff2edca0adc37 /ishtar_common
parent25a9131ac22ab0167f83e0ad6ce62e756e37850f (diff)
downloadIshtar-629a414f87da47641653394232ebc08c72299d11.tar.bz2
Ishtar-629a414f87da47641653394232ebc08c72299d11.zip
Custom command to manage imports with CLI
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/management/commands/ishtar_import.py38
-rw-r--r--ishtar_common/models.py4
2 files changed, 40 insertions, 2 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()
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 20b8a6f46..c657f532d 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -1690,8 +1690,8 @@ class Import(models.Model):
verbose_name_plural = _(u"Imports")
def __unicode__(self):
- return u"%s - %s" % (unicode(self.importer_type),
- unicode(self.user))
+ return u"%s - %s - %d" % (unicode(self.importer_type),
+ unicode(self.user), self.pk)
def need_matching(self):
return bool(TargetKey.objects.filter(associated_import=self,