1#!/usr/bin/env python
2# -*- Mode: python -*-
3
4#    Copyright (C) 2001 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: revert_pdfbaseline 8409 2007-11-27 20:43:09Z giles $
17
18#
19# revert_pdfbaseline <file>
20#
21# this script updates the testdata database with a new baseline sum
22# for all versions of file <file>.  use this when you've accidentally
23# updated a baseline you shouldn't have.
24
25import gstestgs
26import gsconf
27import gssum
28import gsparamsets
29import rasterdb
30import anydbm
31import time
32import os, sys
33import string
34import gsutil
35
36def make_pdfcompare_entry(ifile, device, dpi, band):
37    ofile = "%s.pdf.%s.%d.%d" % (ifile, device, dpi, band)
38    print "reverting entry: " + ofile + "...",
39    sys.stdout.flush()
40
41    gs = gstestgs.Ghostscript()
42    gs.log_stdout = gsconf.log_stdout
43    gs.log_stderr = gsconf.log_stderr
44    gs.command = gsconf.baselinegs
45    gs.infile = gsconf.comparefiledir + ifile
46    gs.dpi = dpi
47    gs.band = band
48
49    # make file->PDF
50
51    tfile = ofile + ".pdf"
52    gs.outfile = tfile
53    gs.device = 'pdfwrite'
54    gs.dpi = None
55
56    if not gs.process():
57        print "error."
58        return
59
60    gs.infile = tfile
61    gs.outfile = ofile
62    gs.device = device
63    gs.dpi = dpi
64
65    if gs.process():
66        try:
67	    if gsconf.log_baseline:
68	        log = open(gsconf.log_baseline, "a")
69		log.write(time.ctime() + " " + ifile + " reverted (pdfwrite)\n")
70		log.close()
71            gssum.add_file(ofile)
72            rasterdb.put_file(ofile)
73            os.unlink(tfile)
74            os.unlink(ofile)
75            print "done."
76        except OSError:
77            print "no output produced."
78    else:
79        print "error."
80
81f = os.path.basename(sys.argv[1])
82
83if gsutil.check_extension(f):
84    for params in gsparamsets.testparamsets:
85        make_pdfcompare_entry(f, params.device, params.resolution, params.banding)
86