コード例 #1
0
class GenPyImportTask(GenTask):
    _attr_ImportTask = [AttrDescription('command',
                                        types.StringType,
                                        'multipleLineEdit',
                                        GenTask.eval_zone,
                                        GenTask.set_eval_zone,True)]
    _LockupImportAttr = dict()
    for i in _attr_ImportTask:
        _LockupImportAttr[i.name] = i

    def __init__(self):
        super(GenPyImportTask, self).__init__()

    @classmethod
    def get_lock_up(cls):
        return cls._LockupImportAttr

    def update_with(self,atask,lockup = None,attribList=None):
        super(GenPyImportTask, self).update_with(atask,GenPyImportTask._LockupImportAttr,GenPyImportTask._attr_ImportTask)

    def to_python(self,stream,acontext):
        super(GenPyImportTask, self).to_python(stream,acontext)
        # command
        command = GenPyImportTask._LockupImportAttr['command'].get(self,'command')
        if command == None:
            log.error("'import contents' is required for an import task")
            return False

        scommand = command.split("\n")
        for c in scommand:
            stream.write("%s%s\n" % (acontext['tab'],c))
        return True
コード例 #2
0
class GenForEachTask(GenTask):
    _attr_ForTask = [
        AttrDescription('container', types.StringType, 'simpleLineEdit',
                        GenTask.eval_zone, GenTask.set_eval_zone, True),
        AttrDescription('output', types.StringType, 'simpleLineEdit',
                        GenTask.eval_zone, GenTask.set_eval_zone, False)
    ]

    _LockupForAttr = dict()
    for i in _attr_ForTask:
        _LockupForAttr[i.name] = i

    def __init__(self):
        super(GenForEachTask, self).__init__()
        self.pythonString = "for %s in %s"

    def update_with(self, atask, lockup=None, attribList=None):
        super(GenForEachTask,
              self).update_with(atask, GenForEachTask._LockupForAttr,
                                GenForEachTask._attr_ForTask)

    def to_python(self, stream, acontext):
        super(GenForEachTask, self).to_python(stream, acontext)
        # here we have to increment
        tab = acontext['tab']
        incrTab = acontext['tabInc']
        container = GenForEachTask._LockupForAttr['container'].get(
            self, 'container')
        output = GenForEachTask._LockupForAttr['output'].get(self, 'output')

        if container != None and container != "":
            out = None
            if output != None and output != "":
                out = clean_quote(output)
            else:
                out = 'item'
            over = clean_quote(container)
            command = self.pythonString % (out, over)
            stream.write("%s%s:\n" % (tab, command))
        acontext['tab'] += incrTab
        return True
コード例 #3
0
class GenIfTask(GenTask):
    _attr_CtlTask = [
        AttrDescription('condition', types.StringType, 'simpleLineEdit',
                        GenTask.eval_zone, GenTask.set_eval_zone, False)
    ]

    _LockupCtlAttr = dict()
    for i in _attr_CtlTask:
        _LockupCtlAttr[i.name] = i

    def __init__(self):
        super(GenIfTask, self).__init__()
        self.pythonString = "if"

    @classmethod
    def get_lock_up(cls):
        return cls._LockupCtlAttr

    def update_with(self, atask, lockup=None, attribList=None):
        super(GenIfTask, self).update_with(atask, GenIfTask._LockupCtlAttr,
                                           GenIfTask._attr_CtlTask)

    def to_python(self, stream, acontext):
        super(GenIfTask, self).to_python(stream, acontext)
        # here we have to increment
        tab = acontext['tab']
        incrTab = acontext['tabInc']
        condition = GenIfTask._LockupCtlAttr['condition'].get(
            self, 'condition')

        if condition != None:
            # some condition are getting replace with except:
            if condition.find("hasFailed") != -1:
                stream.write("%sexcept:\n" % (tab))
            else:
                stream.write("%s%s %s:\n" %
                             (tab, self.pythonString, clean_quote(condition)))
        else:
            stream.write("%s%s:\n" % (acontext['tab'], self.pythonString))
        acontext['tab'] += incrTab
        return True
コード例 #4
0
ファイル: genmel_task.py プロジェクト: erictexier/dsksoftkit
class GenMelTask(GenTask):
    _attr_MelTask = [
        AttrDescription('source', types.StringType, 'simpleLineEdit',
                        GenTask.zone, GenTask.set_zone, False),
        AttrDescription('command', types.StringType, 'multipleLineEdit',
                        GenTask.eval_zone, GenTask.set_eval_zone, True),
        AttrDescription('output', types.BooleanType, 'simpleLineEdit',
                        GenTask.eval_zone, GenTask.set_eval_zone, False),
        AttrDescription('evalEcho', types.BooleanType, 'simpleCheck',
                        GenTask.zone, GenTask.set_zone, False)
    ]
    _LockupMelAttr = dict()
    for i in _attr_MelTask:
        _LockupMelAttr[i.name] = i

    def __init__(self):
        super(GenMelTask, self).__init__()

    @classmethod
    def get_lock_up(cls):
        return cls._LockupMelAttr

    def update_with(self, atask, lockup=None, attribList=None):
        super(GenMelTask, self).update_with(atask, GenMelTask._LockupMelAttr,
                                            GenMelTask._attr_MelTask)

    def to_python(self, stream, acontext):
        super(GenMelTask, self).to_python(stream, acontext)

        # command
        command = GenMelTask._LockupMelAttr['command'].get(self, 'command')
        if command == None:
            log.error("'command' is required for a mel task")
            return

        # output
        output = GenMelTask._LockupMelAttr['output'].get(self, 'output')

        # source
        source = GenMelTask._LockupMelAttr['source'].get(self, 'source')

        module = "maya.mel"
        tab = acontext['tab']

        GenTask.do_python_module(stream, acontext, tab, module)

        if source != None:
            stream.write(("%smaya.mel.eval('" % tab) +
                         ('source "%s"' % source) + "')\n")

        res = do_clean_command(command)
        final = ""
        if res.success:
            if output == None:
                final = ("%smaya.mel.eval('" %
                         tab) + res.newCommand + "'" + res.addOn + ")"
            else:
                final = (
                    "%s%s = maya.mel.eval('" %
                    (tab, output)) + res.newCommand + "'" + res.addOn + ")"
        else:
            if output == None:
                final = ("%smaya.mel.eval('" % tab) + command + "')"
            else:
                final = ("%s%s = maya.mel.eval('" %
                         (tab, output)) + command + "')"

        evalEcho = GenMelTask._LockupMelAttr['evalEcho'].get(self, 'evalEcho')
        if evalEcho == True:
            p = re.compile("\(.*\)", re.DOTALL)
            m = p.search(final)
            if m:
                stream.write("%sprint%s\n" % (tab, m.group()))
            stream.write(final + "\n")
            if output != None:
                stream.write("%sprint 'return value " % tab + "%s' % " +
                             output + "\n")
        else:
            stream.write(final + "\n")
        return True
コード例 #5
0
class GenPyTask(GenTask):
    _attr_PyTask = [
        AttrDescription('module', types.StringType, 'simpleLineEdit',
                        GenTask.zone, GenTask.set_zone, False),
        AttrDescription('command', types.StringType, 'multipleLineEdit',
                        GenTask.eval_zone, GenTask.set_eval_zone, True),
        AttrDescription('output', types.StringType, 'simpleLineEdit',
                        GenTask.eval_zone, GenTask.set_eval_zone, False),
        AttrDescription('args', types.StringType, 'argLineEdit',
                        GenTask.eval_zone, GenTask.set_eval_zone, False),
        AttrDescription('kwargs', types.StringType, 'argLineEdit',
                        GenTask.eval_zone, GenTask.set_eval_zone, False),
        AttrDescription('handler', types.StringType, 'simpleLineEdit',
                        GenTask.zone, GenTask.set_zone, False),
    ]
    _LockupPyAttr = dict()
    for i in _attr_PyTask:
        _LockupPyAttr[i.name] = i

    def __init__(self):
        super(GenPyTask, self).__init__()

    @classmethod
    def get_lock_up(cls):
        return cls._LockupPyAttr

    def update_with(self, atask, lockup=None, attribList=None):
        super(GenPyTask, self).update_with(atask, GenPyTask._LockupPyAttr,
                                           GenPyTask._attr_PyTask)
        if hasattr(atask, 'resolveArgValues'):
            self.resolveArgValues = atask.resolveArgValues
            if hasattr(atask, 'resolveKwArgValues'):
                self.resolveKwArgValues = atask.resolveKwArgValues
                if atask.resolveArgValues == False or atask.resolveKwArgValues == False:
                    log.warning(
                        "resolve argument set to false is not supported for now"
                    )

    def _build_clean_argument_list(self):
        # add the args and the kwargs
        # exception
        # if cmd is found in args and kwargs is a tuple or string don't add the kwargs argument

        lcmd = list()
        val = GenPyTask._LockupPyAttr['args'].get(self, 'args')

        if val != None and val != "":
            assert isinstance(val, basestring)
            val = remove_extern_bracket(val)
            val = clean_quote(val)
            # now we have to deal with the funny syntax %()s
            sval = val.split(",")
            for s in sval:
                s = s.strip()
                s = remove_over_quoted(s)
                res = do_clean_command(s)
                if res.success:
                    lcmd.append("%s%s\n" % (res.newCommand, res.addOn))
                else:
                    lcmd.append(s)

        val = GenPyTask._LockupPyAttr['kwargs'].get(self, 'kwargs')
        if val != None and val != "":
            # we canno't eval here
            # first see it's a path
            pe = ""
            if val.startswith("{'"):
                pe = re.compile(r"'[\w]*':")
                val = remove_extern_cbracket(val)
            elif val.startswith('{"'):
                pe = re.compile(r'"[\w]*":')
                val = remove_extern_cbracket(val)
            else:  # it's a path
                if len(lcmd
                       ) != 0:  # when 2 path are define the dict one is ignore
                    return lcmd
                val = clean_quote(val)
                sval = val.split(",")
                for s in sval:
                    s = s.strip()
                    s = remove_over_quoted(s)
                    res = do_clean_command(s)
                    if res.success:
                        lcmd.append("%s%s" % (res.newCommand, res.addOn))
                    else:
                        lcmd.append(s)
                return lcmd
            # I know it's ugly and it much be an other way but I cannot come up with
            # the right patern is insulate key,value, knowing that everything here can be escape
            allKey = re.findall(pe, val)
            allKey.reverse()
            dlist = list()
            # we start by the end, by splitting we should be able to build a list of tuple
            for k in allKey:
                sval = val.split(k)
                val = sval[0]
                # clean the key:
                akey = remove_extern_quote(k.replace(":", "").strip())
                # clean the value
                aval = sval[1].strip()
                if len(aval) > 0 and aval[-1] == ",": aval = aval[:-1]
                aval = clean_quote(aval)
                dlist.append((akey, remove_over_quoted(aval)))
            dlist.reverse()
            for i in dlist:  # put it back in order
                res = do_clean_command(i[1])
                if res.success:
                    if len(res.newCommand) > 0 and not res.newCommand[0] in [
                            '"', "'"
                    ]:
                        lcmd.append("%s = '%s' %s" %
                                    (i[0], res.newCommand, res.addOn))
                    else:
                        lcmd.append("%s = %s%s" %
                                    (i[0], res.newCommand, res.addOn))
                else:
                    lcmd.append("%s = %s" % (i[0], i[1]))

        return lcmd

    def get_argument_string(self):
        argList = self._build_clean_argument_list()
        return ",".join(argList)

    def set_argument_string(self, args):
        arg = list()
        karg = list()
        argList = args.split(",")
        for i in argList:
            if i.find("=") != -1:
                karg.append(i)
            else:
                arg.append(i)

        self.set('args', ",".join(arg))
        self.set('kwargs', ",".join(karg))

    def is_script(self):
        handler = GenPyTask._LockupPyAttr['handler'].get(self, 'handler')
        return not handler in [None, '', 'eval']

    def to_python(self, stream, acontext):
        # there is 2 case here, one (when module is present, it only about importing the
        # module and excuting the function. The other one is to define a local function
        # and execute it, return value are optional

        super(GenPyTask, self).to_python(stream, acontext)

        tab = acontext['tab']
        #tabInc = acontext['tabInc']
        # command
        command = GenPyTask._LockupPyAttr['command'].get(self, 'command')
        if command == None or command.strip() == "":
            log.error("'command' is required for a py task %r" %
                      self.getName())
            return False

        # output
        output = GenPyTask._LockupPyAttr['output'].get(self, 'output')
        if output == "":
            output = None

        handler = GenPyTask._LockupPyAttr['handler'].get(self, 'handler')
        if handler == "":
            handler = None

        argumentList = self._build_clean_argument_list()

        if handler == None or handler == 'eval':
            # something the argument string is already in the command
            # module
            module = GenPyTask._LockupPyAttr['module'].get(self, 'module')
            doModule = (module != None and module != "")
            if doModule:
                # module
                GenTask.do_python_module(stream, acontext, tab, module)

            m = GenTask._argumentFunction.search(command)

            # having argument syntax in the function take precedence
            startLine = tab
            if output != None:
                startLine += "%s = " % output
            if m:
                if doModule == True:
                    stream.write("%s%s.%s\n" %
                                 (startLine, module, clean_quote(command)))
                else:
                    stream.write("%s%s\n" % (startLine, clean_quote(command)))
            else:
                import traceback
                nbOfArgument = len(argumentList)

                if nbOfArgument == 0 and doModule:
                    # some argument like RTD,CFD can be added let check if it's need
                    # inspect
                    import inspect
                    funcstring = "%s.%s" % (module, command)
                    inspectSuccess = True
                    readArg = None

                    try:
                        exec("import %s" % module)
                    except:
                        #traceback.print_exc()
                        inspectSuccess = False
                        log.warning("couldn't import the module('%s')" %
                                    module)

                    try:
                        readArg = inspect.getargspec(eval(funcstring))
                    except:
                        inspectSuccess = False
                        #log.warning("couldn't get the function('%s') argument in %s" % (funcstring,self.label))

                    if inspectSuccess == False:
                        if doModule:
                            stream.write("%s%s.%s()\n" %
                                         (startLine, module, command))
                        else:
                            stream.write("%s%s()\n" % (startLine, command))
                    else:
                        # very simple for now
                        #defa = readArg.defaults

                        argu = ""
                        for i in readArg.args:
                            m = GenTask._checkStringEval.match(i)
                            if m:
                                if argu == "":
                                    argu = i
                                else:
                                    argu = argu + "," + i

                        if argu == "":
                            if doModule:
                                stream.write("%s%s.%s()\n" %
                                             (startLine, module, command))
                            else:
                                stream.write("%s%s()\n" % (startLine, command))
                        else:
                            if doModule:
                                stream.write(
                                    "%s%s.%s(%s)\n" %
                                    (startLine, module, command, argu))
                            else:
                                stream.write("%s%s.%s(%s)\n" %
                                             (startLine, command, argu))
                else:
                    maxLen = 0
                    for ea in argumentList:
                        maxLen += len(ea)

                    endValue = ")"
                    if nbOfArgument > 1:
                        endValue = ","
                    startCmd = ""
                    alen = 0
                    if doModule:
                        startCmd = "%s%s.%s(" % (startLine, module, command)
                    else:
                        startCmd = "%s%s(" % (startLine, command)
                    alen = len(startCmd)
                    if maxLen > 80 and nbOfArgument > 1:  # maximum line length to display
                        stream.write("%s%s%s\n" %
                                     (startCmd, argumentList[0], endValue))
                        for ar in argumentList[1:-1]:
                            stream.write("%s%s,\n" % (' ' * alen, ar))
                        # we need the ) with the last element
                        stream.write("%s%s)\n" %
                                     (' ' * alen, argumentList[-1]))
                    else:
                        stream.write("%s%s)\n" %
                                     (startCmd, ", ".join(argumentList)))
        else:
            sc = command.split("\n")
            for i in sc:
                stream.write("%s%s\n" % (tab, i))

        return True
コード例 #6
0
class GenExternalTask(GenTask):

    _attr_ExtTask = [
        AttrDescription('workingDirectory', types.StringType, 'simpleLineEdit',
                        GenTask.zone, GenTask.set_zone, True),
        AttrDescription('logdir', types.StringType, 'simpleLineEdit',
                        GenTask.zone, GenTask.set_zone, False),
        AttrDescription('block', types.BooleanType, 'simpleCheck',
                        GenTask.zone, GenTask.set_zone, True),
        AttrDescription('daemon', types.BooleanType, 'simpleCheck',
                        GenTask.zone, GenTask.set_zone, True),
        # more
        AttrDescription('env_RemoveQVars', types.BooleanType, 'simpleCheck',
                        GenTask.zone, GenTask.set_zone, True),
        AttrDescription('env_RemoveEnvVars', types.BooleanType, 'simpleCheck',
                        GenTask.zone, GenTask.set_zone, True),
        AttrDescription('postExec', types.StringType, 'multipleLineEdit',
                        GenTask.eval_zone, GenTask.set_eval_zone, False),
        AttrDescription('preExec', types.StringType, 'multipleLineEdit',
                        GenTask.eval_zone, GenTask.set_eval_zone, False),
        # remote execution
        AttrDescription('host', types.StringType, 'simpleLineEdit',
                        GenTask.zone, GenTask.set_zone, False),
        AttrDescription('display', types.StringType, 'simpleLineEdit',
                        GenTask.zone, GenTask.set_zone, False),
        AttrDescription('_command', types.StringType, 'noEdit', GenTask.zone,
                        GenTask.set_zone, True)
    ]

    _LockupExtAttr = dict()
    for i in _attr_ExtTask:
        _LockupExtAttr[i.name] = i

    def __init__(self):
        super(GenExternalTask, self).__init__()

    @classmethod
    def get_lock_up(cls):
        return cls._LockupExtAttr

    def update_with(self, atask, lockup=None, attribList=None):
        super(GenExternalTask,
              self).update_with(atask, GenExternalTask._LockupExtAttr,
                                GenExternalTask._attr_ExtTask)

    def to_python(self, stream, acontext):
        # we build a method to handle the remote code
        # on this stream we only call that method
        super(GenExternalTask, self).to_python(stream, acontext)

        callFunction = self.get_function_name(acontext, self.getName())
        remoteCallFunction = "remote_%s" % callFunction
        tab = saveTab = acontext['tab']

        #if acontext.has_key('packageName'):
        #    packageName = acontext['packageName']

        preExec = GenExternalTask._LockupExtAttr['preExec'].get(
            self, 'preExec')
        if preExec != None and preExec != "":
            sc = preExec.split("\n")
            for i in sc:
                stream.write("%s%s\n" % (tab, i))

        stream.write("%sself.%s(RTD,CFD,TP)\n" %
                     (acontext['tab'], callFunction))

        # main stream
        # write the call to the method
        postExec = GenExternalTask._LockupExtAttr['postExec'].get(
            self, 'postExec')
        if postExec != None and postExec != "":
            sc = postExec.split("\n")
            for i in sc:
                stream.write("%s%s\n" % (tab, i))

        workingDirectory = GenExternalTask._LockupExtAttr[
            'workingDirectory'].get(self, 'workingDirectory')
        block = GenExternalTask._LockupExtAttr['block'].get(self, 'block')
        daemon = GenExternalTask._LockupExtAttr['daemon'].get(self, 'daemon')
        env_RemoveQVars = GenExternalTask._LockupExtAttr[
            'env_RemoveQVars'].get(self, 'env_RemoveQVars')
        env_RemoveEnvVars = GenExternalTask._LockupExtAttr[
            'env_RemoveEnvVars'].get(self, 'env_RemoveEnvVars')

        host = GenExternalTask._LockupExtAttr['host'].get(self, 'host')
        display = GenExternalTask._LockupExtAttr['display'].get(
            self, 'display')

        # start a new stream
        tabInc = acontext['tabInc']
        tab = tabInc  # that where method start

        # start a new stream
        stream2 = GenTask.push_stream(acontext, stream, callFunction)
        saveImport = GenTask.copy_reset_import_statement(acontext)
        # write the new method definition definition
        stream2.write("\n")
        stream2.write(tab + "#" * 30 + "\n")
        stream2.write(tabInc + "def %s(self,RTD,CFD,TP):\n" % (callFunction))

        # write the local function definition for the remote client code
        tab = tabInc * 2

        stream2.write("\n")
        stream2.write(tab + "def %s(RTD,CFD,TP):\n" % (remoteCallFunction))

        # remote client code
        acontext['tab'] = tab = tabInc * 3
        self.traverse_with_tab(stream2, "to_python", acontext)

        # manage the subprocess syntax
        tab = tabInc * 2

        dumpline = list()

        dumpline.append(tab)
        dumpline.append(tab + "if TP.is_remote():")
        dumpline.append(tab + tabInc + "TP.set_remote(False)")
        # we are in the remote code
        dumpline.append(tab + tabInc + "return %s(RTD,CFD,TP)" %
                        (remoteCallFunction))
        dumpline.append(tab + "else:")

        dumpline.append(tab + tabInc +
                        "from dsk.base.lib.wrapper_xenvi import WrapperxEnvi")
        dumpline.append(tab)
        stream2.write("\n".join(dumpline))
        '''
        stream2.write(tab + tabInc + "import os\n")
        stream2.write(tab + tabInc + "import subprocess\n")
        stream2.write(tab + tabInc + "TP.set_remote(True)\n")

        # this is where the serialiation can happen
        acmd = "p = subprocess.Popen("
        stream2.write(tab + tabInc + acmd)
        # start args
        stream2.write("['python',__file__,self.__class__.__name__,%r" % callFunction)
        stream2.write(",RTD.serialize(),CFD.serialize(),TP.serialize()]")
        if workingDirectory != None and workingDirectory != "":
            stream2.write(",cwd= %s" %  quote_if_needed(workingDirectory))

        # end function call ( close paranthesis and newline
        stream2.write(")\n")

        stream2.write(tab + tabInc + "TP.set_remote(False)\n")
        if(block != None and block == True):stream2.write(tab + tabInc + "os.waitpid(p.pid, 0)[1]\n")
        else:stream2.write(tab + tabInc + "# no wait\n")
        stream2.write(tab + tabInc + "return\n")

        '''
        # restore the context
        acontext['tab'] = saveTab
        GenTask.reload_import_statement(saveImport, acontext)
        # here we define the function that will be call
        if block != None:
            stream2.write(tab + "#-->bool(%s)" % block + " wait\n")
        if daemon != None:
            stream2.write(tab + "#-->bool(%s)" % daemon + " daemon\n")

        if env_RemoveQVars != None:
            stream2.write(tab + "#-->bool(%s)" % env_RemoveQVars +
                          " env_RemoveQVars\n")
        if env_RemoveEnvVars != None:
            stream2.write(tab + "#-->bool(%s)" % env_RemoveEnvVars +
                          " env_RemoveEnvVars\n")
        if postExec != None:
            stream2.write(tab + "#-->" + postExec + " postExec\n")
        if host != None: stream2.write(tab + "#-->" + host + " host\n")
        if display != None:
            stream2.write(tab + "#-->" + display + " display\n")
        stream2.write("\n")
        acontext['tab'] = tab  # start at the function of the class
        # restore where we left it
        acontext['tab'] = saveTab
        return False  # we take care of the traversing
コード例 #7
0
class GenPackageTask(GenTask):
    _attr_PackageTask = [
        AttrDescription('file', types.StringType, 'simpleLineEdit',
                        GenTask.zone, GenTask.set_zone, True),
        AttrDescription('preExec', types.StringType, 'multipleLineEdit',
                        GenTask.eval_zone, GenTask.set_eval_zone, False),
        AttrDescription('postExec', types.StringType, 'multipleLineEdit',
                        GenTask.eval_zone, GenTask.set_eval_zone, False)
    ]
    _LockupPackageAttr = dict()
    for i in _attr_PackageTask:
        _LockupPackageAttr[i.name] = i

    def __init__(self):
        super(GenPackageTask, self).__init__()

    @classmethod
    def get_lock_up(cls):
        return cls._LockupPackageAttr

    def update_with(self, atask, lockup=None, attribList=None):
        super(GenPackageTask,
              self).update_with(atask, GenPackageTask._LockupPackageAttr,
                                GenPackageTask._attr_PackageTask)

    def to_python(self, stream, acontext):
        from dsk.base.tdata.taskdata.taskdata_api import TaskDataApi
        super(GenPackageTask, self).to_python(stream, acontext)
        tab = acontext['tab']
        if acontext.has_key(
                'doTaskPackage') and acontext['doTaskPackage'] == False:
            stream.write("%s#TaskPackage turn off\n" % tab)
            return
        afile = GenPackageTask._LockupPackageAttr['file'].get(self, 'file')
        preExec = GenPackageTask._LockupPackageAttr['preExec'].get(
            self, 'preExec')
        postExec = GenPackageTask._LockupPackageAttr['postExec'].get(
            self, 'postExec')
        if postExec == "":
            postExec = None
        if afile == None or afile == "":
            raise RequiredFieldError(
                "cannot build the taskPackage without a file")

        if preExec != None:
            sc = preExec.split("\n")
            for i in sc:
                stream.write("%s%s\n" % (tab, i))
        # to valid the TASK interface
        stream.write("%sTASK = n = %s()\n" %
                     (tab, TaskDataApi.get_class_name_from_package(afile))
                     )  # make TASK accessible for preExec

        stream.write("%sn.doIt(RTD,CFD,TP)\n" % tab)

        if postExec != None:
            sc = postExec.split("\n")
            for i in sc:
                stream.write("%s%s\n" % (tab, i))

        # update the package loaded
        if not afile in acontext['taskPackageLoaded']:
            acontext['taskPackage'].append(afile)