Changeset 9173 for src/django_gheat


Ignore:
Timestamp:
May 10, 2011, 1:44:07 PM (14 years ago)
Author:
rick
Message:

Allow compressed kismet files as well as input.

File:
1 edited

Legend:

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

    r9169 r9173  
    99from lxml import etree
    1010import datetime
     11import gzip
    1112import os
    1213import sys
    1314
    1415def import_file(gpsxml_file, netxml_file, meetrondje, gebruiker, email):
    15   gpsxml_doc = etree.parse(gpsxml_file)
    16   netxml_doc = etree.parse(netxml_file)
     16  open_file = lambda file: gzip.open(file,'rb') if file.endswith('.gz') else open(file,'rb')
     17  gpsxml_doc = etree.parse(open_file(gpsxml_file))
     18  netxml_doc = etree.parse(open_file(netxml_file))
    1719
    1820  points = gpsxml_doc.findall('gps-point')
     
    8789
    8890class Command(BaseCommand):
    89   args = '<gpsxml> [<netxml>]'
     91  args = '<gpsxml>[.gz] [<netxml>[.gz]]'
    9092  option_list = BaseCommand.option_list + (
    9193    make_option('-m', '--meetrondje', dest='meetrondje', default='rondje',help='Naam van het meetrondje'),
     
    100102      elif len(args) == 1:
    101103        (gpsxml_file,) = args
    102         netxml_file = gpsxml_file[:-6] + 'netxml'
     104        netxml_file = gpsxml_file.replace('.gpsxml','.netxml')
    103105      else:
    104106        raise ValueError
Note: See TracChangeset for help on using the changeset viewer.