ForgePatch/fml/getversion.py

77 lines
2.5 KiB
Python
Raw Normal View History

2012-05-10 16:24:17 +00:00
import sys
import os
import commands
import fnmatch
import re
import subprocess, shlex
2012-07-02 16:24:37 +00:00
mcp_home = sys.argv[1]
mcp_dir = os.path.abspath(mcp_home)
print(mcp_dir)
sys.path.append(mcp_dir)
from runtime.commands import Commands
Commands._version_config = os.path.join(mcp_dir,Commands._version_config)
2012-05-10 16:24:17 +00:00
def cmdsplit(args):
if os.sep == '\\':
args = args.replace('\\', '\\\\')
return shlex.split(args)
def cleanDirs(path):
if not os.path.isdir(path):
return
files = os.listdir(path)
if len(files):
for f in files:
fullpath = os.path.join(path, f)
if os.path.isdir(fullpath):
cleanDirs(fullpath)
files = os.listdir(path)
if len(files) == 0:
os.rmdir(path)
def main():
print("Obtaining version information from git")
2012-05-10 16:53:27 +00:00
cmd = "git describe --long --match='[^(jenkins)]*'"
2012-05-10 16:24:17 +00:00
try:
process = subprocess.Popen(cmdsplit(cmd), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1)
vers, _ = process.communicate()
except OSError:
print("Git not found")
vers="v1.0-0-deadbeef"
(major,minor,rev,githash)=re.match("v(\d+).(\d+)-(\d+)-(.*)",vers).groups()
2012-07-02 16:24:37 +00:00
(mcpversion,mcclientversion,mcserverversion) = re.match("[.\w]+ \(data: ([.\w]+), client: ([.\w.]+), server: ([.\w.]+)\)",Commands.fullversion()).groups()
if os.getenv("GIT_BRANCH") is None:
2012-12-04 04:44:35 +00:00
cmd = "git rev-parse --abbrev-ref HEAD"
try:
process = subprocess.Popen(cmdsplit(cmd), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1)
branch, _ = process.communicate()
2012-12-16 03:37:32 +00:00
branch = branch.strip()
2012-12-04 04:44:35 +00:00
except OSError:
print("Git not found")
branch="master"
else:
2012-12-03 13:30:44 +00:00
branch=os.getenv("GIT_BRANCH").rpartition('/')[2]
2012-12-04 04:44:35 +00:00
if branch == 'HEAD':
branch = "master"
2012-05-10 16:24:17 +00:00
with open("fmlversion.properties","w") as f:
f.write("%s=%s\n" %("fmlbuild.major.number",major))
f.write("%s=%s\n" %("fmlbuild.minor.number",minor))
f.write("%s=%s\n" %("fmlbuild.revision.number",rev))
f.write("%s=%s\n" %("fmlbuild.githash",githash))
2012-07-02 16:24:37 +00:00
f.write("%s=%s\n" %("fmlbuild.mcpversion",mcpversion))
f.write("%s=%s\n" %("fmlbuild.mcversion",mcclientversion))
f.write("%s=%s\n" %("fmlbuild.branch",branch))
2012-07-02 16:24:37 +00:00
print("Version information: FML %s.%s.%s (%s) using MCP %s for minecraft %s" % (major, minor, rev, branch, mcpversion, mcclientversion))
2012-05-10 16:24:17 +00:00
if __name__ == '__main__':
main()