2012-12-04 02:15:38 +00:00
|
|
|
import os, os.path, sys, zipfile
|
2013-03-04 03:30:23 +00:00
|
|
|
import shutil, glob, fnmatch, subprocess
|
|
|
|
from pprint import pformat
|
2012-12-04 02:15:38 +00:00
|
|
|
from optparse import OptionParser
|
2012-08-01 23:35:35 +00:00
|
|
|
|
|
|
|
forge_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
2012-08-15 06:57:16 +00:00
|
|
|
from forge import apply_forge_patches
|
2012-08-01 23:35:35 +00:00
|
|
|
|
|
|
|
def main():
|
|
|
|
print '=================================== Setup Start ================================='
|
2012-12-04 02:15:38 +00:00
|
|
|
|
|
|
|
parser = OptionParser()
|
|
|
|
parser.add_option('-m', '--mcp-dir', action='store', dest='mcp_dir', help='Path to download/extract MCP to', default=None)
|
2013-03-04 03:30:23 +00:00
|
|
|
parser.add_option('-b', '--build', action='store', dest='build', help='Build number', default=None)
|
2012-12-04 02:15:38 +00:00
|
|
|
options, _ = parser.parse_args()
|
|
|
|
|
2013-03-04 03:30:23 +00:00
|
|
|
build_num = 0
|
|
|
|
if not options.build is None:
|
|
|
|
try:
|
|
|
|
build_num = int(options.build)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2012-12-04 02:15:38 +00:00
|
|
|
fml_dir = os.path.join(forge_dir, 'fml')
|
|
|
|
mcp_dir = os.path.join(forge_dir, 'mcp')
|
|
|
|
|
|
|
|
if not options.mcp_dir is None:
|
|
|
|
mcp_dir = os.path.abspath(options.mcp_dir)
|
|
|
|
|
|
|
|
src_dir = os.path.join(mcp_dir, 'src')
|
|
|
|
|
2013-03-04 03:30:23 +00:00
|
|
|
setup_fml(mcp_dir, fml_dir, build_num)
|
2012-08-01 23:35:35 +00:00
|
|
|
|
|
|
|
base_dir = os.path.join(mcp_dir, 'src_base')
|
|
|
|
work_dir = os.path.join(mcp_dir, 'src_work')
|
|
|
|
|
|
|
|
if os.path.isdir(base_dir):
|
|
|
|
shutil.rmtree(base_dir)
|
|
|
|
if os.path.isdir(work_dir):
|
|
|
|
shutil.rmtree(work_dir)
|
|
|
|
|
|
|
|
print 'Setting up source directories'
|
|
|
|
shutil.copytree(src_dir, base_dir)
|
|
|
|
shutil.copytree(src_dir, work_dir)
|
|
|
|
|
|
|
|
print 'Applying forge patches'
|
2013-03-04 03:30:23 +00:00
|
|
|
apply_forge_patches(fml_dir, mcp_dir, forge_dir, work_dir, False)
|
2012-08-01 23:35:35 +00:00
|
|
|
|
2012-12-09 22:09:11 +00:00
|
|
|
setup_eclipse(forge_dir)
|
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
print '=================================== Setup Finished ================================='
|
|
|
|
|
2013-03-04 03:30:23 +00:00
|
|
|
def setup_fml(mcp_dir, fml_dir, build_num=0):
|
2012-08-01 23:35:35 +00:00
|
|
|
print 'Setting up Forge ModLoader'
|
2013-07-01 19:30:19 +00:00
|
|
|
os.environ['WORKSPACE'] = os.path.abspath(os.path.join(mcp_dir, '..'))
|
2013-03-04 03:30:23 +00:00
|
|
|
os.environ['BUILD_NUMBER'] = str(build_num)
|
|
|
|
|
|
|
|
BUILD = ['ant', 'jenkinsbuild']
|
|
|
|
if sys.platform.startswith('win'):
|
|
|
|
BUILD = ['cmd', '/C'] + BUILD
|
|
|
|
|
|
|
|
if not run_command(BUILD, cwd=fml_dir):
|
|
|
|
print('Could not setup FML')
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
sys.path.append(fml_dir)
|
|
|
|
sys.path.append(os.path.join(fml_dir, 'install'))
|
|
|
|
from fml import finish_setup_fml
|
|
|
|
finish_setup_fml(fml_dir, mcp_dir)
|
2013-03-05 00:33:02 +00:00
|
|
|
|
|
|
|
print('Copy resources:')
|
2013-03-05 01:17:15 +00:00
|
|
|
copy_files(os.path.join(fml_dir, 'client'), os.path.join(mcp_dir, 'src', 'minecraft'))
|
|
|
|
copy_files(os.path.join(fml_dir, 'common'), os.path.join(mcp_dir, 'src', 'minecraft'))
|
2013-03-04 03:30:23 +00:00
|
|
|
|
2013-03-05 00:33:02 +00:00
|
|
|
name = 'fmlversion.properties'
|
|
|
|
print(' ' + name)
|
2013-03-05 01:17:15 +00:00
|
|
|
shutil.copy(os.path.join(fml_dir, name), os.path.join(mcp_dir, 'src', 'minecraft', name))
|
|
|
|
|
|
|
|
def copy_files(src_dir, dest_dir):
|
|
|
|
for file in glob.glob(os.path.join(src_dir, '*')):
|
|
|
|
if not os.path.isfile(file) or file.lower().endswith('.java'):
|
|
|
|
continue
|
|
|
|
print(' ' + file)
|
|
|
|
shutil.copy(file, os.path.join(dest_dir, os.path.basename(file)))
|
2013-03-05 00:33:02 +00:00
|
|
|
|
2013-03-04 03:30:23 +00:00
|
|
|
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:
|
2013-04-29 16:18:05 +00:00
|
|
|
print "failed: {0}".format(process.returncode)
|
2013-03-04 03:30:23 +00:00
|
|
|
return False
|
|
|
|
return True
|
2012-08-01 23:35:35 +00:00
|
|
|
|
2012-12-09 22:09:11 +00:00
|
|
|
def setup_eclipse(forge_dir):
|
|
|
|
eclipse_dir = os.path.join(forge_dir, 'eclipse')
|
|
|
|
eclipse_zip = os.path.join(forge_dir, 'eclipse-workspace-dev.zip')
|
|
|
|
|
|
|
|
if not os.path.isdir(eclipse_dir) and os.path.isfile(eclipse_zip):
|
|
|
|
print 'Extracting Dev Workspace'
|
|
|
|
zf = zipfile.ZipFile(eclipse_zip)
|
|
|
|
zf.extractall(forge_dir)
|
|
|
|
zf.close()
|
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
if __name__ == '__main__':
|
2013-03-03 19:05:34 +00:00
|
|
|
main()
|