3 # Loads block files from sectors folders into map.sqlite database.
4 # The sectors folder should be safe to remove after this prints "Finished."
11 exit('You need to have the Python sqlite3 module.')
17 # sectors2 gets to try first
18 if os.path.isdir(path + 'sectors2/'):
19 paths.append('sectors2')
20 if os.path.isdir(path + 'sectors/'):
21 paths.append('sectors')
24 exit('Could not find sectors folder at ' + path + 'sectors2/ or ' + path + 'sectors/')
28 return (u if u < 2**11 else u - 2**12)
37 # Convert sector folder(s) to integer
38 def getSectorPos(dirname):
43 elif len(dirname) == 7:
48 print('Terrible sector at ' + dirname)
53 # Convert block file to integer position
54 def getBlockPos(sectordir, blockfile):
55 p2d = getSectorPos(sectordir)
60 if len(blockfile) != 4:
61 print("Invalid block filename: " + blockfile)
65 return p2d[0], y, p2d[1]
67 # Convert location to integer
68 def getBlockAsInteger(p):
69 return int64(p[2]*16777216 + p[1]*4096 + p[0])
74 if not os.path.isfile(path + 'map.sqlite'):
77 conn = sqlite3.connect(path + 'map.sqlite')
80 exit('Could not open database.')
85 cur.execute("CREATE TABLE IF NOT EXISTS `blocks` (`pos` INT NOT NULL PRIMARY KEY, `data` BLOB);")
87 print('Created database at ' + path + 'map.sqlite')
97 elif base == 'sectors2':
100 print('Ignoring base ' + base)
103 for root, dirs, files in os.walk(path + base):
106 pos = getBlockAsInteger(getBlockPos(root[(-8 if v == 1 else -7 if v == 2 else 0):], block))
109 print('Ignoring broken path ' + root + '/' + block)
112 f = open(root+'/'+block, 'rb')
113 cur.execute('INSERT OR IGNORE INTO `blocks` VALUES(?, ?)', (pos, f.read()))
117 if(time.time() - t > 3):
119 print(str(count)+' blocks processed...')
123 print('Finished. (' + str(count) + ' blocks)')