Implement a --version option to overviewer
Should also work with py2exe binary kits
This commit is contained in:
@@ -49,6 +49,23 @@ helptext = """
|
|||||||
%prog [OPTIONS] <World # / Name / Path to World> <tiles dest dir>
|
%prog [OPTIONS] <World # / Name / Path to World> <tiles dest dir>
|
||||||
%prog -d <World # / Name / Path to World / Path to cache dir> [tiles dest dir]"""
|
%prog -d <World # / Name / Path to World / Path to cache dir> [tiles dest dir]"""
|
||||||
|
|
||||||
|
|
||||||
|
def findGitVersion():
|
||||||
|
if os.path.exists(".git"):
|
||||||
|
with open(os.path.join(".git","HEAD")) as f:
|
||||||
|
data = f.read().strip()
|
||||||
|
if data.startswith("ref: "):
|
||||||
|
with open(os.path.join(".git", data[5:])) as g:
|
||||||
|
return g.read().strip()
|
||||||
|
else:
|
||||||
|
return data
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
import overviewer_version
|
||||||
|
return overviewer_version.VERSION
|
||||||
|
except:
|
||||||
|
return "unknown"
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
cpus = multiprocessing.cpu_count()
|
cpus = multiprocessing.cpu_count()
|
||||||
@@ -56,6 +73,7 @@ def main():
|
|||||||
cpus = 1
|
cpus = 1
|
||||||
|
|
||||||
parser = ConfigOptionParser(usage=helptext, config="settings.py")
|
parser = ConfigOptionParser(usage=helptext, config="settings.py")
|
||||||
|
parser.add_option("-V", "--version", dest="version", help="Displays version information and then exits", action="store_true")
|
||||||
parser.add_option("-p", "--processes", dest="procs", help="How many worker processes to start. Default %s" % cpus, default=cpus, action="store", type="int")
|
parser.add_option("-p", "--processes", dest="procs", help="How many worker processes to start. Default %s" % cpus, default=cpus, action="store", type="int")
|
||||||
parser.add_option("-z", "--zoom", dest="zoom", help="Sets the zoom level manually instead of calculating it. This can be useful if you have outlier chunks that make your world too big. This value will make the highest zoom level contain (2**ZOOM)^2 tiles", action="store", type="int", configFileOnly=True)
|
parser.add_option("-z", "--zoom", dest="zoom", help="Sets the zoom level manually instead of calculating it. This can be useful if you have outlier chunks that make your world too big. This value will make the highest zoom level contain (2**ZOOM)^2 tiles", action="store", type="int", configFileOnly=True)
|
||||||
parser.add_option("-d", "--delete", dest="delete", help="Clear all caches. Next time you render your world, it will have to start completely over again. This is probably not a good idea for large worlds. Use this if you change texture packs and want to re-render everything.", action="store_true", commandLineOnly=True)
|
parser.add_option("-d", "--delete", dest="delete", help="Clear all caches. Next time you render your world, it will have to start completely over again. This is probably not a good idea for large worlds. Use this if you change texture packs and want to re-render everything.", action="store_true", commandLineOnly=True)
|
||||||
@@ -72,6 +90,18 @@ def main():
|
|||||||
|
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
|
|
||||||
|
if options.version:
|
||||||
|
print "Minecraft-Overviewer"
|
||||||
|
print "Git version: %s" % findGitVersion()
|
||||||
|
try:
|
||||||
|
import overviewer_version
|
||||||
|
if hasattr(sys, "frozen"):
|
||||||
|
print "py2exe version build on %s" % overviewer_version.BUILD_DATE
|
||||||
|
print "Build machine: %s %s" % (overviewer_version.BUILD_PLATFORM, overviewer_version.BUILD_OS)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if len(args) < 1:
|
if len(args) < 1:
|
||||||
print "You need to give me your world number or directory"
|
print "You need to give me your world number or directory"
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|||||||
19
setup.py
19
setup.py
@@ -7,6 +7,7 @@ from distutils import log
|
|||||||
import os, os.path
|
import os, os.path
|
||||||
import glob
|
import glob
|
||||||
import platform
|
import platform
|
||||||
|
import time
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import py2exe
|
import py2exe
|
||||||
@@ -88,10 +89,26 @@ class CustomBuild(build_ext):
|
|||||||
build_ext.build_extensions(self)
|
build_ext.build_extensions(self)
|
||||||
|
|
||||||
|
|
||||||
|
if py2exe is not None:
|
||||||
|
# define a subclass of py2exe to build our version file on the fly
|
||||||
|
class CustomPy2exe(py2exe.build_exe.py2exe):
|
||||||
|
def run(self):
|
||||||
|
try:
|
||||||
|
import overviewer
|
||||||
|
f = open("overviewer_version.py", "w")
|
||||||
|
f.write("VERSION=%r\n" % overviewer.findGitVersion())
|
||||||
|
f.write("BUILD_DATE=%r\n" % time.asctime())
|
||||||
|
f.write("BUILD_PLATFORM=%r\n" % platform.processor())
|
||||||
|
f.write("BUILD_OS=%r\n" % platform.platform())
|
||||||
|
f.close()
|
||||||
|
setup_kwargs['data_files'].append(('.', ['overviewer_version.py']))
|
||||||
|
except:
|
||||||
|
print "WARNING: failed to build overview_version file"
|
||||||
|
py2exe.build_exe.py2exe.run(self)
|
||||||
|
setup_kwargs['cmdclass']['py2exe'] = CustomPy2exe
|
||||||
|
|
||||||
setup_kwargs['cmdclass']['clean'] = CustomClean
|
setup_kwargs['cmdclass']['clean'] = CustomClean
|
||||||
setup_kwargs['cmdclass']['build_ext'] = CustomBuild
|
setup_kwargs['cmdclass']['build_ext'] = CustomBuild
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
setup(**setup_kwargs)
|
setup(**setup_kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user