Changeset 9628


Ignore:
Timestamp:
Aug 30, 2011, 6:42:43 PM (13 years ago)
Author:
rick
Message:

Merge forgotten functions from import_droidstumbler.py@9618

File:
1 edited

Legend:

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

    r9627 r9628  
    99# Rick van der Zwet <info@rickvanderzwet.nl>
    1010#
     11from _mysql_exceptions import OperationalError
    1112from django.core.management.base import BaseCommand,CommandError
     13from django.db import connection, transaction
    1214from django.db.utils import IntegrityError
     15from gheat.models import *
    1316from optparse import OptionParser, make_option
    14 from gheat.models import *
    15 from lxml import etree
    1617import datetime
    1718import gzip
     
    6970  # Start nagging we cannot parse the entries
    7071  raise CommandError("Invalid date '%s', options: %s" % (datestr, strptime_options))
     72
     73
     74def bulk_sql(sql_table, sql_values):
     75  """ Awefull hack to ensure we can do mass imports into the DJANGO databases"""
     76  if len(sql_values) == 0:
     77    raise ValueError, "No data to import"
     78
     79  cursor = connection.cursor()
     80  try:
     81    # Make sure the special NULL is preserved
     82    sql = "INSERT INTO %s VALUES %s" % (sql_table, ','.join(sql_values).replace("'NULL'",'NULL'))
     83    count = cursor.execute(sql)
     84    transaction.commit_unless_managed()
     85  except OperationalError, e:
     86    logger.error("%s - %s ", sql_table, sql_values[0])
     87    raise
     88  except IntegrityError, e:
     89    logger.error("Unable to import - %s" %  e)
     90    raise
     91  return count
     92
     93
     94organizations = None
     95def get_organization_id_by_ssid(ssid):
     96  """ Wrapper to return Organization ID of a certain SSID Type
     97  XXX: This should technically be casted into the Organization properly, but
     98  XXX: that properly does not cache properly.
     99  """
     100  global organizations
     101  if not organizations:
     102   organizations = dict(Organization.objects.all().values_list('name','id'))
     103 
     104  name = Organization.get_name_by_ssid(ssid)
     105  if not name:
     106    return 'NULL'
     107  else:
     108    return int(organizations[name])
     109
     110
    71111
    72112def import_accespoints(ap_pool, counters):
Note: See TracChangeset for help on using the changeset viewer.