0

Add new option "--advanced-help". Options previously marked

configFileOnly are now marked as "advanced" and will not appear in
default help text.
This commit is contained in:
Thomas Lake
2011-08-15 17:02:19 +01:00
parent 547e87dd02
commit 8c87fa6bb5
2 changed files with 57 additions and 37 deletions

View File

@@ -98,27 +98,28 @@ def main():
avail_rendermodes = c_overviewer.get_render_modes() avail_rendermodes = c_overviewer.get_render_modes()
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("-V", "--version", dest="version", helptext="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", helptext="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", helptext="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", advanced=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", helptext="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("--regionlist", dest="regionlist", help="A file containing, on each line, a path to a regionlist to update. Instead of scanning the world directory for regions, it will just use this list. Normal caching rules still apply.") parser.add_option("--regionlist", dest="regionlist", helptext="A file containing, on each line, a path to a regionlist to update. Instead of scanning the world directory for regions, it will just use this list. Normal caching rules still apply.")
parser.add_option("--forcerender", dest="forcerender", help="Force re-rendering the entire map (or the given regionlist). Useful for re-rendering without deleting the entire map with --delete.", action="store_true") parser.add_option("--forcerender", dest="forcerender", helptext="Force re-rendering the entire map (or the given regionlist). Useful for re-rendering without deleting the entire map with --delete.", action="store_true")
parser.add_option("--rendermodes", dest="rendermode", help="Specifies the render types, separated by commas. Use --list-rendermodes to list them all.", type="choice", choices=avail_rendermodes, required=True, default=avail_rendermodes[0], listify=True) parser.add_option("--rendermodes", dest="rendermode", helptext="Specifies the render types, separated by commas. Use --list-rendermodes to list them all.", type="choice", choices=avail_rendermodes, required=True, default=avail_rendermodes[0], listify=True)
parser.add_option("--list-rendermodes", dest="list_rendermodes", action="store_true", help="List available render modes and exit.", commandLineOnly=True) parser.add_option("--list-rendermodes", dest="list_rendermodes", action="store_true", helptext="List available render modes and exit.", commandLineOnly=True)
parser.add_option("--imgformat", dest="imgformat", help="The image output format to use. Currently supported: png(default), jpg.", configFileOnly=True ) parser.add_option("--imgformat", dest="imgformat", helptext="The image output format to use. Currently supported: png(default), jpg.", advanced=True )
parser.add_option("--imgquality", dest="imgquality", default=95, help="Specify the quality of image output when using imgformat=\"jpg\".", type="int", configFileOnly=True) parser.add_option("--imgquality", dest="imgquality", default=95, helptext="Specify the quality of image output when using imgformat=\"jpg\".", type="int", advanced=True)
parser.add_option("--bg_color", dest="bg_color", help="Configures the background color for the GoogleMap output. Specify in #RRGGBB format", configFileOnly=True, type="string", default="#1A1A1A") parser.add_option("--bg_color", dest="bg_color", helptext="Configures the background color for the GoogleMap output. Specify in #RRGGBB format", advanced=True, type="string", default="#1A1A1A")
parser.add_option("--optimize-img", dest="optimizeimg", help="If using png, perform image file size optimizations on the output. Specify 1 for pngcrush, 2 for pngcrush+advdef and 3 for pngcrush-advdef with more agressive settings. This may double (or more) render times, but will produce up to 30% smaller images. NOTE: requires corresponding programs in $PATH or %PATH%", configFileOnly=True) parser.add_option("--optimize-img", dest="optimizeimg", helptext="If using png, perform image file size optimizations on the output. Specify 1 for pngcrush, 2 for pngcrush+advdef and 3 for pngcrush-advdef with more agressive settings. This may double (or more) render times, but will produce up to 30% smaller images. NOTE: requires corresponding programs in $PATH or %PATH%", advanced=True)
parser.add_option("--web-assets-hook", dest="web_assets_hook", help="If provided, run this function after the web assets have been copied, but before actual tile rendering begins. It should accept a QuadtreeGen object as its only argument.", action="store", metavar="SCRIPT", type="function", configFileOnly=True) parser.add_option("--web-assets-hook", dest="web_assets_hook", helptext="If provided, run this function after the web assets have been copied, but before actual tile rendering begins. It should accept a QuadtreeGen object as its only argument.", action="store", metavar="SCRIPT", type="function", advanced=True)
parser.add_option("--web-assets-path", dest="web_assets_path", help="Specifies a non-standard web_assets directory to use. Files here will overwrite the default web assets.", metavar="PATH", type="string", configFileOnly=True) parser.add_option("--web-assets-path", dest="web_assets_path", helptext="Specifies a non-standard web_assets directory to use. Files here will overwrite the default web assets.", metavar="PATH", type="string", advanced=True)
parser.add_option("--textures-path", dest="textures_path", help="Specifies a non-standard textures path, from which terrain.png and other textures are loaded.", metavar="PATH", type="string", configFileOnly=True) parser.add_option("--textures-path", dest="textures_path", helptext="Specifies a non-standard textures path, from which terrain.png and other textures are loaded.", metavar="PATH", type="string", advanced=True)
parser.add_option("-q", "--quiet", dest="quiet", action="count", default=0, help="Print less output. You can specify this option multiple times.") parser.add_option("-q", "--quiet", dest="quiet", action="count", default=0, helptext="Print less output. You can specify this option multiple times.")
parser.add_option("-v", "--verbose", dest="verbose", action="count", default=0, help="Print more output. You can specify this option multiple times.") parser.add_option("-v", "--verbose", dest="verbose", action="count", default=0, helptext="Print more output. You can specify this option multiple times.")
parser.add_option("--skip-js", dest="skipjs", action="store_true", help="Don't output marker.js or regions.js") parser.add_option("--skip-js", dest="skipjs", action="store_true", helptext="Don't output marker.js or regions.js")
parser.add_option("--no-signs", dest="nosigns", action="store_true", help="Don't output signs to markers.js") parser.add_option("--no-signs", dest="nosigns", action="store_true", helptext="Don't output signs to markers.js")
parser.add_option("--display-config", dest="display_config", action="store_true", help="Display the configuration parameters, but don't render the map. Requires all required options to be specified", commandLineOnly=True) parser.add_option("--display-config", dest="display_config", action="store_true", helptext="Display the configuration parameters, but don't render the map. Requires all required options to be specified", commandLineOnly=True)
#parser.add_option("--write-config", dest="write_config", action="store_true", help="Writes out a sample config file", commandLineOnly=True) parser.add_option("--advanced-help", dest="advanced_help", action="store_true", helptext="Display help - including advanced options", commandLineOnly=True)
#parser.add_option("--write-config", dest="write_config", action="store_true", helptext="Writes out a sample config file", commandLineOnly=True)
options, args = parser.parse_args() options, args = parser.parse_args()
@@ -142,6 +143,10 @@ def main():
print "{name:{0}} {description}".format(name_width, **info) print "{name:{0}} {description}".format(name_width, **info)
sys.exit(0) sys.exit(0)
if options.advanced_help:
parser.advanced_help()
sys.exit(0)
if len(args) < 1: if len(args) < 1:
logging.error("You need to give me your world number or directory") logging.error("You need to give me your world number or directory")
parser.print_help() parser.print_help()

View File

@@ -1,4 +1,4 @@
from optparse import OptionParser import optparse
import sys import sys
import os.path import os.path
import logging import logging
@@ -9,22 +9,22 @@ class OptionsResults(object):
class ConfigOptionParser(object): class ConfigOptionParser(object):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.cmdParser = OptionParser(usage=kwargs.get("usage","")) self.cmdParser = optparse.OptionParser(usage=kwargs.get("usage",""))
self.configFile = kwargs.get("config","settings.py") self.configFile = kwargs.get("config","settings.py")
self.configVars = [] self.configVars = []
self.advancedHelp = []
# these are arguments not understood by OptionParser, so they must be removed # these are arguments not understood by OptionParser, so they must be removed
# in add_option before being passed to the OptionParser # in add_option before being passed to the OptionParser
# note that default is a valid OptionParser argument, but we remove it # note that default is a valid OptionParser argument, but we remove it
# because we want to do our default value handling # because we want to do our default value handling
self.customArgs = ["required", "commandLineOnly", "default", "listify", "listdelim", "choices"] self.customArgs = ["required", "commandLineOnly", "default", "listify", "listdelim", "choices", "helptext", "advanced"]
self.requiredArgs = [] self.requiredArgs = []
# add the *very* special config-file path option # add the *very* special config-file path option
self.add_option("--settings", dest="config_file", help="Specifies a settings file to load, by name. This file's format is discussed in the README.", metavar="PATH", type="string", commandLineOnly=True) self.add_option("--settings", dest="config_file", helptext="Specifies a settings file to load, by name. This file's format is discussed in the README.", metavar="PATH", type="string", commandLineOnly=True)
def display_config(self): def display_config(self):
logging.info("Using the following settings:") logging.info("Using the following settings:")
@@ -35,22 +35,37 @@ class ConfigOptionParser(object):
def add_option(self, *args, **kwargs): def add_option(self, *args, **kwargs):
if kwargs.get("configFileOnly", False) and kwargs.get("commandLineOnly", False):
raise Exception(args, "configFileOnly and commandLineOnly are mututally exclusive")
self.configVars.append(kwargs.copy()) self.configVars.append(kwargs.copy())
if not kwargs.get("configFileOnly", False): if kwargs.get("advanced"):
kwargs['help'] = optparse.SUPPRESS_HELP
self.advancedHelp.append((args, kwargs.copy()))
else:
kwargs["help"]=kwargs["helptext"]
for arg in self.customArgs: for arg in self.customArgs:
if arg in kwargs.keys(): del kwargs[arg] if arg in kwargs.keys(): del kwargs[arg]
if kwargs.get("type", None): if kwargs.get("type", None):
kwargs['type'] = 'string' # we'll do our own converting later kwargs['type'] = 'string' # we'll do our own converting later
self.cmdParser.add_option(*args, **kwargs) self.cmdParser.add_option(*args, **kwargs)
def print_help(self): def print_help(self):
self.cmdParser.print_help() self.cmdParser.print_help()
def advanced_help(self):
self.cmdParser.set_conflict_handler('resolve') # Allows us to overwrite the previous definitions
for opt in self.advancedHelp:
opt[1]['help']="[!]" + opt[1]['helptext']
for arg in self.customArgs:
if arg in opt[1].keys(): del opt[1][arg]
if opt[1].get("type", None):
opt[1]['type'] = 'string' # we'll do our own converting later
self.cmdParser.add_option(*opt[0], **opt[1])
self.cmdParser.epilog = "Advanced options indicated by [!]. These options should not normally be required, and may have caveats regarding their use. See README file for more details"
self.print_help()
def parse_args(self): def parse_args(self):
# first, load the results from the command line: # first, load the results from the command line:
@@ -61,7 +76,7 @@ class ConfigOptionParser(object):
g = dict() g = dict()
for a in self.configVars: for a in self.configVars:
n = a['dest'] n = a['dest']
if a.get('configFileOnly', False): continue if a.get('advanced', False): continue
if a.get('commandLineOnly', False): continue if a.get('commandLineOnly', False): continue
v = getattr(options, n) v = getattr(options, n)
if v != None: if v != None:
@@ -116,7 +131,7 @@ class ConfigOptionParser(object):
# third, merge options into configReslts (with options overwriting anything in configResults) # third, merge options into configReslts (with options overwriting anything in configResults)
for a in self.configVars: for a in self.configVars:
n = a['dest'] n = a['dest']
if a.get('configFileOnly', False): continue if a.get('advanced', False): continue
if getattr(options, n) != None: if getattr(options, n) != None:
configResults.__dict__[n] = getattr(options, n) configResults.__dict__[n] = getattr(options, n)