[utils.miner] Improved output with colouring in python scripts
This commit is contained in:
parent
676cd2bf65
commit
d89bd44f8b
|
@ -7,12 +7,12 @@ import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Tool libs
|
# Tool libs
|
||||||
from utils import run, sanitize
|
import utils
|
||||||
import conf
|
import conf
|
||||||
from objects import GameBlock
|
from objects import GameBlock
|
||||||
|
|
||||||
|
|
||||||
print("=> Phase: blocks")
|
utils.title('BLOCKS')
|
||||||
if conf.SAVE:
|
if conf.SAVE:
|
||||||
sys.path.append('../../minecraftcodex')
|
sys.path.append('../../minecraftcodex')
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'local_settings'
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'local_settings'
|
||||||
|
@ -26,10 +26,10 @@ BLOCKS = []
|
||||||
###
|
###
|
||||||
# LOOK FOR CORRECT JAVA FILES
|
# LOOK FOR CORRECT JAVA FILES
|
||||||
###
|
###
|
||||||
print(" => Looking for java files...")
|
utils.sub("Looking for java files...")
|
||||||
print(" Keywords: %s" % ', '.join(conf.BLOCKS_JAVA_KEYWORDS))
|
#utils.sub("Keywords: %s" % ', '.join(conf.BLOCKS_JAVA_KEYWORDS), end='\n')
|
||||||
for keyword in conf.BLOCKS_JAVA_KEYWORDS:
|
for keyword in conf.BLOCKS_JAVA_KEYWORDS:
|
||||||
command = run('grep \'%s\' ./classes/*' % keyword)
|
command = utils.run('grep \'%s\' ./classes/*' % keyword)
|
||||||
lines = []
|
lines = []
|
||||||
[lines.append(x) for x in command]
|
[lines.append(x) for x in command]
|
||||||
lines = ''.join(lines).split('\n')
|
lines = ''.join(lines).split('\n')
|
||||||
|
@ -37,13 +37,15 @@ for keyword in conf.BLOCKS_JAVA_KEYWORDS:
|
||||||
if result and result is not '':
|
if result and result is not '':
|
||||||
java_file = os.path.basename(result.strip().split()[0][:-1])
|
java_file = os.path.basename(result.strip().split()[0][:-1])
|
||||||
if java_file not in conf.BLOCKS_FILES:
|
if java_file not in conf.BLOCKS_FILES:
|
||||||
print(" Found: %s" % java_file)
|
utils.echo("%s " % java_file, end='')
|
||||||
conf.BLOCKS_FILES.append(java_file)
|
conf.BLOCKS_FILES.append(java_file)
|
||||||
|
|
||||||
|
utils.echo('\r')
|
||||||
|
|
||||||
###
|
###
|
||||||
# GET ITEMS INFO FROM CLASSFILE
|
# GET ITEMS INFO FROM CLASSFILE
|
||||||
###
|
###
|
||||||
print(" => Mining blocks...")
|
utils.sub('Looking for dataz', end='\n')
|
||||||
|
|
||||||
# Old items for final count
|
# Old items for final count
|
||||||
try:
|
try:
|
||||||
|
@ -67,7 +69,7 @@ for java_file in conf.BLOCKS_FILES:
|
||||||
if conf.DEBUG:
|
if conf.DEBUG:
|
||||||
print("Line: " + item['code'])
|
print("Line: " + item['code'])
|
||||||
|
|
||||||
item['code'] = sanitize(item['code'])
|
item['code'] = utils.sanitize(item['code'])
|
||||||
|
|
||||||
if conf.DEBUG:
|
if conf.DEBUG:
|
||||||
print("Sanitize: " + item['code'])
|
print("Sanitize: " + item['code'])
|
||||||
|
@ -110,21 +112,20 @@ if conf.SAVE:
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
# Print the miner summary and compile the new old data
|
# Print the miner summary and compile the new old data
|
||||||
print(' => Summary')
|
|
||||||
new_old_data = {}
|
new_old_data = {}
|
||||||
new_old_data['list'] = []
|
new_old_data['list'] = []
|
||||||
[new_old_data['list'].append(x.name) for x in BLOCKS]
|
[new_old_data['list'].append(x.name) for x in BLOCKS]
|
||||||
new_blocks = len(new_old_data['list'])-len(OLD_BLOCKS['list'])
|
new_blocks = len(new_old_data['list'])-len(OLD_BLOCKS['list'])
|
||||||
print(' Fetched %d blocks (%d new)' % (len(new_old_data['list']), new_blocks))
|
utils.info('Fetched %d blocks (%d new)' % (len(new_old_data['list']), new_blocks))
|
||||||
if new_blocks > 0:
|
if new_blocks != 0:
|
||||||
print(' Modifications:')
|
utils.sub('Modifications:', end='\n')
|
||||||
for item in BLOCKS:
|
for item in BLOCKS:
|
||||||
if item.name not in OLD_BLOCKS['list']:
|
if item.name not in OLD_BLOCKS['list']:
|
||||||
print(' + %s' % item.name)
|
utils.sub(' + %s' % item.name, end='\n', color=utils.colors.GREEN)
|
||||||
|
|
||||||
for item in OLD_BLOCKS['list']:
|
for item in OLD_BLOCKS['list']:
|
||||||
if item not in new_old_data['list']:
|
if item not in new_old_data['list']:
|
||||||
print(' - %s' % item)
|
utils.sub(' - %s' % item, end='\n', color=utils.colors.RED)
|
||||||
|
|
||||||
oldblocks = open('blocks.json', 'w')
|
oldblocks = open('blocks.json', 'w')
|
||||||
oldblocks.write(json.dumps(new_old_data))
|
oldblocks.write(json.dumps(new_old_data))
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
JARFILE=$1
|
JARFILE=$1
|
||||||
|
|
||||||
if [ "$JARFILE" != "" ]; then
|
if [ "$JARFILE" != "" ]; then
|
||||||
echo "=> Phase: JAR file"
|
echo "[] Preparing files from JAR: $JARFILE []"
|
||||||
# Remove old
|
# Remove old
|
||||||
rm -rf ./jarfile ./classes
|
rm -rf ./jarfile ./classes
|
||||||
|
|
||||||
|
@ -13,18 +13,18 @@ if [ "$JARFILE" != "" ]; then
|
||||||
mkdir classes
|
mkdir classes
|
||||||
|
|
||||||
# Decompress the jarfile into the jarfile folder
|
# Decompress the jarfile into the jarfile folder
|
||||||
echo " => Unpackaging jar file"
|
echo " Unpackaging jar file"
|
||||||
unzip -qq $JARFILE -d ./jarfile
|
unzip -qq $JARFILE -d ./jarfile
|
||||||
|
|
||||||
# Find all the classes and pass then through JAD
|
# Find all the classes and pass then through JAD
|
||||||
#find . -type d -name *.class -exec rm -rf {} \;
|
#find . -type d -name *.class -exec rm -rf {} \;
|
||||||
echo " => Decompiling classes"
|
echo " Decompiling classes"
|
||||||
ls ./jarfile/*.class | xargs -n1 ./tools/jad/jad -sjava -dclasses &> /dev/null
|
ls ./jarfile/*.class | xargs -n1 ./tools/jad/jad -sjava -dclasses &> /dev/null
|
||||||
|
|
||||||
# Remove classfiles and left only other files
|
# Remove classfiles and left only other files
|
||||||
echo " => Cleaning"
|
echo " Cleaning"
|
||||||
rm ./jarfile/*.class
|
rm ./jarfile/*.class
|
||||||
else
|
else
|
||||||
echo "No jarfile specified."
|
echo "[!] No jarfile specified!"
|
||||||
exit
|
exit -1
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -7,12 +7,12 @@ import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Tool libs
|
# Tool libs
|
||||||
from utils import run, sanitize
|
import utils
|
||||||
import conf
|
import conf
|
||||||
from objects import GameItem
|
from objects import GameItem
|
||||||
|
|
||||||
|
|
||||||
print("=> Phase: items")
|
utils.title("ITEMS")
|
||||||
|
|
||||||
if conf.SAVE:
|
if conf.SAVE:
|
||||||
sys.path.append('../../minecraftcodex')
|
sys.path.append('../../minecraftcodex')
|
||||||
|
@ -27,21 +27,23 @@ ITEMS = []
|
||||||
###
|
###
|
||||||
# LOOK FOR CORRECT JAVA FILES
|
# LOOK FOR CORRECT JAVA FILES
|
||||||
###
|
###
|
||||||
print(" => Looking for java files...")
|
utils.sub("Looking for java files: ")
|
||||||
print(" Keywords: %s" % ', '.join(conf.ITEMS_JAVA_KEYWORDS))
|
#utils.sub("Keywords: %s" % ', '.join(conf.ITEMS_JAVA_KEYWORDS), end='\n')
|
||||||
for keyword in conf.ITEMS_JAVA_KEYWORDS:
|
for keyword in conf.ITEMS_JAVA_KEYWORDS:
|
||||||
cmd = run('grep \'%s\' ./classes/*' % keyword)
|
cmd = utils.run('grep \'%s\' ./classes/*' % keyword)
|
||||||
for result in cmd:
|
for result in cmd:
|
||||||
if result and result is not '':
|
if result and result is not '':
|
||||||
java_file = os.path.basename(result.strip().split()[0][:-1])
|
java_file = os.path.basename(result.strip().split()[0][:-1])
|
||||||
if java_file not in conf.ITEMS_FILES:
|
if java_file not in conf.ITEMS_FILES:
|
||||||
print(" Found: %s" % java_file)
|
utils.echo("%s " % java_file, end='')
|
||||||
conf.ITEMS_FILES.append(java_file)
|
conf.ITEMS_FILES.append(java_file)
|
||||||
|
|
||||||
|
utils.echo('\r')
|
||||||
|
|
||||||
###
|
###
|
||||||
# GET ITEMS INFO FROM CLASSFILE
|
# GET ITEMS INFO FROM CLASSFILE
|
||||||
###
|
###
|
||||||
print(" => Mining items...")
|
utils.sub('Looking for dataz', end='\n')
|
||||||
|
|
||||||
# Old items for final count
|
# Old items for final count
|
||||||
try:
|
try:
|
||||||
|
@ -65,7 +67,7 @@ for java_file in conf.ITEMS_FILES:
|
||||||
if conf.DEBUG:
|
if conf.DEBUG:
|
||||||
print("Line: " + item['code'])
|
print("Line: " + item['code'])
|
||||||
|
|
||||||
item['code'] = sanitize(item['code'])
|
item['code'] = utils.sanitize(item['code'])
|
||||||
|
|
||||||
if conf.DEBUG:
|
if conf.DEBUG:
|
||||||
print("Sanitize: " + item['code'])
|
print("Sanitize: " + item['code'])
|
||||||
|
@ -109,21 +111,20 @@ if conf.SAVE:
|
||||||
|
|
||||||
|
|
||||||
# Print the miner summary and compile the new old data
|
# Print the miner summary and compile the new old data
|
||||||
print(' => Summary')
|
|
||||||
new_old_data = {}
|
new_old_data = {}
|
||||||
new_old_data['list'] = []
|
new_old_data['list'] = []
|
||||||
[new_old_data['list'].append(x.name) for x in ITEMS]
|
[new_old_data['list'].append(x.name) for x in ITEMS]
|
||||||
new_items = len(new_old_data['list'])-len(OLD_ITEMS['list'])
|
new_items = len(new_old_data['list'])-len(OLD_ITEMS['list'])
|
||||||
print(' Fetched %d items (%d new)' % (len(ITEMS), new_items))
|
utils.info('Fetched %d items (%d new)' % (len(ITEMS), new_items))
|
||||||
if new_items > 0:
|
if new_items != 0:
|
||||||
print(' Modifications:')
|
utils.sub('Modifications', end='\n')
|
||||||
for item in ITEMS:
|
for item in ITEMS:
|
||||||
if item.name not in OLD_ITEMS['list']:
|
if item.name not in OLD_ITEMS['list']:
|
||||||
print(' + %s' % item.name)
|
utils.sub(' + %s' % item.name, end='\n', color=utils.colors.GREEN)
|
||||||
|
|
||||||
for item in OLD_ITEMS['list']:
|
for item in OLD_ITEMS['list']:
|
||||||
if item not in new_old_data['list']:
|
if item not in new_old_data['list']:
|
||||||
print(' - %s' % item)
|
utils.sub(' - %s' % item, end='\n', color=utils.colors.RED)
|
||||||
|
|
||||||
olditems = open('items.json', 'w')
|
olditems = open('items.json', 'w')
|
||||||
olditems.write(json.dumps(new_old_data))
|
olditems.write(json.dumps(new_old_data))
|
||||||
|
|
|
@ -7,12 +7,12 @@ import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Tool libs
|
# Tool libs
|
||||||
from utils import run, sanitize
|
import utils
|
||||||
import conf
|
import conf
|
||||||
from objects import GameLanguage
|
from objects import GameLanguage
|
||||||
|
|
||||||
|
|
||||||
print("=> Phase: languages")
|
utils.title('LANGUAGES')
|
||||||
if conf.SAVE:
|
if conf.SAVE:
|
||||||
sys.path.append('../../minecraftcodex')
|
sys.path.append('../../minecraftcodex')
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'local_settings'
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'local_settings'
|
||||||
|
@ -28,9 +28,9 @@ LANGUAGES_STR = []
|
||||||
###
|
###
|
||||||
# LOOK FOR CORRECT JAVA FILES
|
# LOOK FOR CORRECT JAVA FILES
|
||||||
###
|
###
|
||||||
print(" => Looking for languages files...")
|
utils.sub("Looking for languages files:")
|
||||||
directory_list = os.listdir(conf.LANGUAGES_PATH)
|
directory_list = os.listdir(conf.LANGUAGES_PATH)
|
||||||
print(" Found %d file(s)." % len(directory_list))
|
utils.echo("found %d file(s)" % len(directory_list), end='\n')
|
||||||
|
|
||||||
###
|
###
|
||||||
# GET LANGUAGES
|
# GET LANGUAGES
|
||||||
|
@ -44,7 +44,7 @@ try:
|
||||||
except:
|
except:
|
||||||
OLD_LANGUAGES = []
|
OLD_LANGUAGES = []
|
||||||
|
|
||||||
print(" => Mining languages...")
|
utils.sub('Looking for dataz', end='\n')
|
||||||
for item in directory_list:
|
for item in directory_list:
|
||||||
if '.lang' in item:
|
if '.lang' in item:
|
||||||
if conf.DEBUG:
|
if conf.DEBUG:
|
||||||
|
@ -103,23 +103,20 @@ if conf.SAVE:
|
||||||
string_obj.save()
|
string_obj.save()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print(" => Summary")
|
|
||||||
|
|
||||||
# LANGUAGES
|
# LANGUAGES
|
||||||
[LANGUAGES_STR.append(x.name) for x in LANGUAGES]
|
[LANGUAGES_STR.append(x.name) for x in LANGUAGES]
|
||||||
new_languages = len(LANGUAGES_STR) - len(OLD_LANGUAGES)
|
new_languages = len(LANGUAGES_STR) - len(OLD_LANGUAGES)
|
||||||
print(" Found %d languages (%d new)." % (len(LANGUAGES_STR), new_languages))
|
utils.info("Found %d languages (%d new)." % (len(LANGUAGES_STR), new_languages))
|
||||||
if len(LANGUAGES_STR) != len(OLD_LANGUAGES):
|
if len(LANGUAGES_STR) != len(OLD_LANGUAGES):
|
||||||
print(" Comparision:")
|
utils.sub('Modifications:', end='\n')
|
||||||
|
|
||||||
for string in LANGUAGES_STR:
|
for lang in LANGUAGES_STR:
|
||||||
if string not in OLD_LANGUAGES:
|
if lang not in OLD_LANGUAGES:
|
||||||
print(" + %s" % string)
|
utils.sub(' + %s' % lang, end='\n', color=utils.colors.GREEN)
|
||||||
|
|
||||||
for string in OLD_LANGUAGES:
|
for lang in OLD_LANGUAGES:
|
||||||
if string not in LANGUAGES_STR:
|
if lang not in LANGUAGES_STR:
|
||||||
print(" - %s" % string)
|
utils.sub(' - %s' % lang, end='\n', color=utils.colors.RED)
|
||||||
|
|
||||||
olditems = open('languages.json', 'w')
|
olditems = open('languages.json', 'w')
|
||||||
olditems.write(json.dumps(LANGUAGES_STR))
|
olditems.write(json.dumps(LANGUAGES_STR))
|
||||||
|
@ -127,17 +124,17 @@ olditems.close()
|
||||||
|
|
||||||
# STRINGS
|
# STRINGS
|
||||||
new_strings = len(STRINGS) - len(OLD_STRINGS)
|
new_strings = len(STRINGS) - len(OLD_STRINGS)
|
||||||
print(" Found %d strings (%d new) -based on en_US-." % (len(STRINGS), new_strings))
|
utils.info("Found %d strings (%d new) -based on en_US-." % (len(STRINGS), new_strings))
|
||||||
if len(STRINGS) != len(OLD_STRINGS):
|
if len(STRINGS) != len(OLD_STRINGS):
|
||||||
print(" Comparision:")
|
utils.sub('Modifications:', end='\n')
|
||||||
|
|
||||||
for string in STRINGS:
|
for string in STRINGS:
|
||||||
if string not in OLD_STRINGS:
|
if string not in OLD_STRINGS:
|
||||||
print(" + %s" % string)
|
utils.sub(' + %s' % string, end='\n', color=utils.colors.GREEN)
|
||||||
|
|
||||||
for string in OLD_STRINGS:
|
for string in OLD_STRINGS:
|
||||||
if string not in STRINGS:
|
if string not in STRINGS:
|
||||||
print(" - %s" % string)
|
utils.sub(' - %s' % string, end='\n', color=utils.colors.RED)
|
||||||
|
|
||||||
olditems = open('strings.json', 'w')
|
olditems = open('strings.json', 'w')
|
||||||
olditems.write(json.dumps(STRINGS))
|
olditems.write(json.dumps(STRINGS))
|
||||||
|
|
|
@ -8,10 +8,11 @@ import json
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
# Tool libs
|
# Tool libs
|
||||||
|
import utils
|
||||||
import conf
|
import conf
|
||||||
from objects import GameTexture
|
from objects import GameTexture
|
||||||
|
|
||||||
print("=> Phase: textures")
|
utils.title("TEXTURES")
|
||||||
|
|
||||||
if conf.SAVE:
|
if conf.SAVE:
|
||||||
path.append('../../minecraftcodex')
|
path.append('../../minecraftcodex')
|
||||||
|
@ -73,21 +74,22 @@ if conf.SAVE:
|
||||||
)
|
)
|
||||||
item.save()
|
item.save()
|
||||||
|
|
||||||
print(' => Summary')
|
|
||||||
|
# SUMMARY
|
||||||
new_old_data = {}
|
new_old_data = {}
|
||||||
new_old_data['list'] = []
|
new_old_data['list'] = []
|
||||||
[new_old_data['list'].append(x.name) for x in TEXTURES]
|
[new_old_data['list'].append(x.name) for x in TEXTURES]
|
||||||
new_items = len(new_old_data['list'])-len(OLD_TEXTURES['list'])
|
new_items = len(new_old_data['list'])-len(OLD_TEXTURES['list'])
|
||||||
print(' Fetched %d textures (%d new)' % (len(TEXTURES), new_items))
|
utils.info('Fetched %d textures (%d new)' % (len(TEXTURES), new_items))
|
||||||
if new_items > 0:
|
if new_items != 0:
|
||||||
print(' Modifications:')
|
utils.sub('Modifications', end='\n')
|
||||||
for item in TEXTURES:
|
for item in TEXTURES:
|
||||||
if item.name not in OLD_TEXTURES['list']:
|
if item.name not in OLD_TEXTURES['list']:
|
||||||
print(' + %s' % item.name)
|
utils.sub(' + %s' % item.name, end='\n', color=utils.colors.GREEN)
|
||||||
|
|
||||||
for item in OLD_TEXTURES['list']:
|
for item in OLD_TEXTURES['list']:
|
||||||
if item not in new_old_data['list']:
|
if item not in new_old_data['list']:
|
||||||
print(' - %s' % item)
|
utils.sub(' - %s' % item, end='\n', color=utils.colors.RED)
|
||||||
|
|
||||||
olditems = open('textures.json', 'w')
|
olditems = open('textures.json', 'w')
|
||||||
olditems.write(json.dumps(new_old_data))
|
olditems.write(json.dumps(new_old_data))
|
||||||
|
|
Loading…
Reference in New Issue