def METHOD_NAME(self, argstr, script_lines):
    """Generates commands and, if mfile specified, writes it to disk."""
    cwd = os.getcwd()
    mfile = self.inputs.mfile or self.inputs.uses_mcr
    paths = []
    if isdefined(self.inputs.paths):
        paths = self.inputs.paths
    # prescript
    prescript = self.inputs.prescript
    postscript = self.inputs.postscript
    # prescript takes different default value depending on the mfile argument
    if mfile:
        prescript.insert(
            0, "fprintf(1,'Executing %s at %s:\\n',mfilename(),datestr(now));"
        )
    else:
        prescript.insert(0, "fprintf(1,'Executing code at %s:\\n',datestr(now));")
    for path in paths:
        # addpath() is not available after compilation
        # https://www.mathworks.com/help/compiler/ismcc.html
        # https://www.mathworks.com/help/compiler/isdeployed.html
        prescript.append("if ~(ismcc || isdeployed), addpath('%s'); end;\n" % path)
    if not mfile:
        # clean up the code of comments and replace newlines with commas
        script_lines = ",".join(
            [
                line
                for line in script_lines.split("\n")
                if not line.strip().startswith("%")
            ]
        )
    script_lines = "\n".join(prescript) + script_lines + "\n".join(postscript)
    if mfile:
        with open(os.path.join(cwd, self.inputs.script_file), "w") as mfile:
            mfile.write(script_lines)
        if self.inputs.uses_mcr:
            script = "%s" % (os.path.join(cwd, self.inputs.script_file))
        else:
            script = "addpath('{}');{}".format(
                cwd,
                self.inputs.script_file.split(".")[0],
            )
    else:
        script = "".join(script_lines.split("\n"))
    return argstr % script