1*c8dee2aaSAndroid Build Coastguard Worker''' 2*c8dee2aaSAndroid Build Coastguard WorkerCompares the rendererings of serialized SkPictures to expected images. 3*c8dee2aaSAndroid Build Coastguard Worker 4*c8dee2aaSAndroid Build Coastguard WorkerLaunch with --help to see more information. 5*c8dee2aaSAndroid Build Coastguard Worker 6*c8dee2aaSAndroid Build Coastguard Worker 7*c8dee2aaSAndroid Build Coastguard WorkerCopyright 2012 Google Inc. 8*c8dee2aaSAndroid Build Coastguard Worker 9*c8dee2aaSAndroid Build Coastguard WorkerUse of this source code is governed by a BSD-style license that can be 10*c8dee2aaSAndroid Build Coastguard Workerfound in the LICENSE file. 11*c8dee2aaSAndroid Build Coastguard Worker''' 12*c8dee2aaSAndroid Build Coastguard Worker# common Python modules 13*c8dee2aaSAndroid Build Coastguard Workerimport os 14*c8dee2aaSAndroid Build Coastguard Workerimport optparse 15*c8dee2aaSAndroid Build Coastguard Workerimport sys 16*c8dee2aaSAndroid Build Coastguard Workerimport shutil 17*c8dee2aaSAndroid Build Coastguard Workerimport tempfile 18*c8dee2aaSAndroid Build Coastguard Workerimport test_rendering 19*c8dee2aaSAndroid Build Coastguard Worker 20*c8dee2aaSAndroid Build Coastguard WorkerUSAGE_STRING = 'Usage: %s input... expectedDir' 21*c8dee2aaSAndroid Build Coastguard WorkerHELP_STRING = ''' 22*c8dee2aaSAndroid Build Coastguard Worker 23*c8dee2aaSAndroid Build Coastguard WorkerTakes input SkPicture files and renders them as PDF files, and then compares 24*c8dee2aaSAndroid Build Coastguard Workerthose resulting PDF files against PDF files found in expectedDir. 25*c8dee2aaSAndroid Build Coastguard Worker 26*c8dee2aaSAndroid Build Coastguard WorkerEach instance of "input" can be either a file (name must end in .skp), or a 27*c8dee2aaSAndroid Build Coastguard Workerdirectory (in which case this script will process all .skp files within the 28*c8dee2aaSAndroid Build Coastguard Workerdirectory). 29*c8dee2aaSAndroid Build Coastguard Worker''' 30*c8dee2aaSAndroid Build Coastguard Worker 31*c8dee2aaSAndroid Build Coastguard Worker 32*c8dee2aaSAndroid Build Coastguard Workerdef Main(args): 33*c8dee2aaSAndroid Build Coastguard Worker """Allow other scripts to call this script with fake command-line args. 34*c8dee2aaSAndroid Build Coastguard Worker 35*c8dee2aaSAndroid Build Coastguard Worker @param The commandline argument list 36*c8dee2aaSAndroid Build Coastguard Worker """ 37*c8dee2aaSAndroid Build Coastguard Worker parser = optparse.OptionParser(USAGE_STRING % '%prog' + HELP_STRING) 38*c8dee2aaSAndroid Build Coastguard Worker parser.add_option('--render_dir', dest='render_dir', 39*c8dee2aaSAndroid Build Coastguard Worker help = ('specify the location to output the rendered ' 40*c8dee2aaSAndroid Build Coastguard Worker 'files. Default is a temp directory.')) 41*c8dee2aaSAndroid Build Coastguard Worker parser.add_option('--diff_dir', dest='diff_dir', 42*c8dee2aaSAndroid Build Coastguard Worker help = ('specify the location to output the diff files. ' 43*c8dee2aaSAndroid Build Coastguard Worker 'Default is a temp directory.')) 44*c8dee2aaSAndroid Build Coastguard Worker 45*c8dee2aaSAndroid Build Coastguard Worker options, arguments = parser.parse_args(args) 46*c8dee2aaSAndroid Build Coastguard Worker 47*c8dee2aaSAndroid Build Coastguard Worker if (len(arguments) < 3): 48*c8dee2aaSAndroid Build Coastguard Worker print("Expected at least one input and one ouput folder.") 49*c8dee2aaSAndroid Build Coastguard Worker parser.print_help() 50*c8dee2aaSAndroid Build Coastguard Worker sys.exit(-1) 51*c8dee2aaSAndroid Build Coastguard Worker 52*c8dee2aaSAndroid Build Coastguard Worker inputs = arguments[1:-1] 53*c8dee2aaSAndroid Build Coastguard Worker expected_dir = arguments[-1] 54*c8dee2aaSAndroid Build Coastguard Worker 55*c8dee2aaSAndroid Build Coastguard Worker test_rendering.TestRenderSkps(inputs, expected_dir, options.render_dir, 56*c8dee2aaSAndroid Build Coastguard Worker options.diff_dir, 'render_pdfs', '') 57*c8dee2aaSAndroid Build Coastguard Worker 58*c8dee2aaSAndroid Build Coastguard Workerif __name__ == '__main__': 59*c8dee2aaSAndroid Build Coastguard Worker Main(sys.argv) 60*c8dee2aaSAndroid Build Coastguard Worker 61