Ignore:
Timestamp:
Sep 6, 2011, 1:09:58 PM (13 years ago)
Author:
rick
Message:

Harden import such that is survives errors like:

  • Empty files.
  • Invalid XML files.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/gheat/dataimport/__init__.py

    r9664 r9668  
    162162    }
    163163
     164  if os.path.getsize(filename) == 0:
     165    logger.error("Cannot parse empty files")
     166    return counters
     167   
    164168  fh = open_file(filename)
    165   if 'ns1' in filename:
    166     (counters, ap_pool, client_pool, meting_pool) = netstumbler.process_ns1(fh, counters)
    167   elif 'gpsxml' in filename:
    168     (counters, ap_pool, client_pool, meting_pool) = kismet.process_gpsxml(fh, counters)
    169   elif 'netxml' in filename:
    170     (counters, ap_pool, client_pool, meting_pool) = kismet.process_netxml(fh, counters)
    171   elif 'ScanResult' in filename:
    172     (counters, ap_pool, client_pool, meting_pool) = droidstumbler.process_csv(fh, counters)
    173   else:
    174     (ap_pool, client_pool, meting_pool) = (None, None, None)
    175     logger.error("file '%s' format not recognized")
     169  try:
     170    if 'ns1' in filename:
     171      (counters, ap_pool, client_pool, meting_pool) = netstumbler.process_ns1(fh, counters)
     172    elif 'gpsxml' in filename:
     173      (counters, ap_pool, client_pool, meting_pool) = kismet.process_gpsxml(fh, counters)
     174    elif 'netxml' in filename:
     175      (counters, ap_pool, client_pool, meting_pool) = kismet.process_netxml(fh, counters)
     176    elif 'ScanResult' in filename:
     177      (counters, ap_pool, client_pool, meting_pool) = droidstumbler.process_csv(fh, counters)
     178    else:
     179      (ap_pool, client_pool, meting_pool) = (None, None, None)
     180      logger.error("file '%s' format not recognized")
     181  except IOError, e:
     182    logger.error("File invalid: %s", e)
     183    return counters
    176184
    177185  if ap_pool:
Note: See TracChangeset for help on using the changeset viewer.