ForgePatch/release.py

178 lines
5.9 KiB
Python
Raw Normal View History

2012-08-01 23:35:35 +00:00
import os, os.path, sys
import shutil, fnmatch
import logging, zipfile, re
forge_dir = os.path.dirname(os.path.abspath(__file__))
mcp_dir = os.path.abspath('..')
src_dir = os.path.join(mcp_dir, 'src')
sys.path.append(mcp_dir)
from runtime.reobfuscate import reobfuscate
from forge import reset_logger, load_version, zip_folder, zip_create, inject_version, build_forge_dev
2012-08-01 23:35:35 +00:00
reobf_dir = os.path.join(mcp_dir, 'reobf')
client_dir = os.path.join(reobf_dir, 'minecraft')
zip = None
zip_name = None
zip_base = None
version_str = None
def main():
global version_str
build_num = 0
if len(sys.argv) > 1:
try:
build_num = int(sys.argv[1])
except:
pass
ret = 0
fml_dir = os.path.join(forge_dir, 'fml')
build_forge_dev(mcp_dir, forge_dir, fml_dir, build_num)
2012-08-01 23:35:35 +00:00
if ret != 0:
sys.exit(ret)
print '=================================== Release Start ================================='
error_level = 0
try:
os.chdir(mcp_dir)
reset_logger()
reobfuscate(None, False, True, True)
reset_logger()
os.chdir(forge_dir)
except SystemExit, e:
print 'Reobfusicate Exception: %d ' % e.code
error_level = e.code
extract_fml_obfed()
extract_paulscode()
2012-08-01 23:35:35 +00:00
version = load_version(build_num)
version_str = '%d.%d.%d.%d' % (version['major'], version['minor'], version['revision'], version['build'])
out_folder = os.path.join(forge_dir, 'forge-%s' % version_str)
if os.path.isdir(out_folder):
shutil.rmtree(out_folder)
os.makedirs(out_folder)
zip_start('minecraftforge-universal-%s.zip' % version_str)
2012-08-01 23:35:35 +00:00
zip_folder(client_dir, '', zip)
zip_add('client/forge_logo.png')
2012-08-01 23:35:35 +00:00
zip_add('install/MinecraftForge-Credits.txt')
zip_add('install/MinecraftForge-License.txt')
zip_add('fml/CREDITS-fml.txt')
zip_add('fml/LICENSE-fml.txt')
zip_add('fml/README-fml.txt')
zip_add('fml/common/fml_at.cfg')
zip_add('fml/common/fml_marker.cfg')
zip_add('fml/common/fmlversion.properties')
2012-08-01 23:35:35 +00:00
zip_add('install/Paulscode IBXM Library License.txt')
zip_add('install/Paulscode SoundSystem CodecIBXM License.txt')
zip_add('common/forge_at.cfg')
2012-08-01 23:35:35 +00:00
zip_end()
inject_version(os.path.join(forge_dir, 'common/net/minecraftforge/common/ForgeVersion.java'.replace('/', os.sep)), build_num)
2012-08-01 23:35:35 +00:00
zip_start('minecraftforge-src-%s.zip' % version_str, 'forge')
zip_add('client', 'client')
zip_add('common', 'common')
zip_add('patches', 'patches')
zip_add('fml', 'fml')
2012-08-01 23:35:35 +00:00
zip_add('install/install.cmd')
zip_add('install/install.sh')
zip_add('install/README-MinecraftForge.txt')
zip_add('install/install.py')
zip_add('forge.py')
zip_add('install/MinecraftForge-Credits.txt')
zip_add('install/MinecraftForge-License.txt')
zip_add('install/Paulscode IBXM Library License.txt')
zip_add('install/Paulscode SoundSystem CodecIBXM License.txt')
zip_end()
inject_version(os.path.join(forge_dir, 'common/net/minecraftforge/common/ForgeVersion.java'.replace('/', os.sep)), 0)
2012-08-01 23:35:35 +00:00
print '=================================== Release Finished %d =================================' % error_level
sys.exit(error_level)
def zip_add(file, key=None):
if key == None:
key = os.path.basename(file)
else:
key = key.replace('/', os.sep)
if not zip_base is None:
key = os.path.join(zip_base, key)
file = os.path.join(forge_dir, file.replace('/', os.sep))
if os.path.isdir(file):
zip_folder(file, key, zip)
else:
if os.path.isfile(file):
print key
zip.write(file, key)
def zip_start(name, base=None):
global zip, zip_name, zip_base
zip_name = name
print '=================================== %s Start =================================' % zip_name
zip_file = os.path.join(forge_dir, 'forge-%s' % version_str, name)
zip = zipfile.ZipFile(zip_file, 'w', zipfile.ZIP_DEFLATED)
zip_base = base
def zip_end():
global zip, zip_name, zip_base
zip.close()
print '=================================== %s Finished =================================' % zip_name
zip_name = None
zip_base = None
def update_info(input, version):
input = os.path.join(forge_dir, input.replace('/', os.sep))
temp = os.path.join(forge_dir, 'file.backup')
shutil.move(input, temp)
with open(temp, 'r') as fh:
buf = fh.read()
buf = re.sub(r'{version}', version, buf)
with open(input, 'w') as fh:
fh.write(buf)
def extract_fml_obfed():
fml_file = os.path.join(forge_dir, 'fml', 'difflist.txt')
if not os.path.isfile(fml_file):
print 'Could not find Forge ModLoader\'s DiffList, looking for it at: %s' % fml_file
sys.exit(1)
with open(fml_file, 'r') as fh:
lines = fh.readlines()
client = zipfile.ZipFile(os.path.join(mcp_dir, 'temp', 'client_reobf.jar'))
print 'Extracting Reobfed Forge ModLoader classes'
for line in lines:
line = line.replace('\n', '').replace('\r', '').replace('/', os.sep)
if not os.path.isfile(os.path.join(reobf_dir, line)):
print ' %s' % line
2012-08-01 23:35:35 +00:00
side = line.split(os.sep)[0]
if side == 'minecraft':
client.extract(line[10:].replace(os.sep, '/'), client_dir)
client.close()
def extract_paulscode():
client = zipfile.ZipFile(os.path.join(mcp_dir, 'temp', 'client_reobf.jar'))
print 'Extracting Reobfed Paulscode for mac users -.-'
for i in client.filelist:
if i.filename.startswith('paulscode'):
if not os.path.isfile(os.path.join(client_dir, i.filename)):
print ' %s' % i.filename
client.extract(i.filename, client_dir)
client.close()
2012-08-01 23:35:35 +00:00
if __name__ == '__main__':
main()