Ejemplo n.º 1
0
    def import_data(self, data):
        # Put away the current generation tables.
        self.switch_to_generation(None)

        # Make a new current generation.
        self.make_new_generation()

        # Read the data.
        print("Reading")

        objs = refs = bytes = 0

        sql_alch_conn = Connection.get(None).session

        transaction = sql_alch_conn.begin()

        for objdata in self._parse_data(data):

            sql_alch_conn.execute(
                """insert into obj
                        (address, type, name, value, size, len, repr)
                   values
                        (:address, :type, :name, :value, :size, :len, :repr)
                """,
                address=objdata['address'],
                type=objdata['type'],
                name=objdata.get('name'),
                value=objdata.get('value'),
                size=objdata['size'],
                len=objdata.get('len'),
                repr=objdata['repr']
            )
            objs += 1
            bytes += objdata['size']
            for ref in objdata['refs']:
                sql_alch_conn.execute(
                    "insert into ref (parent, child) values (:parent, :child)",
                    parent=objdata['address'],
                    child=ref,
                )
                refs += 1
            if objs % 10000 == 0:
                transaction.commit()
                transaction = sql_alch_conn.begin()
                print("loaded {} objects, {} refs".format(objs, refs))

        self.execute_and_ignore('COMMIT')
        print("")

        return {'objs': objs, 'refs': refs, 'bytes': bytes}
Ejemplo n.º 2
0
    def import_data(self, data):
        # Put away the current generation tables.
        self.switch_to_generation(None)

        # Make a new current generation.
        self.make_new_generation()

        # Read the data.
        print("Reading")

        objs = refs = bytes = 0

        sql_alch_conn = Connection.get(None).session

        transaction = sql_alch_conn.begin()

        for objdata in self._parse_data(data):

            sql_alch_conn.execute(
                """insert into obj
                        (address, type, name, value, size, len, repr)
                   values
                        (:address, :type, :name, :value, :size, :len, :repr)
                """,
                address=objdata['address'],
                type=objdata['type'],
                name=objdata.get('name'),
                value=objdata.get('value'),
                size=objdata['size'],
                len=objdata.get('len'),
                repr=objdata['repr']
            )
            objs += 1
            bytes += objdata['size']
            for ref in objdata['refs']:
                sql_alch_conn.execute(
                    "insert into ref (parent, child) values (:parent, :child)",
                    parent=objdata['address'],
                    child=ref,
                )
                refs += 1
            if objs % 10000 == 0:
                transaction.commit()
                transaction = sql_alch_conn.begin()
                print("loaded {} objects, {} refs".format(objs, refs))

        self.execute_and_ignore('COMMIT')
        print("")

        return {'objs': objs, 'refs': refs, 'bytes': bytes}
Ejemplo n.º 3
0
 def _dec(self, *args, **kwargs):
     if not Connection.get(None):
         print("Need an open database")
         return
     return fn(self, *args, **kwargs)
Ejemplo n.º 4
0
 def _dec(self, *args, **kwargs):
     if not Connection.get(None):
         print("Need an open database")
         return
     return fn(self, *args, **kwargs)