Esempio n. 1
0
    def exec_command(self, cmd, cwd, env=None):
        if cwd is None:
            cwd = self.gen.bld.bld_root.abspath()
        kw = {}
        if env is not None:
            kw["env"] = env
        if not self.disable_output:
            if self.env["VERBOSE"]:
                pprint('GREEN', " ".join([str(c) for c in cmd]))
            else:
                pprint('GREEN', "%-16s%s" % (self.name.upper(), " ".join([i.bldpath() for i in self.inputs])))

        self.gen.bld.set_cmd_cache(self, cmd)
        try:
            p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                    stderr=subprocess.STDOUT, cwd=cwd, **kw)
            stdout = p.communicate()[0].decode("utf-8")
            if p.returncode:
                raise TaskRunFailure(cmd, stdout)
            if sys.version_info >= (3,):
                stdout = stdout
            else:
                stdout = stdout.encode("utf-8")
            if self.disable_output:
                self.log.write(stdout)
            else:
                sys.stderr.write(stdout)
            self.gen.bld.set_stdout_cache(self, stdout)
        except OSError:
            e = get_exception()
            raise TaskRunFailure(cmd, str(e))
        except WindowsError:
            e = get_exception()
            raise TaskRunFailure(cmd, str(e))
Esempio n. 2
0
 def exec_command(self, cmd, cwd):
     if not self.disable_output:
         if self.env["VERBOSE"]:
             pprint("GREEN", " ".join(cmd))
         else:
             pprint("GREEN", "%-16s%s" % (self.name.upper(), " ".join([os.path.basename(i) for i in self.outputs])))
     p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     stdout, stderr = p.communicate()
     if p.returncode:
         raise TaskRunFailure("cmd %s failed: %s" % (" ".join(cmd), stderr))
Esempio n. 3
0
def convert_func(self):
    if not len(self.inputs) == 1:
        raise ValueError("convert_func needs exactly one input")
    source, target = self.inputs[0], self.outputs[0]

    pprint('GREEN', "%-16s%s" % (self.name.upper(),
           " ".join([s.srcpath() for s in self.inputs])))
    cmd = ["2to3", "-w", "--no-diffs", "-n", source.abspath()]
    st = subprocess.call(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    if st != 0:
        pprint('RED', "FAILED %-16s%s" % (self.name.upper(),
               " ".join([s.srcpath() for s in self.inputs])))
        raise TaskRunFailure(cmd)
    target.write(source.read())
Esempio n. 4
0
def template(self):
    if not len(self.inputs) == 1:
        raise ValueError("template func needs exactly one input")

    pprint('GREEN', "%-16s%s" % (self.name.upper(),
        " ".join([str(s) for s in self.inputs])))
    subs_re = dict([(k, re.compile("@" + k + "@")) 
                     for k in self.env["SUBST_DICT"]])
    cnt = self.inputs[0].read()
    for k, v in self.env["SUBST_DICT"].items():
        cnt = subs_re[k].sub(v, cnt)

    ensure_dir(self.outputs[0].abspath())
    self.outputs[0].write(cnt)
def convert_func(self):
    if not len(self.inputs) == 1:
        raise ValueError("convert_func needs exactly one input")
    source, target = self.inputs[0], self.outputs[0]

    pprint(
        'GREEN', "%-16s%s" %
        (self.name.upper(), " ".join([s.srcpath() for s in self.inputs])))
    cmd = ["2to3", "-w", "--no-diffs", "-n", source.abspath()]
    st = subprocess.call(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    if st != 0:
        pprint(
            'RED', "FAILED %-16s%s" %
            (self.name.upper(), " ".join([s.srcpath() for s in self.inputs])))
        raise TaskRunFailure(cmd)
    target.write(source.read())
Esempio n. 6
0
def template(self):
    if not len(self.inputs) == 1:
        raise ValueError("template func needs exactly one input")

    pprint('GREEN', "%-16s%s" % (self.name.upper(), " ".join(self.inputs)))
    subs_re = dict([(k, re.compile("@" + k + "@")) 
                     for k in self.env["SUBST_DICT"]])
    fid = open(self.inputs[0])
    try:
        cnt = fid.read()
        for k, v in self.env["SUBST_DICT"].items():
            cnt = subs_re[k].sub(v, cnt)
    finally:
        fid.close()

    ensure_dir(self.outputs[0])
    fid = open(self.outputs[0], "w")
    try:
        fid.write(cnt)
    finally:
        fid.close()
Esempio n. 7
0
File: task.py Progetto: dagss/Bento
    def exec_command(self, cmd, cwd):
        if cwd is None:
            cwd = self.gen.bld.bld_root.abspath()
        if not self.disable_output:
            if self.env["VERBOSE"]:
                pprint('GREEN', " ".join([str(c) for c in cmd]))
            else:
                pprint('GREEN', "%-16s%s" % (self.name.upper(), " ".join([i.bldpath() for i in self.inputs])))

        try:
            p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT, cwd=cwd)
            stdout = p.communicate()[0].decode("utf-8")
            if p.returncode:
                raise TaskRunFailure(cmd, stdout)
            if self.disable_output:
                if sys.version_info >= (3,):
                    self.log.write(stdout)
                else:
                    self.log.write(stdout.encode("utf-8"))
            else:
                sys.stderr.write(stdout.encode("utf-8"))
        except OSError, e:
            raise TaskRunFailure(cmd, str(e))
Esempio n. 8
0
def copy_func(self):
    source, target = self.inputs[0], self.outputs[0]
    pprint('YELLOW', "%-16s%s" % (self.name.upper(),
           " ".join([s.srcpath() for s in self.inputs])))
    target.write(source.read())
Esempio n. 9
0
def convert_func(self):
    global __RUN_CONVERT
    __RUN_CONVERT = True
    source, target = self.inputs[0], self.outputs[0]
    pprint('BLUE', "%-16s%s" % (self.name.upper(), self.inputs[0].srcpath()))
    target.write("")
Esempio n. 10
0
def copy_func(self):
    if __RUN_CONVERT:
        raise AssertionError("precendence test failed")
    source, target = self.inputs[0], self.outputs[0]
    pprint('BLUE', "%-16s%s" % (self.name.upper(), self.inputs[0].srcpath()))
    target.write(source.read())
def copy_func(self):
    source, target = self.inputs[0], self.outputs[0]
    pprint(
        'YELLOW', "%-16s%s" %
        (self.name.upper(), " ".join([s.srcpath() for s in self.inputs])))
    target.write(source.read())
Esempio n. 12
0
def convert_func(self):
    global __RUN_CONVERT
    __RUN_CONVERT = True
    source, target = self.inputs[0], self.outputs[0]
    pprint('BLUE', "%-16s%s" % (self.name.upper(), self.inputs[0].srcpath()))
    target.write("")
Esempio n. 13
0
def copy_func(self):
    if __RUN_CONVERT:
        raise AssertionError("precendence test failed")
    source, target = self.inputs[0], self.outputs[0]
    pprint('BLUE', "%-16s%s" % (self.name.upper(), self.inputs[0].srcpath()))
    target.write(source.read())