示例#1
0
def run_importers(importer_classes, sqlite_file, include_deps=False):
    """
    importer_classes: (list) References to the importer classes to run.
    sqlite_file: (str) Path to the SQLite file to import from.
    """
    # Create the SQLite connection object.
    conn = sqlite3.connect(sqlite_file)
    # Ignore characters that can't be decoded from UTF-8.
    conn.text_factory = lambda x: unicode(x, "utf-8", "ignore")
    conn.row_factory = sqlite3.Row

    if include_deps:
        add_dependencies(importer_classes)

    ordered_importers = order_importers(importer_classes)

    # Timestamp of when the imports started.
    time_started = datetime.datetime.now()

    # Carry out the imports in order.
    for importer_class in ordered_importers:
        importer = importer_class()
        importer.prep_and_run_importer(conn)

    # Print the total time, for the ricers.
    time_elapsed = datetime.datetime.now() - time_started
    hours = time_elapsed.seconds / 3600
    minutes = (time_elapsed.seconds % 3600) / 60
    seconds = (time_elapsed.seconds % 3600) % 60
    print "Import completed in %0.2d:%0.2d:%0.2d" % (
        hours, minutes, seconds
    )
示例#2
0
def run_importers(importer_classes, include_deps=False):
    """
    importer_classes: (list) References to the importer classes to run.
    """
    # Create the SQLite connection object.
    conn = sqlite3.connect(settings.EVE_CCP_DUMP_SQLITE_DB)
    conn.row_factory = sqlite3.Row

    if include_deps:
        add_dependencies(importer_classes)

    ordered_importers = order_importers(importer_classes)

    # Timestamp of when the imports started.
    time_started = datetime.datetime.now()

    # Carry out the imports in order.
    for importer_class in ordered_importers:
        importer = importer_class()
        importer.prep_and_run_importer(conn)

    # Print the total time, for the ricers.
    time_elapsed = datetime.datetime.now() - time_started
    hours = time_elapsed.seconds / 3600
    minutes = (time_elapsed.seconds % 3600) / 60
    seconds = (time_elapsed.seconds % 3600) % 60
    print "Import completed in %0.2d:%0.2d:%0.2d" % (
        hours, minutes, seconds
    )
示例#3
0
def run_importers(importer_classes, sqlite_file, include_deps=False):
    """
    importer_classes: (list) References to the importer classes to run.
    sqlite_file: (str) Path to the SQLite file to import from.
    """
    # Create the SQLite connection object.
    conn = sqlite3.connect(sqlite_file)
    # Ignore characters that can't be decoded from UTF-8.
    conn.text_factory = lambda x: unicode(x, "utf-8", "ignore")
    conn.row_factory = sqlite3.Row

    if include_deps:
        add_dependencies(importer_classes)

    ordered_importers = order_importers(importer_classes)

    # Timestamp of when the imports started.
    time_started = datetime.datetime.now()

    # Carry out the imports in order.
    for importer_class in ordered_importers:
        importer = importer_class()
        importer.prep_and_run_importer(conn)

    # Print the total time, for the ricers.
    time_elapsed = datetime.datetime.now() - time_started
    hours = time_elapsed.seconds / 3600
    minutes = (time_elapsed.seconds % 3600) / 60
    seconds = (time_elapsed.seconds % 3600) % 60
    print "Import completed in %0.2d:%0.2d:%0.2d" % (
        hours, minutes, seconds
    )
示例#4
0
    def _cursor(self):
        if self.connection is None:
            ## The following is the same as in django.db.backends.sqlite3.base ##
            settings_dict = self.settings_dict
            if not settings_dict['NAME']:
                raise ImproperlyConfigured(
                    "Please fill out the database NAME in the settings module before using the database."
                )
            kwargs = {
                'database': settings_dict['NAME'],
                'detect_types':
                Database.PARSE_DECLTYPES | Database.PARSE_COLNAMES,
            }
            kwargs.update(settings_dict['OPTIONS'])
            self.connection = Database.connect(**kwargs)
            # Register extract, date_trunc, and regexp functions.
            self.connection.create_function("django_extract", 2,
                                            _sqlite_extract)
            self.connection.create_function("django_date_trunc", 2,
                                            _sqlite_date_trunc)
            self.connection.create_function("regexp", 2, _sqlite_regexp)
            self.connection.create_function("django_format_dtdelta", 5,
                                            _sqlite_format_dtdelta)
            connection_created.send(sender=self.__class__, connection=self)

            ## From here on, customized for GeoDjango ##

            # Enabling extension loading on the SQLite connection.
            try:
                self.connection.enable_load_extension(True)
            except AttributeError:
                raise ImproperlyConfigured(
                    'The pysqlite library does not support C extension loading. '
                    'Both SQLite and pysqlite must be configured to allow '
                    'the loading of extensions to use SpatiaLite.')

            # Loading the SpatiaLite library extension on the connection, and returning
            # the created cursor.
            cur = self.connection.cursor(factory=SQLiteCursorWrapper)
            try:
                cur.execute("SELECT load_extension(%s)",
                            (self.spatialite_lib, ))
            except Exception, msg:
                raise ImproperlyConfigured(
                    'Unable to load the SpatiaLite library extension '
                    '"%s" because: %s' % (self.spatialite_lib, msg))
            return cur
示例#5
0
文件: base.py 项目: BillyWu/django
    def _cursor(self):
        if self.connection is None:
            ## The following is the same as in django.db.backends.sqlite3.base ##
            settings_dict = self.settings_dict
            if not settings_dict['NAME']:
                raise ImproperlyConfigured("Please fill out the database NAME in the settings module before using the database.")
            kwargs = {
                'database': settings_dict['NAME'],
                'detect_types': Database.PARSE_DECLTYPES | Database.PARSE_COLNAMES,
            }
            kwargs.update(settings_dict['OPTIONS'])
            self.connection = Database.connect(**kwargs)
            # Register extract, date_trunc, and regexp functions.
            self.connection.create_function("django_extract", 2, _sqlite_extract)
            self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc)
            self.connection.create_function("regexp", 2, _sqlite_regexp)
            self.connection.create_function("django_format_dtdelta", 5, _sqlite_format_dtdelta)
            connection_created.send(sender=self.__class__, connection=self)

            ## From here on, customized for GeoDjango ##

            # Enabling extension loading on the SQLite connection.
            try:
                self.connection.enable_load_extension(True)
            except AttributeError:
                raise ImproperlyConfigured('The pysqlite library does not support C extension loading. '
                                           'Both SQLite and pysqlite must be configured to allow '
                                           'the loading of extensions to use SpatiaLite.'
                                           )

            # Loading the SpatiaLite library extension on the connection, and returning
            # the created cursor.
            cur = self.connection.cursor(factory=SQLiteCursorWrapper)
            try:
                cur.execute("SELECT load_extension(%s)", (self.spatialite_lib,))
            except Exception, msg:
                raise ImproperlyConfigured('Unable to load the SpatiaLite library extension '
                                           '"%s" because: %s' % (self.spatialite_lib, msg))
            return cur