Changeset 9182


Ignore:
Timestamp:
May 12, 2011, 8:26:36 AM (14 years ago)
Author:
rick
Message:

Allow importing multiple files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/gheat/management/commands/import_droidstumbler.py

    r9181 r9182  
    100100
    101101class Command(BaseCommand):
    102   args = '<csvfile>[.gz]'
     102  args = '<csvfile>[.gz] [csvfile2[.gz] [csvfile3[.gz] ...] '
    103103  option_list = BaseCommand.option_list + (
    104104    make_option('-m', '--meetrondje', dest='meetrondje', default=None),
     
    110110
    111111  def handle(self, *args, **options):
    112     try:
    113       (csv_file,) = args
    114     except ValueError:
     112    if len(args) == 0:
    115113      self.print_help(sys.argv[0],sys.argv[1])
    116114      raise CommandError("Not all arguments are provided")
    117     if not os.path.isfile(csv_file):
    118       raise CommandError("csv file '%s' does not exists" % csv_file)
    119115
    120     # Meetrondje from filename if needed
    121     if options['meetrondje'] == None:
    122       meetrondje = os.path.basename(csv_file).rstrip('.gz').rstrip('.csv')
    123     else:
    124       meetrondje = options['meetrondje']
    125     # Date from filename if needed
    126     if options['datum'] == None:
    127        datum = os.path.basename(csv_file).lstrip('ScanResult-').rstrip('.csv.gz')
    128     else:
    129        datum = options['datum']
    130     try:
    131        datum = datetime.datetime.strptime(datum,'%Y-%m-%d-%H%M%S')
    132     except ValueError:
    133       raise CommandError("Invalid date '%s'\n" % options['datum'])
     116    for csv_file in args:
     117      # Make sure to check files before we going to do importing at all
     118      if not os.path.isfile(csv_file):
     119        raise CommandError("csv file '%s' does not exists" % csv_file)
     120      self.stdout.write("#INFO: Processing '%s'\n" % csv_file)
    134121
    135     self.stdout.write('#INFO: Meetrondje: %s @ %s\n' % (meetrondje, datum))
    136     self.stdout.write("#INFO: Going to import '%s' for gebruiker '%s <%s>'\n" % (os.path.basename(csv_file), options['gebruiker'], options['email']))
    137     (ap_count, new_ap_count, meting_count, meting_error_count) = import_droidstumbler(csv_file,meetrondje,options['gebruiker'],options['email'], datum, True)
    138     self.stdout.write("#INFO: Import summary accespoints: added:%s processed:%s\n" % (new_ap_count, ap_count))
    139     self.stdout.write("#INFO: Import summary metingen: added:%s error:%s\n" % (meting_count, meting_error_count))
     122      # Meetrondje from filename if needed
     123      if options['meetrondje'] == None:
     124        meetrondje = os.path.basename(csv_file).rstrip('.gz').rstrip('.csv')
     125      else:
     126        meetrondje = options['meetrondje']
     127      # Date from filename if needed
     128      if options['datum'] == None:
     129         datum = os.path.basename(csv_file).lstrip('ScanResult-').rstrip('.csv.gz')
     130      else:
     131         datum = options['datum']
     132      try:
     133         datum = datetime.datetime.strptime(datum,'%Y-%m-%d-%H%M%S')
     134      except ValueError:
     135        raise CommandError("Invalid date '%s'\n" % options['datum'])
     136
     137      self.stdout.write('#INFO: Meetrondje: %s @ %s\n' % (meetrondje, datum))
     138      self.stdout.write("#INFO: Going to import '%s' for gebruiker '%s <%s>'\n" % (os.path.basename(csv_file), options['gebruiker'], options['email']))
     139      (ap_count, new_ap_count, meting_count, meting_error_count) = import_droidstumbler(csv_file,meetrondje,options['gebruiker'],options['email'], datum, True)
     140      self.stdout.write("#INFO: Import summary accespoints: added:%s processed:%s\n" % (new_ap_count, ap_count))
     141      self.stdout.write("#INFO: Import summary metingen: added:%s error:%s\n" % (meting_count, meting_error_count))
Note: See TracChangeset for help on using the changeset viewer.