1#!/usr/bin/env python
2# -*- Mode: python -*-
3
4#    Copyright (C) 2001-2006 Artifex Software Inc.
5#    All Rights Reserved.
6#
7# This software is provided AS-IS with no warranty, either express or
8# implied.
9#
10# This software is distributed under license and may not be copied, modified
11# or distributed except as expressly authorized under the terms of that
12# license.  Refer to licensing information at http://www.artifex.com/
13# or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
14# San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
15
16# $Id: make_two_versions 8409 2007-11-27 20:43:09Z giles $
17
18#
19# make_two_versions <filename> [<device> [<res> [<banding>]]]
20#
21# this script creates two versions of the file specified
22# one from baseline, and one from head
23# these are appropriate for a visual diff
24
25import gstestgs
26import gsconf
27import rasterdb
28import os, sys
29import string
30
31if len(sys.argv) < 2:
32    print "\n    usage: make_two_versions filename [ device:ppmraw [ res:72 [ banding:0 ] ] ]\n"
33    sys.exit()
34
35file = os.path.basename(sys.argv[1])
36if len(sys.argv) > 2:
37    device = sys.argv[2]
38else:
39    device = 'ppmraw'
40if len(sys.argv) > 3:
41    res = int(sys.argv[3])
42else:
43    res = 72
44if len(sys.argv) > 4:
45    banding = int(sys.argv[4])
46else:
47    banding = 0
48
49dbfile = "%s.%s.%d.%d" % (file, device, res, 0)
50ofile = "%s.%s.baseline.pnm" % (file, device)
51
52# check if raster for this baseline is in the database, and if so, use
53# it instead of generating approximate raster via baselinegs
54if rasterdb.exists(dbfile):
55    rasterdb.get_file(dbfile, output=ofile)
56else:
57    gs = gstestgs.Ghostscript()
58    gs.command = gsconf.baselinegs
59    gs.infile = gsconf.comparefiledir + file
60    gs.outfile = ofile
61    gs.device = device
62    gs.dpi = res
63    gs.band = banding
64    gs.log_stdout = gsconf.log_stdout
65    gs.log_stderr = gsconf.log_stderr
66
67    if not gs.process():
68        print "Error occurred running baseline Ghostscript."
69        sys.exit(1)
70
71ofile = "%s.%s.compare.pnm" % (file, device)
72
73gs = gstestgs.Ghostscript()
74gs.command = gsconf.comparegs
75gs.infile = gsconf.comparefiledir + file
76gs.outfile = ofile
77gs.device = device
78gs.dpi = res
79gs.band = banding
80gs.log_stdout = gsconf.log_stdout
81gs.log_stderr = gsconf.log_stderr
82
83if not gs.process():
84    print "Error occurred running compare Ghostscript."
85    sys.exit(1)
86