#!/usr/bin/python import sys import os import datetime import argparse try: # Use pip to install Pillow and Image to enable image diffs from PIL import Image, ImageChops DIFF_ENABLED = True except Exception: DIFF_ENABLED = False def createDiff(image1Path, image2Path, imageDiffPath): try: if os.path.exists(imageDiffPath): os.remove(imageDiffPath) if not os.path.exists(image1Path): print ("Image diff input missing: " + image1Path) return if not os.path.exists(image2Path): print ("Image diff input missing: " + image2Path) return image1 = Image.open(image1Path).convert('RGB') image2 = Image.open(image2Path).convert('RGB') diff = ImageChops.difference(image1, image2) diff.save(imageDiffPath) except Exception: if os.path.exists(imageDiffPath): os.remove(imageDiffPath) print ("Failed to create image diff between: " + image1Path + ", " + image2Path) def main(args=None): parser = argparse.ArgumentParser() parser.add_argument('-i1', '--inputdir1', dest='inputdir1', action='store', help='Input directory', default=".") parser.add_argument('-i2', '--inputdir2', dest='inputdir2', action='store', help='Second input directory', default="") parser.add_argument('-i3', '--inputdir3', dest='inputdir3', action='store', help='Third input directory', default="") parser.add_argument('-o', '--outputfile', dest='outputfile', action='store', help='Output file name', default="tests.html") parser.add_argument('-d', '--diff', dest='CREATE_DIFF', action='store_true', help='Perform image diff', default=False) parser.add_argument('-t', '--timestamp', dest='ENABLE_TIMESTAMPS', action='store_true', help='Write image timestamps', default=False) parser.add_argument('-w', '--imagewidth', type=int, dest='imagewidth', action='store', help='Set image display width', default=256) parser.add_argument('-ht', '--imageheight', type=int, dest='imageheight', action='store', help='Set image display height', default=256) parser.add_argument('-cp', '--cellpadding', type=int, dest='cellpadding', action='store', help='Set table cell padding', default=0) parser.add_argument('-tb', '--tableborder', type=int, dest='tableborder', action='store', help='Table border width. 0 means no border', default=3) parser.add_argument('-l1', '--lang1', dest='lang1', action='store', help='First target language for comparison. Default is glsl', default="glsl") parser.add_argument('-l2', '--lang2', dest='lang2', action='store', help='Second target language for comparison. Default is osl', default="osl") parser.add_argument('-l3', '--lang3', dest='lang3', action='store', help='Third target language for comparison. Default is empty', default="") args = parser.parse_args(args) fh = open(args.outputfile,"w+") fh.write("\n") fh.write("") fh.write("
\n") if args.inputdir1 == ".": args.inputdir1 = os.getcwd() if args.inputdir2 == ".": args.inputdir2 = os.getcwd() elif args.inputdir2 == "": args.inputdir2 = args.inputdir1 if args.inputdir3 == ".": args.inputdir3 = os.getcwd() elif args.inputdir3 == "": args.inputdir3 = args.inputdir1 useThirdLang = args.lang3 if useThirdLang: fh.write("" + os.path.normpath(path1) + ":
\n") fh.write("| " + file1)
if args.ENABLE_TIMESTAMPS and os.path.isfile(fullPath1):
fh.write(" (" + str(datetime.datetime.fromtimestamp(os.path.getmtime(fullPath1))) + ")") fh.write(" | \n")
if fullPath2:
fh.write("" + file2)
if args.ENABLE_TIMESTAMPS and os.path.isfile(fullPath2):
fh.write(" (" + str(datetime.datetime.fromtimestamp(os.path.getmtime(fullPath2))) + ")") fh.write(" | \n")
if fullPath3:
fh.write("" + file3)
if args.ENABLE_TIMESTAMPS and os.path.isfile(fullPath3):
fh.write(" (" + str(datetime.datetime.fromtimestamp(os.path.getmtime(fullPath3))) + ")") fh.write(" | \n")
if diffPath1:
fh.write("Difference " + args.lang1 + " vs. " + args.lang2 + " | \n") if diffPath2: fh.write("Difference " + args.lang1 + " vs. " + args.lang3 + " | \n") if diffPath3: fh.write("Difference " + args.lang2 + " vs. " + args.lang3 + " | \n") fh.write("