# Path: eve_db/ccp_importer/bulkops.py
# def insert_many(objects, using="default"):
#     """Insert list of Django objects in one SQL query. Objects must be
#     of the same Django model. Note that save is not called and signals
#     on the model are not raised."""
#     if not objects:
#         return
# 
#     import django.db.models
#     from django.db import connections
#     con = connections[using]
#     
#     model = objects[0].__class__
#     fields = [f for f in model._meta.fields if not isinstance(f, django.db.models.AutoField)]
#     parameters = []
#     for o in objects:
#         parameters.append(tuple(f.get_db_prep_save(f.pre_save(o, True), connection=con) for f in fields))
#     table = model._meta.db_table
#     column_names = ",".join(con.ops.quote_name(f.column) for f in fields)
#     placeholders = ",".join(("%s",) * len(fields))
#     con.cursor().executemany(
#         "insert into %s (%s) values (%s)" % (table, column_names, placeholders),
#         parameters)
# 
# def update_many(objects, fields=[], using="default"):
#     """Update list of Django objects in one SQL query, optionally only
#     overwrite the given fields (as names, e.g. fields=["foo"]).
#     Objects must be of the same Django model. Note that save is not
#     called and signals on the model are not raised."""
#     if not objects:
#         return
# 
#     import django.db.models
#     from django.db import connections
#     con = connections[using]
# 
#     names = fields
#     meta = objects[0]._meta
#     fields = [f for f in meta.fields if not isinstance(f, django.db.models.AutoField) and (not names or f.name in names)]
# 
#     if not fields:
#         raise ValueError("No fields to update, field names are %s." % names)
#     
#     fields_with_pk = fields + [meta.pk]
#     parameters = []
#     for o in objects:
#         parameters.append(tuple(f.get_db_prep_save(f.pre_save(o, True), connection=con) for f in fields_with_pk))
# 
#     table = meta.db_table
#     assignments = ",".join(("%s=%%s"% con.ops.quote_name(f.column)) for f in fields)
#     con.cursor().executemany(
#         "update %s set %s where %s=%%s" % (table, assignments, meta.pk.column),
#         parameters)


from progressbar import ProgressBar, Percentage, Bar, ETA
from django import db
from django.db import transaction
from django.conf import settings
from eve_db.ccp_importer.bulkops import insert_many, update_many
        query_string = 'SELECT * FROM %s' % self.table_name

        try:
            for new_obj, insert in (self.import_row(row) for row in self.cursor.execute(query_string)):
                # Now we have either a new model instance, an existing model
                # instance with updated fields or None == skip
                if new_obj:
                    if insert:
                        inserts_bucket.append(new_obj)
                        inserts_counter += 1
                        if inserts_counter % batch_size == 0:
                            insert_many(inserts_bucket)
                            inserts_bucket = []
                    else:
                        updates_bucket.append(new_obj)
                        updates_counter += 1
                        if updates_counter % batch_size == 0:
                            update_many(updates_bucket)
                            updates_bucket = []

                if self.itercount % self.progress_update_interval == 0:
                    self._progress_handler()

                self.itercount += 1

    #                if settings.DEBUG:
    #                    db.reset_queries()
            if len(inserts_bucket) > 0:
                insert_many(inserts_bucket)
            if len(updates_bucket) > 0:

# Path: eve_db/ccp_importer/bulkops.py
# def insert_many(objects, using="default"):
#     """Insert list of Django objects in one SQL query. Objects must be
#     of the same Django model. Note that save is not called and signals
#     on the model are not raised."""
#     if not objects:
#         return
# 
#     import django.db.models
#     from django.db import connections
#     con = connections[using]
#     
#     model = objects[0].__class__
#     fields = [f for f in model._meta.fields if not isinstance(f, django.db.models.AutoField)]
#     parameters = []
#     for o in objects:
#         parameters.append(tuple(f.get_db_prep_save(f.pre_save(o, True), connection=con) for f in fields))
#     table = model._meta.db_table
#     column_names = ",".join(con.ops.quote_name(f.column) for f in fields)
#     placeholders = ",".join(("%s",) * len(fields))
#     con.cursor().executemany(
#         "insert into %s (%s) values (%s)" % (table, column_names, placeholders),
#         parameters)
# 
# def update_many(objects, fields=[], using="default"):
#     """Update list of Django objects in one SQL query, optionally only
#     overwrite the given fields (as names, e.g. fields=["foo"]).
#     Objects must be of the same Django model. Note that save is not
#     called and signals on the model are not raised."""
#     if not objects:
#         return
# 
#     import django.db.models
#     from django.db import connections
#     con = connections[using]
# 
#     names = fields
#     meta = objects[0]._meta
#     fields = [f for f in meta.fields if not isinstance(f, django.db.models.AutoField) and (not names or f.name in names)]
# 
#     if not fields:
#         raise ValueError("No fields to update, field names are %s." % names)
#     
#     fields_with_pk = fields + [meta.pk]
#     parameters = []
#     for o in objects:
#         parameters.append(tuple(f.get_db_prep_save(f.pre_save(o, True), connection=con) for f in fields_with_pk))
# 
#     table = meta.db_table
#     assignments = ",".join(("%s=%%s"% con.ops.quote_name(f.column)) for f in fields)
#     con.cursor().executemany(
#         "update %s set %s where %s=%%s" % (table, assignments, meta.pk.column),
#         parameters)


# Path: eve_db/ccp_importer/importers/importer_classes.py
from progressbar import ProgressBar, Percentage, Bar, ETA
from django import db
from django.db import transaction
from django.conf import settings
from eve_db.ccp_importer.bulkops import insert_many, update_many

        query_string = 'SELECT * FROM %s' % self.table_name

        try:
            for new_obj, insert in (self.import_row(row) for row in self.cursor.execute(query_string)):
                # Now we have either a new model instance, an existing model
                # instance with updated fields or None == skip
                if new_obj:
                    if insert:
                        inserts_bucket.append(new_obj)
                        inserts_counter += 1
                        if inserts_counter % batch_size == 0:
                            insert_many(inserts_bucket)
                            inserts_bucket = []
                    else:
                        updates_bucket.append(new_obj)
                        updates_counter += 1
                        if updates_counter % batch_size == 0:
                            update_many(updates_bucket)
                            updates_bucket = []

                if self.itercount % self.progress_update_interval == 0:
                    self._progress_handler()

                self.itercount += 1

    #                if settings.DEBUG:
    #                    db.reset_queries()
            if len(inserts_bucket) > 0:
                insert_many(inserts_bucket)
            if len(updates_bucket) > 0:

                update_many(updates_bucket)