From 99932f35a3eb67b7c434602b7b0d2fe7855e4cf7 Mon Sep 17 00:00:00 2001 From: Andrew Chin Date: Wed, 17 Aug 2011 09:16:39 -0400 Subject: [PATCH] Minor changes to the contrib manager add --list-contribs option construct sys.argv correctly for the contrib scripts --- contribManager.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/contribManager.py b/contribManager.py index 7f1ab3f..f750b90 100755 --- a/contribManager.py +++ b/contribManager.py @@ -5,6 +5,8 @@ import sys import os.path +sys.path.append("overviewer_core") +import nbt scripts=dict( # keys are names, values are scripts benchmark="benchmark.py", @@ -12,6 +14,12 @@ scripts=dict( # keys are names, values are scripts validate="validateRegionFile.py" ) +# you can symlink or hardlink contribManager.py to another name to have it +# automatically find the right script to run. For example: +# > ln -s contribManager.py validate.exe +# > chmod +x validate.exe +# > ./validate.exe -h + # figure out what script to execute argv=os.path.basename(sys.argv[0]) @@ -21,18 +29,26 @@ if argv[-4:] == ".exe": if argv[-3:] == ".py": argv=argv[0:-3] -print "argv is ", argv - if argv in scripts.keys(): script = scripts[argv] + sys.argv[0] = script else: - if sys.argv[1] in scripts.keys(): + if "--list-contribs" in sys.argv: + print scripts.keys() + sys.exit(0) + if len(sys.argv) > 1 and sys.argv[1] in scripts.keys(): script = scripts[sys.argv[1]] + sys.argv = [script] + sys.argv[2:] else: print "what do you want to run?" sys.exit(1) -print "running", script +torun = os.path.join("contrib", script) + +if not os.path.exists(torun): + print "Script '%s' is missing!" % script + sys.exit(1) + +execfile(torun) -execfile(os.path.join("contrib", script))