Changeset 9627
- Timestamp:
- Aug 30, 2011, 6:34:39 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/django_gheat/gheat/management/commands/import_datafile.py
r9626 r9627 29 29 logger.setLevel(logging.INFO) 30 30 31 # Open files for reading32 31 def open_file(file): 33 if file.endswith('.gz'): 34 return gzip.open(file,'rb') 35 else: 36 return open(file,'rb') 37 38 # Prefix/Suffix removal 32 """ Open files for reading, unzip if needed """ 33 if file.endswith('.gz'): 34 return gzip.open(file,'rb') 35 else: 36 return open(file,'rb') 37 38 39 39 valid_prefixes = ['DroidStumbler-', 'Kismet-','ScanResult-'] 40 40 def strip_prefix(filename): 41 """ Prefix removal """ 41 42 for prefix in valid_prefixes: 42 43 if filename.startswith(prefix): 43 44 filename = filename[len(prefix):] 44 45 return filename 46 47 45 48 valid_suffixes = ['.gz', '.gpsxml', '.netxml', '.csv', '.ns1'] 46 49 def strip_suffix(filename): 50 """ Suffix removal """ 47 51 for suffix in valid_suffixes: 48 52 if filename.endswith(suffix): 49 53 filename = filename[:-len(suffix)] 50 54 return filename 55 56 51 57 def strip_file(filename): 58 """ Prefix and suffix removal """ 52 59 return strip_suffix(strip_prefix(filename)) 53 60 61 62 #Kismet-20110805-15-37-30-1 63 #ScanResult-2011-05-09-201117 64 strptime_choices = ['%Y%m%d-%H-%M-%S-1', '%Y-%m-%d-%H%M%S'] 65 def process_date(datestr): 66 for strptime in strptime_choices: 67 try: return datetime.datetime.strptime(datestr,strptime) 68 except ValueError: pass 69 # Start nagging we cannot parse the entries 70 raise CommandError("Invalid date '%s', options: %s" % (datestr, strptime_options)) 54 71 55 72 def import_accespoints(ap_pool, counters): … … 146 163 147 164 def handle(self, *args, **options): 148 if options['verbosity'] > 1:165 if options['verbosity'] > 2: 149 166 logger.setLevel(logging.DEBUG) 150 167 if len(args) == 0: … … 167 184 168 185 def get_date(filename): 169 def process_date(datestr):170 try:171 # Kismet-20110805-15-37-30-1172 return datetime.datetime.strptime(datestr,'%Y%m%d-%H-%M-%S-1')173 except ValueError:174 raise CommandError("Invalid date '%s'" % datestr)175 186 if options['datum'] == None: 176 187 datestr = strip_file(os.path.basename(filename))
Note:
See TracChangeset
for help on using the changeset viewer.