Exemplo n.º 1
0
    def __init__(self, verbosity, log_file=None, verbosity_logf=999):
        tc.report_driver_c.__init__(self)
        if log_file:
            assert isinstance(log_file, basestring)

        self.tls = threading.local()

        if log_file:

            _basename, ext = os.path.splitext(log_file)
            if ext in self.compress:  # compressed logfile support
                kws = dict(log_file=log_file)
                # use shell + exec to try to game possible buffering
                # issues w/ Python and blocks
                command = self.compress[ext]
                pipe = subprocess.Popen("exec " + command % kws +
                                        " > '%s'" % log_file,
                                        shell=True,
                                        stdin=subprocess.PIPE)
                logf = pipe.stdin
                self.logf = commonl.io_tls_prefix_lines_c(
                    self.tls,
                    io.open(pipe.stdin.fileno(), "w"),
                    encoding='utf-8',
                    errors='replace')
            else:
                logf = io.open(log_file,
                               "w+",
                               encoding='utf-8',
                               errors='replace')
                self.logf = commonl.io_tls_prefix_lines_c(self.tls,
                                                          logf.detach(),
                                                          encoding='utf-8',
                                                          errors='replace')
        else:
            self.logf = None
        consolef = io.open("/dev/stdout",
                           "w",
                           encoding='utf-8',
                           errors='replace')
        self.consolef = commonl.io_tls_prefix_lines_c(self.tls,
                                                      consolef.detach(),
                                                      encoding='utf-8',
                                                      errors='replace')
        self.verbosity = verbosity
        self.verbosity_logf = verbosity_logf
Exemplo n.º 2
0
    def __init__(self, verbosity, log_file=None, verbosity_logf=999):
        tc.report_driver_c.__init__(self)
        if log_file:
            assert isinstance(log_file, str)

        self.tls = threading.local()

        if log_file:

            _basename, ext = os.path.splitext(log_file)
            if ext in self.compress:  # compressed logfile support
                kws = dict(log_file=log_file)
                # use shell + exec to try to game possible buffering
                # issues w/ Python and blocks
                command = self.compress[ext]
                pipe = subprocess.Popen("exec " + command % kws +
                                        " > '%s'" % log_file,
                                        shell=True,
                                        stdin=subprocess.PIPE)
                logf = io.open(pipe.stdin.fileno(),
                               "w",
                               encoding='utf-8',
                               errors='replace')
            else:
                logf = io.open(log_file,
                               "w+",
                               encoding='utf-8',
                               errors='replace')
            self.logf = commonl.io_tls_prefix_lines_c(self.tls, logf.detach())
        else:
            self.logf = None
        try:
            fd = sys.stdout.fileno()
        except AttributeError:
            # purposedly work around #@#@#DR those libraries who wrap around
            # sys.stdout to do whatever. Too bad
            fd = 1  # 1 is always stdout

        consolef = io.open(fd, "wb")
        self.consolef = commonl.io_tls_prefix_lines_c(self.tls,
                                                      consolef.detach())
        self.verbosity = verbosity
        self.verbosity_logf = verbosity_logf
Exemplo n.º 3
0
 def _get_fd(self, code, tmpdir):
     # FIXME: document the decorator
     if not code in self.fs:
         # open truncating because this is a new entry
         f = io.open(os.path.join(tmpdir, "report-" + code + ".txt"), "wb")
         self.fs[code] = f.name
     else:
         f = io.open(self.fs[code], "a+b")
     # reassign the stream so we use the prefix printing
     # capabilities
     return commonl.io_tls_prefix_lines_c(self.tls, f.detach())
Exemplo n.º 4
0
 def _get_fd(self, code, tmpdir):
     # FIXME: document the decorator
     if not code in self.fs:
         f = io.open(os.path.join(tmpdir, "report-" + code + ".txt"),
                     "w",
                     encoding='utf-8',
                     errors='replace')
         self.fs[code] = f.name
     else:
         f = io.open(self.fs[code],
                     "a+",
                     encoding='utf-8',
                     errors='replace')
     # reassign the stream so we use the prefix printing
     # capabilities
     return commonl.io_tls_prefix_lines_c(self.tls,
                                          f.detach(),
                                          encoding='utf-8',
                                          errors='replace')