Created
January 31, 2019 17:56
-
-
Save mattdodge/123b24c69836f8ea5d89017acc20e5c0 to your computer and use it in GitHub Desktop.
Find duplicate blocks in a nio project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: From your nio project root run: | |
# | |
# python duplicate_blocks.py | |
from copy import copy | |
import json | |
import os | |
from os.path import join | |
blocks = {} | |
def block_configs_match(block1, block2): | |
""" Returns True if two block configs match on everything but name/id """ | |
block1 = copy(block1) | |
block2 = copy(block2) | |
del block1['id'] | |
del block1['name'] | |
del block2['id'] | |
del block2['name'] | |
return block1 == block2 | |
for _, _, filenames in os.walk('etc/blocks'): | |
for filename in filenames: | |
if not filename.endswith('.cfg'): | |
continue | |
filename = join('etc', 'blocks', filename) | |
with open(filename) as block: | |
block_cfg = json.load(block) | |
blocks[block_cfg['id']] = block_cfg | |
for block1_id, block1 in blocks.items(): | |
for block2_id, block2 in blocks.items(): | |
if block2_id == block1_id: | |
continue | |
if block_configs_match(block1, block2): | |
print("Block \"{}\" ({}) and \"{}\" ({}) are " | |
"matching {} blocks".format( | |
block1['name'], block1_id[:6], | |
block2['name'], block2_id[:6], | |
block1['type'], | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment