1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-12-22 07:38:48 -05:00

Support Python 2 and 3 in sectors2sqlite.py.

This commit is contained in:
Kahrl 2011-09-26 13:24:21 +02:00
parent d5899a53fd
commit 561bb64963

View File

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