From: Kahrl Date: Mon, 26 Sep 2011 11:24:21 +0000 (+0200) Subject: Support Python 2 and 3 in sectors2sqlite.py. X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=561bb649632c942b8c45b52558d180b83b48b681;p=zefram%2Fminetest%2Fminetest_engine.git Support Python 2 and 3 in sectors2sqlite.py. --- diff --git a/util/sectors2sqlite.py b/util/sectors2sqlite.py index 17884212..38261a49 100755 --- a/util/sectors2sqlite.py +++ b/util/sectors2sqlite.py @@ -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):