def cli2rst(cliFile, rstFile): cli = ctk_cli.CLIModule(cliFile) rst = rstcloth.RstCloth() rst.title(cli.title) rst.newline() rst.content(cli.description) rst.newline() rst.field('Authors', cli.contributor) rst.field('Version', cli.version) rst.field('License', cli.license) rst.newline() rst.newline() for parameterGroup in cli: rst.h2(parameterGroup.label + ' Parameters') rst.content(parameterGroup.description) rst.newline() for parameter in parameterGroup: rst.definition(parameter.label, parameter.description, bold=True) rst.newline() rst.write(rstFile)
def readXmlDefinition(self): '''Read the XML definition and creates the dictionary for the parameters of the macro''' #print "Reading xml macro description" self._CLImodule = ctk_cli.CLIModule(self._xmlDefinition) (arguments, options, outputs) = self._CLImodule.classifyParameters() self._NumParameters = len(options) for e in options: e.flag = e.flag[1::] # delete the '-' symbol before parameter flag if (e.default == None): e.index = True else: e.index = False self._XMLparameters = options self._paramDictionary = {} for param in self._XMLparameters: self._paramDictionary[param.flag] = [param.index, param.default] #print " -Reading... (", param.flag, ")" return
def parseSlicerCliXml(fd): """ Parse a slicer CLI XML document into a form suitable for use in the worker. :param fd: A file descriptor representing the XML document to parse. :type fd: file-like :returns: A dict of information about the CLI. """ cliSpec = ctk_cli.CLIModule(stream=fd) description = '\n\n'.join(( '**Description**: %s' % cliSpec.description, '**Author(s)**: %s' % cliSpec.contributor, '**Version**: %s' % cliSpec.version, '**License**: %s' % cliSpec.license, '**Acknowledgements**: %s' % (cliSpec.acknowledgements or '*none*'), '*This description was auto-generated from the Slicer CLI XML specification.*' )) info = { 'title': cliSpec.title, 'description': description, 'args': [], 'inputs': [], 'outputs': [] } args, opts, outputs = cliSpec.classifyParameters() for param in itertools.chain(args, opts): _validateParam(param) args.sort(key=lambda p: p.index) opts.sort(key=lambda p: p.flag or p.longflag) inputArgs = [a for a in args if a.channel == 'input'] inputOpts = [o for o in opts if o.channel == 'input'] outputArgs = [a for a in args if a.channel == 'output'] outputOpts = [o for o in opts if o.channel == 'output'] def ioSpec(name, param, addDefault=False): if param.channel == 'output': typ = _SLICER_TO_GIRDER_WORKER_OUTPUT_TYPE_MAP[param.typ] else: typ = _SLICER_TO_GIRDER_WORKER_INPUT_TYPE_MAP[param.typ] spec = { 'id': name, 'name': param.label, 'description': param.description, 'type': typ, 'format': typ } if param.isExternalType(): spec['target'] = 'filepath' if addDefault and param.default is not None: spec['default'] = {'data': param.default} return spec for param in inputOpts: name = param.flag or param.longflag info['inputs'].append(ioSpec(name, param, True)) if param.typ == 'boolean': info['args'].append('$flag{%s}' % name) else: info['args'] += [name, '$input{%s}' % name] for param in outputOpts: name = param.flag or param.longflag info['outputs'].append(ioSpec(name, param)) info['args'] += [ param.flag or param.longflag, os.path.join(DOCKER_DATA_VOLUME, name) ] for param in inputArgs: info['inputs'].append(ioSpec(param.name, param, True)) info['args'].append('$input{%s}' % param.name) for param in outputArgs: info['outputs'].append(ioSpec(param.name, param)) info['args'].append(os.path.join(DOCKER_DATA_VOLUME, param.name)) return info