Support Python 2 and 3 in sectors2sqlite.py.
authorKahrl <kahrl@gmx.net>
Mon, 26 Sep 2011 11:24:21 +0000 (13:24 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Mon, 26 Sep 2011 18:57:18 +0000 (21:57 +0300)
util/sectors2sqlite.py

index 178842129482857f45dba84c1ecf1d273a28191b..38261a498486a749a28e82c816dd492a4912192e 100755 (executable)
@@ -3,7 +3,7 @@
 # Loads block files from sectors folders into map.sqlite database.
 # The sectors folder should be safe to remove after this prints "Finished."
 
-import time, os
+import time, os, sys
 
 try:
        import sqlite3
@@ -114,8 +114,13 @@ for base in paths:
                                        continue
                                
                                f = open(root+'/'+block, 'rb')
-                               cur.execute('INSERT OR IGNORE INTO `blocks` VALUES(?, ?)', (pos, f.read()))
+                               blob = f.read()
                                f.close()
+                               if sys.version_info.major == 2:
+                                       blob = buffer(blob)
+                               else:
+                                       blob = memoryview(blob)
+                               cur.execute('INSERT OR IGNORE INTO `blocks` VALUES(?, ?)', (pos, blob))
                                count += 1
                
                if(time.time() - t > 3):