def write_module_definition(self, lines, ident='', compute_method=None):
        def write_compute_method(self,lines, ident):
            lines.append(ident + "def compute(self):\n")
            lines.append(ident + "    if self.has_input('canvas'):\n")
            lines.append(ident + "        canvas = self.get_input('canvas')\n")
            lines.append(ident + "    else:\n")
            lines.append(ident + "        canvas = vcs.init()\n")
            lines.append(ident + "    args = []\n")
            for inp in self._inputs:
                lines.append(ident + "    %s = None\n"%inp._name)
                for inst in inp._valid_instances:
                    if inp._valid_instances.index(inst) == 0:
                        lines.append(ident + "    if self.has_input('%s'):\n" % inst)
                        lines.append(ident + "        %s = self.get_input('%s')\n" % (inp._name, inst))
                        lines.append(ident + "        args.append(%s)\n"%inp._name)
                    else:
                        lines.append(ident + "    elif self.has_input('%s'):\n" % inst)
                        lines.append(ident + "        %s = self.get_input('%s')\n" % (inp._name, inst))
                        lines.append(ident + "        args.append(%s)\n"%inp._name)
                if inp._required:
                    lines.append("\n"+ ident +"    # %s is a required port\n" % inp._name)
                    lines.append(ident + "    if %s == None:\n" % inp._name)
                    lines.append(ident + "        raise ModuleError(self, \"'%s' is a mandatory port\")\n" % inp._name)

            lines.append("\n"+ident +"    # build up the keyword arguments from the optional inputs.\n")
            lines.append(ident +"    kwargs = {}\n")

            for opt in self._options:
                for inst in opt._valid_instances:
                    if opt._valid_instances.index(inst) == 0:
                        lines.append(ident +"    if self.has_input('%s'):\n" % inst)
                        lines.append(ident +"        kwargs['%s'] = self.get_input('%s')\n" % (opt._name, inst))
                    else:
                        lines.append(ident +"    elif self.has_input('%s'):\n" % inst)
                        lines.append(ident +"        kwargs['%s'] = self.get_input('%s')\n" % (opt._name, inst))

            lines.append(ident + "    #force images to be created in the background\n")
            lines.append(ident + "    kwargs['bg'] = 1\n")
            lines.append(ident + "    res = canvas.%s(*args,**kwargs)\n"%self._name)
            lines.append(ident + "    self.set_output('%s',res)\n"%(self._outputs[0]._name))
            lines.append(ident + "    self.set_output('canvas',canvas)\n")
            lines.append("\n")
        if self._name in do_not_cache_me:
            lines.append(ident + "class %s(Module,NotCacheable):\n" % self._name)
        else:
            lines.append(ident + "class %s(Module):\n" % self._name)
        lines.append(ident + '    """%s\n'%self._doc)
        lines.append(ident + '    """\n')
        if not compute_method:
            write_compute_method(self,lines,ident="    ")
        else:
            lines.extend(compute_method)
dataset/ETHPy150Open VisTrails/VisTrails/contrib/cdat/scripts/cdat_domain.py/CDATAction.write_module_definition/original