python php_syntax.py (-e pour voir seulement les fichiers contenant une erreur)
import os import mimetypes import string import sys def red(string): return '\x1b\x5b1;31;40m%s\x1b\x5b0;37;40m'%(string) def green(string): return '\x1b\x5b1;32;40m%s\x1b\x5b0;37;40m'%(string) def count(list): line_count = 0 for line in list: line_count += 1 return line_count mimeArray = ['application/x-httpd-php'] errors_count = 0 files_count = 0 lines_count = 0 bytes_count = 0 if '-e' in sys.argv: showonlyerror = 1 else: showonlyerror = 0 for path, dirs, files in os.walk('.'): for file in files: f_mime = mimetypes.guess_type(file) if f_mime[0] in mimeArray: f_path = os.path.join(path, file) a = os.popen('php -l %s'%(f_path)).readlines() b = open(f_path) counta = count(a) sizea = os.path.getsize(f_path) line_count = count(b) files_count += 1 bytes_count += sizea lines_count += line_count if counta > 1: errors_count += 1 print('%s'%(red(f_path))) print(' %s, %s line(s), %s byte(s)'%(f_mime[0], line_count, sizea)) for p in a: if p != '\n': print(' %s'%(p.strip())) else: if showonlyerror == 0: print('%s'%(green(f_path))) print(' %s, %s line(s), %s byte(s)'%(f_mime[0], line_count, sizea)) for p in a: print(' %s'%(p.strip())) print if errors_count > 0: print(' file(s): %i, lines: %i, bytes: %i, error: %s'%(files_count, lines_count, bytes_count, red(errors_count))) else: print(' file(s): %i, lines: %i, bytes: %i, error: %s'%(files_count, lines_count, bytes_count, green(errors_count))) |
