2012-12-07 19:25:19 +00:00
|
|
|
import os, os.path, sys, glob
|
2013-07-16 20:55:31 +00:00
|
|
|
import shutil, fnmatch, time, json
|
2013-07-01 06:21:28 +00:00
|
|
|
import logging, zipfile, re, subprocess
|
2013-07-16 20:55:31 +00:00
|
|
|
from pprint import pformat, pprint
|
2012-12-04 02:15:38 +00:00
|
|
|
from optparse import OptionParser
|
2013-06-02 23:26:06 +00:00
|
|
|
from urllib2 import HTTPError
|
2013-07-02 04:42:33 +00:00
|
|
|
from contextlib import closing
|
|
|
|
from datetime import datetime
|
2013-07-12 11:08:29 +00:00
|
|
|
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
|
2012-08-01 23:35:35 +00:00
|
|
|
forge_dir = os.path.dirname(os.path.abspath(__file__))
|
2012-08-10 01:37:52 +00:00
|
|
|
from forge import reset_logger, load_version, zip_folder, zip_create, inject_version, build_forge_dev
|
2012-10-29 05:04:47 +00:00
|
|
|
from changelog import make_changelog
|
2012-08-01 23:35:35 +00:00
|
|
|
|
|
|
|
zip = None
|
|
|
|
zip_name = None
|
|
|
|
zip_base = None
|
|
|
|
version_str = None
|
2012-11-18 06:58:34 +00:00
|
|
|
version_mc = None
|
2012-08-01 23:35:35 +00:00
|
|
|
|
|
|
|
def main():
|
|
|
|
global version_str
|
2012-11-18 06:58:34 +00:00
|
|
|
global version_mc
|
|
|
|
|
2012-12-04 02:15:38 +00:00
|
|
|
parser = OptionParser()
|
|
|
|
parser.add_option('-m', '--mcp-dir', action='store', dest='mcp_dir', help='MCP Path', default=None)
|
|
|
|
parser.add_option('-b', '--build', action='store', dest='build', help='Build number', default=None)
|
2012-12-10 23:43:19 +00:00
|
|
|
parser.add_option('-s', '--skipchangelog', action='store_true', dest='skip_changelog', help='Skip Changelog', default=False)
|
2012-12-18 07:53:33 +00:00
|
|
|
parser.add_option('-j', '--sign-jar', action='store', dest='sign_jar', help='Path to jar signer command', default=None)
|
2012-12-04 02:15:38 +00:00
|
|
|
options, _ = parser.parse_args()
|
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
build_num = 0
|
2012-12-04 02:15:38 +00:00
|
|
|
if not options.build is None:
|
2012-08-01 23:35:35 +00:00
|
|
|
try:
|
2012-12-04 02:15:38 +00:00
|
|
|
build_num = int(options.build)
|
2012-08-01 23:35:35 +00:00
|
|
|
except:
|
|
|
|
pass
|
2012-12-04 02:15:38 +00:00
|
|
|
|
|
|
|
mcp_dir = os.path.join(forge_dir, 'mcp')
|
|
|
|
if not options.mcp_dir is None:
|
|
|
|
mcp_dir = os.path.abspath(options.mcp_dir)
|
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
ret = 0
|
2012-08-10 01:37:52 +00:00
|
|
|
fml_dir = os.path.join(forge_dir, 'fml')
|
2013-03-07 04:45:40 +00:00
|
|
|
ret = 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)
|
|
|
|
|
2013-03-04 03:30:23 +00:00
|
|
|
|
|
|
|
temp_dir = os.path.join(forge_dir, 'temp')
|
|
|
|
src_dir = os.path.join(mcp_dir, 'src')
|
|
|
|
reobf_dir = os.path.join(mcp_dir, 'reobf')
|
|
|
|
client_dir = os.path.join(reobf_dir, 'minecraft')
|
|
|
|
fml_dir = os.path.join(temp_dir, 'fml')
|
2012-12-04 02:15:38 +00:00
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
print '=================================== Release Start ================================='
|
2013-03-04 03:30:23 +00:00
|
|
|
|
|
|
|
fml = glob.glob(os.path.join(forge_dir, 'fml', 'target', 'fml-src-*.%d-*.zip' % build_num))
|
|
|
|
if not len(fml) == 1:
|
|
|
|
if len(fml) == 0:
|
|
|
|
print 'Missing FML source zip, should be named fml-src-*.zip inside ./fml/target/ created when running setup'
|
|
|
|
else:
|
|
|
|
print 'To many FML source zips found, we should only have one. Check the Forge Git for the latest FML version supported'
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if os.path.isdir(fml_dir):
|
|
|
|
shutil.rmtree(fml_dir)
|
|
|
|
|
|
|
|
print 'Extracting: %s' % os.path.basename(fml[0])
|
|
|
|
zf = zipfile.ZipFile(fml[0])
|
|
|
|
zf.extractall(temp_dir)
|
|
|
|
zf.close()
|
|
|
|
|
2013-07-03 13:26:47 +00:00
|
|
|
if os.path.isfile('MANIFEST.MF'):
|
|
|
|
os.remove('MANIFEST.MF')
|
|
|
|
|
|
|
|
fml_name = os.path.basename(fml[0]).replace('src', 'universal').replace('.zip', '.jar').replace('-master.', '.')
|
|
|
|
print('Extracting %s MANIFEST.MF' % fml_name)
|
|
|
|
with closing(zipfile.ZipFile(os.path.join(forge_dir, 'fml', 'target', fml_name), mode='r')) as zip_in:
|
|
|
|
with closing(open('MANIFEST.MF', 'wb')) as out:
|
|
|
|
out.write(zip_in.read('META-INF/MANIFEST.MF'))
|
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
error_level = 0
|
|
|
|
try:
|
2012-12-04 02:15:38 +00:00
|
|
|
sys.path.append(mcp_dir)
|
|
|
|
from runtime.reobfuscate import reobfuscate
|
2012-08-01 23:35:35 +00:00
|
|
|
os.chdir(mcp_dir)
|
|
|
|
reset_logger()
|
2013-03-09 09:00:52 +00:00
|
|
|
reobfuscate(None, False, True, True, True, False, False)
|
2012-08-01 23:35:35 +00:00
|
|
|
reset_logger()
|
|
|
|
os.chdir(forge_dir)
|
|
|
|
except SystemExit, e:
|
|
|
|
print 'Reobfusicate Exception: %d ' % e.code
|
|
|
|
error_level = e.code
|
|
|
|
|
2013-03-04 03:30:23 +00:00
|
|
|
extract_fml_obfed(fml_dir, mcp_dir, reobf_dir, client_dir)
|
2013-07-01 06:21:28 +00:00
|
|
|
gen_bin_patches(mcp_dir, os.path.join(forge_dir, 'fml'), build_num, client_dir)
|
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
version = load_version(build_num)
|
2012-11-18 06:58:34 +00:00
|
|
|
version_forge = '%d.%d.%d.%d' % (version['major'], version['minor'], version['revision'], version['build'])
|
2013-03-04 03:30:23 +00:00
|
|
|
version_mc = load_mc_version(fml_dir)
|
2012-12-04 02:15:38 +00:00
|
|
|
branch = get_branch_name()
|
2012-11-18 06:58:34 +00:00
|
|
|
|
|
|
|
version_str = '%s-%s' % (version_mc, version_forge)
|
2012-12-04 02:15:38 +00:00
|
|
|
if not branch == "":
|
|
|
|
version_str = '%s-%s' % (version_str, branch)
|
2012-08-01 23:35:35 +00:00
|
|
|
|
2013-07-02 04:42:33 +00:00
|
|
|
out_folder = os.path.join(forge_dir, 'target')
|
2013-07-16 20:55:31 +00:00
|
|
|
if not os.path.isdir(out_folder):
|
|
|
|
os.makedirs(out_folder)
|
|
|
|
|
|
|
|
for f in ['minecraftforge-changelog-%s.txt', 'minecraftforge-universal-%s.jar', 'minecraftforge-installer-%s.jar']:
|
|
|
|
fn = os.path.join(out_folder, f % version_str)
|
|
|
|
if os.path.isfile(fn):
|
|
|
|
os.remove(fn)
|
2012-11-18 06:58:34 +00:00
|
|
|
|
2012-12-07 21:42:32 +00:00
|
|
|
if not options.skip_changelog:
|
2013-07-02 04:42:33 +00:00
|
|
|
changelog_file = 'target/minecraftforge-changelog-%s.txt' % (version_str)
|
2013-06-02 23:26:06 +00:00
|
|
|
try:
|
2013-07-12 10:09:54 +00:00
|
|
|
make_changelog("http://ci.jenkins.minecraftforge.net/job/minecraftforge/", build_num, changelog_file, version_str)
|
2013-06-02 23:26:06 +00:00
|
|
|
except HTTPError, e:
|
|
|
|
print 'Changelog failed to generate: %s' % e
|
|
|
|
options.skip_changelog = True
|
2012-11-18 06:58:34 +00:00
|
|
|
|
2012-10-15 22:32:12 +00:00
|
|
|
version_file = 'forgeversion.properties'
|
|
|
|
if os.path.exists(version_file):
|
|
|
|
os.remove(version_file)
|
|
|
|
|
|
|
|
with open(version_file, 'wb') as fh:
|
|
|
|
fh.write('forge.major.number=%d\n' % version['major'])
|
|
|
|
fh.write('forge.minor.number=%d\n' % version['minor'])
|
|
|
|
fh.write('forge.revision.number=%d\n' % version['revision'])
|
|
|
|
fh.write('forge.build.number=%d\n' % version['build'])
|
2013-07-16 20:55:31 +00:00
|
|
|
|
|
|
|
json_data = gather_json(forge_dir, version_mc, version_forge, version_str)
|
2012-10-15 22:32:12 +00:00
|
|
|
|
2012-12-18 07:53:33 +00:00
|
|
|
if not options.sign_jar is None:
|
2013-07-02 04:42:33 +00:00
|
|
|
sign_jar(forge_dir, options.sign_jar, client_dir, 'minecraftforge-universal-%s.jar' % version_str)
|
2012-12-18 07:53:33 +00:00
|
|
|
else:
|
2013-07-02 04:42:33 +00:00
|
|
|
zip_start('minecraftforge-universal-%s.jar' % version_str)
|
2012-12-18 07:53:33 +00:00
|
|
|
zip_folder(client_dir, '', zip)
|
|
|
|
zip_add('MANIFEST.MF','META-INF/MANIFEST.MF')
|
2012-08-14 05:28:23 +00:00
|
|
|
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('install/Paulscode IBXM Library License.txt')
|
|
|
|
zip_add('install/Paulscode SoundSystem CodecIBXM License.txt')
|
2012-08-10 09:25:48 +00:00
|
|
|
zip_add('common/forge_at.cfg')
|
2013-08-28 11:59:45 +00:00
|
|
|
zip_add('common/assets','assets')
|
2012-10-15 22:32:12 +00:00
|
|
|
zip_add(version_file)
|
2012-12-10 23:43:19 +00:00
|
|
|
if not options.skip_changelog:
|
|
|
|
zip_add(changelog_file, 'MinecraftForge-Changelog.txt')
|
2013-07-16 20:55:31 +00:00
|
|
|
print(' version.json')
|
|
|
|
zip.writestr('version.json', json.dumps(json_data['versionInfo'], indent=4, separators=(',', ': ')))
|
2012-08-01 23:35:35 +00:00
|
|
|
|
2013-03-04 03:30:23 +00:00
|
|
|
#Add dependancy and licenses from FML
|
|
|
|
FML_FILES = [
|
|
|
|
'CREDITS-fml.txt',
|
|
|
|
'LICENSE-fml.txt',
|
|
|
|
'README-fml.txt',
|
|
|
|
'common/fml_at.cfg',
|
|
|
|
'common/fml_marker.cfg',
|
|
|
|
'common/fmlversion.properties',
|
|
|
|
'common/mcpmod.info',
|
2013-07-14 18:22:57 +00:00
|
|
|
'client/mcplogo.png',
|
2013-07-01 06:21:28 +00:00
|
|
|
'common/deobfuscation_data-%s.lzma' % version_mc
|
2013-03-04 03:30:23 +00:00
|
|
|
]
|
|
|
|
for file in FML_FILES:
|
|
|
|
zip_add(os.path.join(fml_dir, file))
|
|
|
|
|
|
|
|
zip_end()
|
2012-12-07 19:25:19 +00:00
|
|
|
|
2013-07-16 20:55:31 +00:00
|
|
|
build_installer(forge_dir, version_str, version_forge, version_mc, out_folder, json.dumps(json_data, indent=4, separators=(',', ': ')))
|
2013-07-02 04:42:33 +00:00
|
|
|
|
2012-08-10 01:37:52 +00:00
|
|
|
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')
|
2012-08-10 01:37:52 +00:00
|
|
|
zip_add('client', 'client')
|
|
|
|
zip_add('common', 'common')
|
|
|
|
zip_add('patches', 'patches')
|
2013-03-04 03:30:23 +00:00
|
|
|
zip_add(fml_dir, 'fml')
|
2012-12-04 02:15:38 +00:00
|
|
|
zip_add('install', '')
|
2012-08-01 23:35:35 +00:00
|
|
|
zip_add('forge.py')
|
2012-10-15 22:32:12 +00:00
|
|
|
zip_add(version_file)
|
2012-12-10 23:43:19 +00:00
|
|
|
if not options.skip_changelog:
|
|
|
|
zip_add(changelog_file, 'MinecraftForge-Changelog.txt')
|
2012-08-01 23:35:35 +00:00
|
|
|
zip_end()
|
2012-08-10 01:37:52 +00:00
|
|
|
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
|
|
|
|
2012-10-15 22:32:12 +00:00
|
|
|
if os.path.exists(version_file):
|
|
|
|
os.remove(version_file)
|
2013-03-04 03:30:23 +00:00
|
|
|
shutil.rmtree(temp_dir)
|
2013-07-03 13:26:47 +00:00
|
|
|
if os.path.isfile('MANIFEST.MF'):
|
|
|
|
os.remove('MANIFEST.MF')
|
2012-10-15 22:32:12 +00:00
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
print '=================================== Release Finished %d =================================' % error_level
|
|
|
|
sys.exit(error_level)
|
2013-07-16 20:55:31 +00:00
|
|
|
|
|
|
|
def gather_json(forge_dir, version_mc, version_forge, version_str):
|
2013-07-02 04:42:33 +00:00
|
|
|
def getTZ():
|
|
|
|
ret = '-'
|
|
|
|
t = time.timezone
|
|
|
|
if (t < 0):
|
|
|
|
ret = '+'
|
|
|
|
t *= -1
|
|
|
|
|
|
|
|
h = int(t/60/60)
|
|
|
|
t -= (h*60*60)
|
|
|
|
m = int(t/60)
|
|
|
|
return '%s%02d%02d' % (ret, h, m)
|
|
|
|
timestamp = datetime.now().replace(microsecond=0).isoformat() + getTZ()
|
2013-07-16 20:55:31 +00:00
|
|
|
json_data = {}
|
|
|
|
with closing(open(os.path.join(forge_dir, 'fml', 'jsons', '%s-rel.json' % version_mc), 'r')) as fh:
|
|
|
|
data = fh.read()
|
|
|
|
data = data.replace('@version@', version_forge)
|
|
|
|
data = data.replace('@timestamp@', timestamp)
|
|
|
|
data = data.replace('@minecraft_version@', version_mc)
|
|
|
|
data = data.replace('@universal_jar@', 'minecraftforge-universal-%s.jar' % version_str)
|
|
|
|
data = data.replace('FMLTweaker', 'F_M_L_Tweaker')
|
|
|
|
data = data.replace('FML', 'Forge')
|
|
|
|
data = data.replace('F_M_L_Tweaker', 'FMLTweaker')
|
|
|
|
data = data.replace('cpw.mods:fml:', 'net.minecraftforge:minecraftforge:')
|
|
|
|
json_data = json.loads(data)
|
|
|
|
pprint(json_data)
|
|
|
|
return json_data
|
|
|
|
|
|
|
|
def build_installer(forge_dir, version_str, version_forge, version_minecraft, out_folder, json_data):
|
|
|
|
file_name = 'minecraftforge-installer-%s.jar' % version_str
|
|
|
|
universal_name = 'minecraftforge-universal-%s.jar' % version_str
|
2013-07-02 04:42:33 +00:00
|
|
|
print '================== %s Start ==================' % file_name
|
|
|
|
with closing(zipfile.ZipFile(os.path.join(forge_dir, 'fml', 'installer_base.jar'), mode='a')) as zip_in:
|
|
|
|
with closing(zipfile.ZipFile(os.path.join(out_folder, file_name), 'w', zipfile.ZIP_DEFLATED)) as zip_out:
|
|
|
|
# Copy everything over
|
|
|
|
for i in zip_in.filelist:
|
|
|
|
if not i.filename in ['install_profile.json', 'big_logo.png']:
|
2013-07-16 20:55:31 +00:00
|
|
|
#print(' %s' % i.filename)
|
2013-07-02 04:42:33 +00:00
|
|
|
zip_out.writestr(i.filename, zip_in.read(i.filename))
|
|
|
|
print(' %s' % universal_name)
|
|
|
|
zip_out.write(os.path.join(out_folder, universal_name), universal_name)
|
|
|
|
print(' big_logo.png')
|
|
|
|
zip_out.write(os.path.join(forge_dir, 'client', 'forge_logo.png'), 'big_logo.png')
|
2013-07-16 20:55:31 +00:00
|
|
|
print(' install_profile.json')
|
|
|
|
zip_out.writestr('install_profile.json', json_data)
|
2013-07-02 04:42:33 +00:00
|
|
|
|
|
|
|
print '================== %s Finished ==================' % file_name
|
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
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):
|
2013-03-04 03:30:23 +00:00
|
|
|
print ' ' + key
|
2012-08-01 23:35:35 +00:00
|
|
|
zip.write(file, key)
|
|
|
|
|
|
|
|
def zip_start(name, base=None):
|
|
|
|
global zip, zip_name, zip_base
|
|
|
|
zip_name = name
|
|
|
|
|
2012-11-18 06:58:34 +00:00
|
|
|
print '================== %s Start ==================' % zip_name
|
2013-07-02 04:42:33 +00:00
|
|
|
zip_file = os.path.join(forge_dir, 'target', name)
|
2012-08-01 23:35:35 +00:00
|
|
|
zip = zipfile.ZipFile(zip_file, 'w', zipfile.ZIP_DEFLATED)
|
|
|
|
zip_base = base
|
|
|
|
|
|
|
|
def zip_end():
|
|
|
|
global zip, zip_name, zip_base
|
|
|
|
zip.close()
|
2012-11-18 06:58:34 +00:00
|
|
|
print '================== %s Finished ==================' % zip_name
|
2012-08-01 23:35:35 +00:00
|
|
|
zip_name = None
|
|
|
|
zip_base = None
|
|
|
|
|
2013-03-04 03:30:23 +00:00
|
|
|
def load_mc_version(fml_dir):
|
|
|
|
props = os.path.join(fml_dir, 'common', 'fmlversion.properties')
|
2012-11-18 06:58:34 +00:00
|
|
|
|
|
|
|
if not os.path.isfile(props):
|
|
|
|
print 'Could not load fmlversion.properties, build failed'
|
|
|
|
sys.exit(1)
|
2012-08-01 23:35:35 +00:00
|
|
|
|
2012-11-18 06:58:34 +00:00
|
|
|
with open(props, 'r') as fh:
|
|
|
|
for line in fh:
|
|
|
|
line = line.strip()
|
|
|
|
if line.startswith('fmlbuild.mcversion'):
|
|
|
|
return line.split('=')[1].strip()
|
|
|
|
|
|
|
|
print 'Could not load fmlversion.properties, build failed'
|
|
|
|
sys.exit(1)
|
|
|
|
|
2013-03-04 03:30:23 +00:00
|
|
|
def extract_fml_obfed(fml_dir, mcp_dir, reobf_dir, client_dir):
|
|
|
|
fml_file = os.path.join(fml_dir, 'difflist.txt')
|
2012-08-01 23:35:35 +00:00
|
|
|
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)):
|
2012-09-12 21:58:46 +00:00
|
|
|
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()
|
2012-12-04 02:15:38 +00:00
|
|
|
|
|
|
|
def get_branch_name():
|
|
|
|
from subprocess import Popen, PIPE, STDOUT
|
|
|
|
branch = ''
|
|
|
|
if os.getenv("GIT_BRANCH") is None:
|
|
|
|
try:
|
|
|
|
process = Popen(["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=PIPE, stderr=STDOUT, bufsize=-1)
|
|
|
|
branch, _ = process.communicate()
|
|
|
|
branch = branch.rstrip('\r\n')
|
|
|
|
except OSError:
|
|
|
|
print "Git not found"
|
|
|
|
else:
|
|
|
|
branch = os.getenv("GIT_BRANCH").rpartition('/')[2]
|
|
|
|
branch = branch.replace('master', '')
|
2012-12-06 03:09:01 +00:00
|
|
|
branch = branch.replace('HEAD', '')
|
2012-12-04 02:15:38 +00:00
|
|
|
print 'Detected Branch as \'%s\'' % branch
|
|
|
|
return branch
|
2012-12-18 07:53:33 +00:00
|
|
|
|
|
|
|
def sign_jar(forge_dir, command, files, dest_zip):
|
|
|
|
from subprocess import Popen, PIPE, STDOUT
|
|
|
|
global zip
|
|
|
|
zip_file = os.path.join(forge_dir, 'tmp.jar')
|
|
|
|
|
2012-12-18 08:21:24 +00:00
|
|
|
if os.path.isfile(zip_file):
|
|
|
|
os.remove(zip_file)
|
|
|
|
|
2012-12-18 07:53:33 +00:00
|
|
|
print '============== Creating tmp zip to sign ====================='
|
|
|
|
zf = zipfile.ZipFile(zip_file, 'w', zipfile.ZIP_DEFLATED)
|
|
|
|
zf.write(os.path.join(forge_dir, 'MANIFEST.MF'), 'META-INF/MANIFEST.MF')
|
|
|
|
zip_folder_filter(files, '', zf, 'cpw/mods/'.replace('/', os.sep))
|
|
|
|
zip_folder_filter(files, '', zf, 'net/minecraftforge/'.replace('/', os.sep))
|
|
|
|
zf.close()
|
|
|
|
print '================ End tmp zip to sign ========================'
|
|
|
|
|
|
|
|
try:
|
|
|
|
process = Popen([command, zip_file, "forge"], stdout=PIPE, stderr=STDOUT, bufsize=-1)
|
|
|
|
out, _ = process.communicate()
|
|
|
|
print out
|
2012-12-18 08:21:24 +00:00
|
|
|
except OSError as e:
|
|
|
|
print "Error creating signed tmp jar: %s" % e.strerror
|
2012-12-18 07:53:33 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
tmp_dir = os.path.join(forge_dir, 'tmp')
|
|
|
|
if os.path.isdir(tmp_dir):
|
|
|
|
shutil.rmtree(tmp_dir)
|
|
|
|
|
|
|
|
zf = zipfile.ZipFile(zip_file)
|
|
|
|
zf.extractall(tmp_dir)
|
|
|
|
zf.close()
|
|
|
|
os.remove(zip_file)
|
2012-09-12 21:58:46 +00:00
|
|
|
|
2012-12-18 07:53:33 +00:00
|
|
|
zip_start(dest_zip)
|
|
|
|
zip_folder(tmp_dir, '', zip)
|
|
|
|
zip_folder(files, '', zip)
|
|
|
|
|
|
|
|
if os.path.isdir(tmp_dir):
|
|
|
|
shutil.rmtree(tmp_dir)
|
|
|
|
|
|
|
|
def zip_folder_filter(path, key, zip, filter):
|
|
|
|
files = os.listdir(path)
|
|
|
|
for file in files:
|
|
|
|
file_path = os.path.join(path, file)
|
|
|
|
file_key = os.path.join(key, file)
|
|
|
|
if os.path.isdir(file_path):
|
|
|
|
zip_folder_filter(file_path, file_key, zip, filter)
|
|
|
|
else:
|
|
|
|
if file_key.startswith(filter):
|
|
|
|
print file_key
|
|
|
|
zip.write(file_path, file_key)
|
|
|
|
|
2013-07-01 06:21:28 +00:00
|
|
|
def gen_bin_patches(mcp_dir, fml_dir, build_num, client_dir):
|
|
|
|
print('Creating Binary patches')
|
|
|
|
os.environ['WORKSPACE'] = os.path.join(mcp_dir, '..')
|
|
|
|
os.environ['BUILD_NUMBER'] = str(build_num)
|
|
|
|
|
|
|
|
BUILD = ['ant', 'makebinpatches']
|
|
|
|
if sys.platform.startswith('win'):
|
|
|
|
BUILD = ['cmd', '/C'] + BUILD
|
|
|
|
|
|
|
|
if not run_command(BUILD, cwd=fml_dir):
|
|
|
|
print('Could not crate binary patches')
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
fml_lzma = os.path.join(fml_dir, 'binpatches.pack.lzma')
|
|
|
|
obf_lzma = os.path.join(client_dir, 'binpatches.pack.lzma')
|
|
|
|
shutil.move(fml_lzma, obf_lzma)
|
|
|
|
|
|
|
|
def run_command(command, cwd='.', verbose=True):
|
|
|
|
print('Running command: ')
|
|
|
|
print(pformat(command))
|
|
|
|
|
|
|
|
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, cwd=cwd)
|
|
|
|
while process.poll() is None:
|
|
|
|
line = process.stdout.readline()
|
|
|
|
if line:
|
|
|
|
line = line.rstrip()
|
|
|
|
print(line)
|
|
|
|
if process.returncode:
|
|
|
|
print "failed: {0}".format(process.returncode)
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|