-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssemble 1.6.2.py
143 lines (114 loc) · 4.3 KB
/
Assemble 1.6.2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python
#-------------------------------------------------------------------------------
# Assemble.py
# Prepares mod to be distributed by packaging the mod
# archive and source archives.
#
# This file, both in source code form or as a compiled binary, is free and
# released into the public domain.
#-------------------------------------------------------------------------------
import os
import sys
import shutil
import zipfile
import subprocess
import traceback
import time
releaseVersion = ""
baseFolder = os.getcwd() + "/"
projectFolder = baseFolder + "Forge/1.6.2/mcp/"
buildFolder = baseFolder + "Build/"
reobfFolder = projectFolder + "/reobf/minecraft/bashpack/"
sourceFolder = projectFolder + "/modsrc/minecraft/bashpack/"
assetsFolder = projectFolder + "/src/minecraft/assets/"
def main():
print "---------------------------------------------"
print "BashPack Bacon Mod Packaging Script"
print "---------------------------------------------"
#Get release version
releaseVersion = raw_input("Enter version: ")
#Check whether to run MCP again or not.
choice = raw_input("Run MCP? [Y/N]: ")
if (choice == "Y" or choice == "y"):
os.chdir(projectFolder)
insertBlank()
recompile()
reobfuscate()
#Clear the build folder
if (os.path.exists(buildFolder)):
print "Removing build folder..."
shutil.rmtree(buildFolder)
print "Waiting to continue..."
time.sleep(1)
os.mkdir(buildFolder)
insertBlank()
print "---------------------------------------"
print "Packaging release archive..."
print "---------------------------------------"
insertBlank()
#Zip up the mod archive.
modArchive = zipfile.ZipFile(buildFolder + "/BashPack " + releaseVersion + " for 1.6.2.zip", "w", zipfile.ZIP_DEFLATED)
modFiles = os.listdir(buildFolder)
modArchive.write(projectFolder + "src/minecraft/bashpack.png", "bashpack.png")
modArchive.write(projectFolder + "src/minecraft/mcmod.info", "mcmod.info")
modArchive.write(baseFolder + "LICENSE", "_LICENSE.txt")
print "Zipping assets..."
for root, dirs, files in os.walk(assetsFolder):
for fileName in files:
fullPath = os.path.join(root, fileName)
modArchive.write(fullPath, fullPath.replace(assetsFolder, "assets/"))
print "Zipping compiled classes..."
for root, dirs, files in os.walk(reobfFolder):
for fileName in files:
fullPath = os.path.join(root, fileName)
modArchive.write(fullPath, fullPath.replace(reobfFolder, "bashpack/"))
modArchive.close()
#Zip up the source.
linesOfCode = 0
print "Zipping up source archive..."
getSource()
sourceArchive = zipfile.ZipFile(buildFolder + "/BashPack " + releaseVersion + " for 1.6.2 - Source.zip", "w", zipfile.ZIP_DEFLATED)
sourceFiles = os.listdir(sourceFolder)
for root, dirs, files in os.walk(sourceFolder):
for fileName in files:
containsCorrectHeader = True
fullPath = os.path.join(root, fileName)
archiveName = fullPath.replace(sourceFolder, "bashpack/")
sourceArchive.write(fullPath, archiveName)
with open(fullPath) as f:
lines = f.readlines()
for line in lines:
linesOfCode += 1
if fileName in lines:
containsCorrectHeader = True
if not containsCorrectHeader:
print "WARNING: Malformed header on " + fileName + "."
print str(linesOfCode) + " lines."
insertBlank()
sourceArchive.close()
print "--------------------------"
print "Packaging complete."
print "--------------------------"
os.system("pause")
def recompile():
os.chdir(projectFolder)
subprocess.call("recompile.bat")
insertBlank()
def reobfuscate():
os.chdir(projectFolder)
subprocess.call("reobfuscate.bat")
insertBlank()
def getSource():
os.chdir(projectFolder)
subprocess.call("getchangedsrc.bat")
insertBlank()
def insertBlank():
print ""
if __name__ == "__main__":
try:
main()
except Exception as e:
print "!!!!!!!!!!!!Unexpected exception!!!!!!!!!!!!"
print e
traceback.print_exc()
os.system("pause")