Exemple #1
0
 def anonymize(self, line):
     #log.debug('anonymize: line: %s', line)
     match = self.re_line_ending.search(line)
     line_ending = ''
     if match:
         line_ending = match.group(1)
     if self.strip_cr:
         line_ending = '\n'
     if not isPythonMinVersion(3):
         line = line.decode('utf-8').encode('ascii', errors='replace')
     line = strip_ansi_escape_codes(line)
     line = self.re_line_ending.sub('', line)
     for _ in self.anonymizations:
         if not self.anonymizations[_]:
             continue
         method = None
         try:
             #log.debug('checking for anonymize_%s', _)
             method = getattr(self, 'anonymize_' + _)
         except AttributeError:
             #log.debug('anonymize_%s not found', _)
             pass
         if method:
             #log.debug('found anonymize_%s: %s', _, method)
             line = method(line)
         else:
             line = self.anonymize_dynamic(_, line)
         if line is None:
             if method:
                 raise AssertionError('anonymize_{} returned None'.format(_))
             else:
                 raise AssertionError('anonymize_dynamic({}, line)'.format(_))
     line += line_ending
     return line
 def run(self):
     if not self.args:
         self.args.append('-')
     for arg in self.args:
         if arg == '-':
             continue
         if not os.path.exists(arg):
             print("'%s' not found" % arg)
             sys.exit(ERRORS['WARNING'])
         if os.path.isfile(arg):
             log_option('file', arg)
         elif os.path.isdir(arg):
             log_option('directory', arg)
         else:
             die("path '%s' could not be determined as either a file or directory"
                 % arg)
     for filename in self.args:
         if filename == '-':
             for line in sys.stdin.readlines():
                 print(strip_ansi_escape_codes(line), end='')
         else:
             with open(filename) as _:
                 for line in _.readlines():
                     print(strip_ansi_escape_codes(line), end='')
 def print_job_log(self, job=None, job_id=None):
     #if (self.color or not self.plaintext) and 'log' in job:
     if not job and not job_id:
         code_error('no job data or job id passed to print_job_log()')
     content = None
     if job is not None:
         if 'log' in job and job['log']:
             content = job['log']
         else:
             job_id = job['id']
     if not content:
         url = 'https://api.travis-ci.org/jobs/{id}/log.txt?deansi=true'.format(id=job_id)
         req = self.request_handler.get(url)
         content = req.content
     content = re.sub(r'\r', '', content)
     #if self.plaintext:
         # leaves a few characters behind which are printable
         #content = re.sub('[^{0}]'.format(string.printable), '', content)
     # mandatory stripping ANSI control sequences for now as although color coding is nice
     # Travis has too many other control sequences that mess up my terminal
     # strip all control sequences
     content = strip_ansi_escape_codes(content)
     print(content)