diff options
Diffstat (limited to 'chimere/management/commands/chimere_import.py')
| -rw-r--r-- | chimere/management/commands/chimere_import.py | 28 | 
1 files changed, 14 insertions, 14 deletions
| diff --git a/chimere/management/commands/chimere_import.py b/chimere/management/commands/chimere_import.py index faddd5e..2f15632 100644 --- a/chimere/management/commands/chimere_import.py +++ b/chimere/management/commands/chimere_import.py @@ -1,8 +1,7 @@  #!/usr/bin/env python  # -*- coding: utf-8 -*- -import csv -import datetime, time +import time  from optparse import make_option  from django.core.management.base import BaseCommand, CommandError @@ -11,18 +10,19 @@ from django.core.exceptions import ObjectDoesNotExist  from chimere.models import Importer  from chimere import tasks +  class Command(BaseCommand):      args = '<import_id>'      help = "Launch import from an external source. Import configuration must "\             "be beforehand inserted in the database with the web admin."      option_list = BaseCommand.option_list + ( -        make_option('--all', +        make_option( +            '--all',              action='store_true',              dest='all',              default=False,              help='Update all imports set to be automatically updated'), -        ) - +    )      def handle(self, *args, **options):          importers = [] @@ -32,26 +32,27 @@ class Command(BaseCommand):              try:                  importers = [Importer.objects.get(pk=int(args[0]))]              except (ValueError, ObjectDoesNotExist): -                raise CommandError("Import with ID '%s' doesn't exist." % \ -                                                                        args[0]) +                raise CommandError( +                    "Import with ID '%s' doesn't exist." % args[0])          else: -            imports = dict([(imp.pk, imp) -                       for imp in Importer.objects.order_by('pk').all()]) +            imports = dict( +                [(imp.pk, imp) +                 for imp in Importer.objects.order_by('pk').all()])              while not importers:                  self.stdout.write('* Choose the import: \n')                  for k in imports: -                    self.stdout.write(' %s\n' % unicode(imports[k]).encode( -                                                             'ascii', 'ignore')) +                    self.stdout.write(' %s\n' % str(imports[k]).encode( +                        'ascii', 'ignore'))                  self.stdout.flush()                  self.stdout.write('\nImport ID: ')                  v = raw_input()                  try:                      importers = [Importer.objects.get(pk=int(v))]                  except (ValueError, ObjectDoesNotExist): -                    self.stdout.write("Import with ID '%s' doesn't exist.\n\n" \ +                    self.stdout.write("Import with ID '%s' doesn't exist.\n\n"                                        % v)          for imprt in importers: -            pending_state = unicode(tasks.IMPORT_MESSAGES['import_pending'][0]) +            pending_state = str(tasks.IMPORT_MESSAGES['import_pending'][0])              imprt.state = pending_state              imprt.save()              tasks.importing(imprt.pk) @@ -62,4 +63,3 @@ class Command(BaseCommand):                  time.sleep(1)                  state = Importer.objects.get(pk=int(imprt.pk)).state              self.stdout.write(state + '\n') - | 
