Exemplo n.º 1
0
def execute(command, printer=debug):
    popen = subprocess.Popen(command,
                             shell=is_string(command),
                             stdout=subprocess.PIPE)
    lines_iterator = iter(popen.stdout.readline, "")
    for line in lines_iterator:
        if not line: break
        printer(to_unicode(line).strip("\n"))  # yield line
    out = to_unicode(popen.communicate()[0])
    printer(out.strip("\n"))
    return popen.returncode
Exemplo n.º 2
0
def getStatusOutputBash(command):
    assert is_string(command), "only strings accepted as command"
    popen = subprocess.Popen([BASH, "-c", command],
                             shell=False,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
    out = to_unicode(popen.communicate()[0])
    return (popen.returncode, out)
Exemplo n.º 3
0
 def test_to_unicode(self):
     t1 = "ताड़िद्दा"
     t2 = u"\u0924\u093e\u0921\u093c\u093f\u0926\u094d\u0926\u093e"
     self.assertTrue(to_unicode(t1) == t2)
     self.assertTrue(to_unicode(t1) == to_unicode(t2))
     self.assertTrue(to_unicode([1, 2, 3]) == u"[1, 2, 3]")
     self.assertTrue(to_unicode({"a": -1}) == u"{'a': -1}")
     self.assertTrue(to_unicode(123456) == u"123456")
Exemplo n.º 4
0
 def test_to_unicode(self):
   t1 = "ताड़िद्दा"
   t2 = u"\u0924\u093e\u0921\u093c\u093f\u0926\u094d\u0926\u093e"
   self.assertTrue(to_unicode(t1) == t2)
   self.assertTrue(to_unicode(t1) == to_unicode(t2))
   self.assertTrue(to_unicode([1,2,3]) == u"[1, 2, 3]")
   self.assertTrue(to_unicode({"a":-1}) == u"{'a': -1}")
   self.assertTrue(to_unicode(123456) == u"123456")
Exemplo n.º 5
0
 def format(self, record):
   record.msg = to_unicode(record.msg)
   if record.levelno == logging.BANNER and sys.stdout.isatty():
     lines = record.msg.split("\n")
     return "\n\033[1;34m==>\033[m \033[1m%s\033[m" % lines[0] + \
            "".join([ "\n    \033[1m%s\033[m" % x for x in lines[1:] ])
   elif record.levelno == logging.INFO or record.levelno == logging.BANNER:
     return record.msg
   return "\n".join([ format(self.fmtstr,
                             levelname=self.LEVEL_COLORS.get(record.levelno, self.COLOR_RESET) +
                                       record.levelname +
                                       self.COLOR_RESET,
                             message=x)
                      for x in record.msg.split("\n") ])
Exemplo n.º 6
0
 def format(self, record):
   record.msg = to_unicode(record.msg)
   if record.levelno == logging.BANNER and sys.stdout.isatty():
     lines = record.msg.split("\n")
     return "\n\033[1;34m==>\033[m \033[1m%s\033[m" % lines[0] + \
            "".join([ "\n    \033[1m%s\033[m" % x for x in lines[1:] ])
   elif record.levelno == logging.INFO or record.levelno == logging.BANNER:
     return record.msg
   return "\n".join([ format(self.fmtstr,
                             levelname=self.LEVEL_COLORS.get(record.levelno, self.COLOR_RESET) +
                                       record.levelname +
                                       self.COLOR_RESET,
                             message=x)
                      for x in record.msg.split("\n") ])