コード例 #1
0
ファイル: system.py プロジェクト: tundra/mkmk
 def build(self):
   args = map(shell_escape, self.args)
   raw_command = "%s %s" % (self.executable, " ".join(args))
   if len(self.env) > 0:
     envs = []
     for (name, value, mode) in self.env:
       if type(value) == list:
         value = ";".join(value)
       if mode == "append":
         env = "set \"%(name)s=%%%(name)s%%;%(value)s\"" % {
           "name": name,
           "value": value
         }
       elif mode == "replace":
         env = "set \"%(name)s=%(value)s\"" % {
           "name": name,
           "value": value
         }
       else:
         raise Exception("Unknown mode %s" % mode)
       envs.append(env)
     raw_command = "cmd /C \"%s && %s\"" % (" && ".join(envs), cmd_escape(raw_command))
   if self.tee_dest:
     params = {
       "command_line": raw_command,
       "outpath": self.tee_dest
     }
     parts = [
       "%(command_line)s > %(outpath)s 2>&1 || echo > %(outpath)s.fail",
       "type %(outpath)s",
       "if exist %(outpath)s.fail (del %(outpath)s %(outpath)s.fail && exit 1) else (exit 0)",
     ]
     result = Command(*[part % params for part in parts])
   else:
     result = Command(raw_command)
   if self.comment:
     result.set_comment(self.comment)
   return result
コード例 #2
0
ファイル: system.py プロジェクト: tundra/mkmk
 def build(self):
   args = map(shell_escape, self.args)
   raw_command = "%s %s" % (self.executable, " ".join(args))
   if len(self.env) > 0:
     envs = []
     for (name, value, mode) in self.env:
       if type(value) == list:
         value = ":".join(value)
       if mode == "append":
         envs.append("%(name)s=$$%(name)s:%(value)s" % {
           "name": name,
           "value": value
         })
       elif mode == "replace":
         envs.append("%(name)s=%(value)s" % {
           "name": name,
           "value": value
         })
       else:
         raise Exception("Unknown mode %s" % mode)
     raw_command = "%s %s" % (" ".join(envs), raw_command)
   if self.tee_dest:
     params = {
       "command_line": raw_command,
       "outpath": self.tee_dest
     }
     parts = [
       "%(command_line)s > %(outpath)s 2>&1 || echo > %(outpath)s.fail",
       "cat %(outpath)s",
       "if [ -f %(outpath)s.fail ]; then rm %(outpath)s %(outpath)s.fail; false; else true; fi",
     ]
     result = Command(*[part % params for part in parts])
   else:
     result = Command(raw_command)
   if self.comment:
     result.set_comment(self.comment)
   return result