Changeset 9628
- Timestamp:
- Aug 30, 2011, 6:42:43 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/django_gheat/gheat/management/commands/import_datafile.py
r9627 r9628 9 9 # Rick van der Zwet <info@rickvanderzwet.nl> 10 10 # 11 from _mysql_exceptions import OperationalError 11 12 from django.core.management.base import BaseCommand,CommandError 13 from django.db import connection, transaction 12 14 from django.db.utils import IntegrityError 15 from gheat.models import * 13 16 from optparse import OptionParser, make_option 14 from gheat.models import *15 from lxml import etree16 17 import datetime 17 18 import gzip … … 69 70 # Start nagging we cannot parse the entries 70 71 raise CommandError("Invalid date '%s', options: %s" % (datestr, strptime_options)) 72 73 74 def 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 94 organizations = None 95 def 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 71 111 72 112 def import_accespoints(ap_pool, counters):
Note:
See TracChangeset
for help on using the changeset viewer.