Changeset 9668 for src/django_gheat


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.
Location:
src/django_gheat/gheat/dataimport
Files:
2 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:
  • src/django_gheat/gheat/dataimport/kismet.py

    r9640 r9668  
    1212
    1313def process_netxml(fh,counters):
    14   netxml_doc = etree.parse(fh)
     14  try:
     15    netxml_doc = etree.parse(fh)
     16  except etree.XMLSyntaxError, e:
     17    raise IOError(e)
    1518
    1619  # Prepare new accespoints and measurements
     
    4548
    4649def process_gpsxml(fh,counters):
    47   gpsxml_doc = etree.parse(fh)
     50  try:
     51    gpsxml_doc = etree.parse(fh)
     52  except etree.XMLSyntaxError, e:
     53    raise IOError(e)
    4854
    4955  bssid_failed = defaultdict(int)
Note: See TracChangeset for help on using the changeset viewer.