def parseArgs(argv): """Creates an argument parser which accepts options for off-screen rendering. Uses the :mod:`fsleyes.parseargs` module to peform the actual parsing. :returns: An ``argparse.Namespace`` object containing the parsed arguments. """ mainParser = parseargs.ArgumentParser( add_help=False, formatter_class=parseargs.FSLeyesHelpFormatter) mainParser.add_argument('-of', '--outfile', help='Output image file name'), mainParser.add_argument('-c', '--crop', type=int, metavar='BORDER', help='Auto-crop image, leaving a ' 'border on each side') mainParser.add_argument('-sz', '--size', type=int, nargs=2, metavar=('W', 'H'), help='Size in pixels (width, height)', default=(800, 600)) name = 'render' prolog = 'FSLeyes render version {}\n'.format(version.__version__) optStr = '-of outfile' description = textwrap.dedent("""\ FSLeyes screenshot generator. Use the '--scene' option to choose between orthographic ('ortho'), lightbox ('lightbox'), or 3D ('3d') views. """) namespace = parseargs.parseArgs( mainParser, argv, name, prolog=prolog, desc=description, usageProlog=optStr, argOpts=['-of', '--outfile', '-sz', '--size', '-c', '--crop'], shortHelpExtra=['--outfile', '--size', '--crop']) if namespace.outfile is None: log.error('outfile is required') mainParser.print_usage() sys.exit(1) namespace.outfile = op.abspath(namespace.outfile) if namespace.scene not in ('ortho', 'lightbox', '3d'): log.info('Unknown scene specified ("{}") - defaulting ' 'to ortho'.format(namespace.scene)) namespace.scene = 'ortho' return namespace
def parseArgs(argv): """Parses the given ``fsleyes`` command line arguments. See the :mod:`.parseargs` module for details on the ``fsleyes`` command line interface. :arg argv: command line arguments for ``fsleyes``. """ import fsleyes.parseargs as parseargs import fsleyes.layouts as layouts import fsleyes.version as version parser = parseargs.ArgumentParser( add_help=False, formatter_class=parseargs.FSLeyesHelpFormatter) serveraction = ft.partial(cliserver.CLIServerAction, allArgs=argv) parser.add_argument('-r', '--runscript', metavar='SCRIPTFILE', help='Run custom FSLeyes script') parser.add_argument('-cs', '--cliserver', action=serveraction, help='Pass all command-line arguments ' 'to a single FSLeyes instance') # We include the list of available # layouts in the help description allLayouts = list(layouts.BUILT_IN_LAYOUTS.keys()) + \ list(layouts.getAllLayouts()) name = 'fsleyes' prolog = 'FSLeyes version {}\n'.format(version.__version__) description = textwrap.dedent("""\ FSLeyes - the FSL image viewer. Use the '--scene' option to load a saved layout ({layouts}). If no '--scene' is specified, a default layout is shown or the previous layout is restored. If a script is provided via the '--runscript' argument, it is assumed that the script sets up the scene. """.format(layouts=', '.join(allLayouts))) # Options for configuring the scene are # managed by the parseargs module return parseargs.parseArgs(parser, argv, name, prolog=prolog, desc=description, argOpts=['-r', '--runscript'])