Debian Codegraph @

toolbin/tests/revert_pdfbaseline

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