| 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 |
# update_specific [ <svn date spec> | -r <svn revision> ] |
| 21 |
# |
| 22 |
# pass files to update via stdin in the following format: |
| 23 |
# (N|P) <file> |
| 24 |
# N for normal regression test, P for pdfwrite regression test |
| 25 |
# <file> must not include a path and must be a file in the |
| 26 |
# comparefiles directory |
| 27 |
|
| 28 |
import os |
| 29 |
import sys |
| 30 |
import string |
| 31 |
import time |
| 32 |
import tempfile |
| 33 |
import anydbm |
| 34 |
import re |
| 35 |
from popen2 import Popen4 |
| 36 |
|
| 37 |
import gstestgs |
| 38 |
import gsconf |
| 39 |
import gssum |
| 40 |
import gsparamsets |
| 41 |
import rasterdb |
| 42 |
|
| 43 |
def norm_entry(cmd, ifile, device, dpi, band, datespec): |
| 44 |
ofile = "%s.%s.%d.%d" % (ifile, device, dpi, band) |
| 45 |
print "updating entry: " + ofile + "...", |
| 46 |
sys.stdout.flush() |
| 47 |
|
| 48 |
gs = gstestgs.Ghostscript() |
| 49 |
gs.command = cmd |
| 50 |
gs.log_stdout = gsconf.log_stdout |
| 51 |
gs.log_stderr = gsconf.log_stderr |
| 52 |
gs.infile = gsconf.comparefiledir + ifile |
| 53 |
gs.outfile = ofile |
| 54 |
gs.device = device |
| 55 |
gs.dpi = dpi |
| 56 |
gs.band = band |
| 57 |
|
| 58 |
if gs.process(): |
| 59 |
try: |
| 60 |
if gsconf.log_baseline: |
| 61 |
log = open(gsconf.log_baseline, "a") |
| 62 |
log.write(time.ctime() + " " + ifile + " updated "\ |
| 63 |
"[" + datespec + "]\n") |
| 64 |
log.close() |
| 65 |
gssum.add_file(ofile) |
| 66 |
rasterdb.put_file(ofile) |
| 67 |
os.unlink(ofile) |
| 68 |
print "done." |
| 69 |
except OSError: |
| 70 |
print "no output produced." |
| 71 |
else: |
| 72 |
print "error." |
| 73 |
|
| 74 |
def pdf_entry(cmd, ifile, device, dpi, band, datespec): |
| 75 |
ofile = "%s.pdf.%s.%d.%d" % (ifile, device, dpi, band) |
| 76 |
print "updating entry: " + ofile + "...", |
| 77 |
sys.stdout.flush() |
| 78 |
|
| 79 |
gs = gstestgs.Ghostscript() |
| 80 |
gs.log_stdout = gsconf.log_stdout |
| 81 |
gs.log_stderr = gsconf.log_stderr |
| 82 |
gs.command = cmd |
| 83 |
gs.infile = gsconf.comparefiledir + ifile |
| 84 |
gs.dpi = dpi |
| 85 |
gs.band = band |
| 86 |
|
| 87 |
# make file->PDF |
| 88 |
|
| 89 |
tfile = ofile + ".pdf" |
| 90 |
gs.outfile = tfile |
| 91 |
gs.device = 'pdfwrite' |
| 92 |
gs.dpi = None |
| 93 |
|
| 94 |
if not gs.process(): |
| 95 |
print "error." |
| 96 |
return |
| 97 |
|
| 98 |
gs.infile = tfile |
| 99 |
gs.outfile = ofile |
| 100 |
gs.device = device |
| 101 |
gs.dpi = dpi |
| 102 |
|
| 103 |
if gs.process(): |
| 104 |
try: |
| 105 |
if gsconf.log_baseline: |
| 106 |
log = open(gsconf.log_baseline, "a") |
| 107 |
log.write(time.ctime() + " " + ifile + " updated (pdfwrite) "\ |
| 108 |
"[" + datespec + "]\n") |
| 109 |
log.close() |
| 110 |
gssum.add_file(ofile) |
| 111 |
rasterdb.put_file(ofile) |
| 112 |
os.unlink(tfile) |
| 113 |
os.unlink(ofile) |
| 114 |
print "done." |
| 115 |
except OSError: |
| 116 |
print "no output produced." |
| 117 |
else: |
| 118 |
print "error." |
| 119 |
|
| 120 |
|
| 121 |
TMP_PREFIX = "REGBUILD." |
| 122 |
|
| 123 |
def make_temp_dir(): |
| 124 |
return tempfile.mkdtemp(prefix=TMP_PREFIX) |
| 125 |
|
| 126 |
def kill_temp_dir(dir): |
| 127 |
if string.find(dir, TMP_PREFIX) == -1: |
| 128 |
raise StandardError, "Tried to kill a non temp dir!" |
| 129 |
|
| 130 |
for root, dirs, files in os.walk(dir, topdown=False): |
| 131 |
for name in files: |
| 132 |
os.remove(os.path.join(root, name)) |
| 133 |
for name in dirs: |
| 134 |
os.rmdir(os.path.join(root, name)) |
| 135 |
os.rmdir(dir) |
| 136 |
|
| 137 |
def run(cmd, dir): |
| 138 |
try: |
| 139 |
os.chdir(dir) |
| 140 |
pipe = Popen4(cmd) |
| 141 |
line = pipe.fromchild.readline() |
| 142 |
while len(line) > 0: |
| 143 |
sys.stdout.write(line) |
| 144 |
sys.stdout.flush() |
| 145 |
line = pipe.fromchild.readline() |
| 146 |
ret = pipe.wait() |
| 147 |
except OSError, e: |
| 148 |
print "ERROR: An exception occured:", e |
| 149 |
ret = -1 |
| 150 |
|
| 151 |
return ret |
| 152 |
|
| 153 |
def change_gsproduct(file): |
| 154 |
tmpfile = "%s.tmp" % (file,) |
| 155 |
|
| 156 |
startre = re.compile("^#ifndef\ GS_PRODUCT$") |
| 157 |
changere = re.compile("^.*?\"[A-Za-z -]+\".*?$") |
| 158 |
endre = re.compile("^$") |
| 159 |
|
| 160 |
old = open(file, "r") |
| 161 |
new = open(tmpfile, "w") |
| 162 |
|
| 163 |
state = 0 |
| 164 |
for line in old.readlines(): |
| 165 |
if state == 0: |
| 166 |
m = startre.search(line) |
| 167 |
if m: |
| 168 |
state = 1 |
| 169 |
|
| 170 |
new.write(line) |
| 171 |
elif state == 1: |
| 172 |
m = changere.search(line) |
| 173 |
if m: |
| 174 |
state = 2 |
| 175 |
new.write("\t\"GPL Ghostscript\"\n") |
| 176 |
else: |
| 177 |
new.write(line) |
| 178 |
elif state == 2: |
| 179 |
m = endre.search(line) |
| 180 |
if m: |
| 181 |
state = 0 |
| 182 |
|
| 183 |
new.write(line) |
| 184 |
|
| 185 |
|
| 186 |
old.close() |
| 187 |
new.close() |
| 188 |
|
| 189 |
os.unlink(file) |
| 190 |
os.rename(tmpfile, file) |
| 191 |
|
| 192 |
if len(sys.argv) < 2: |
| 193 |
print "Not enough arguments." |
| 194 |
print "usage: update_specific [ -r <revision> | <svn date spec> ]" |
| 195 |
print |
| 196 |
sys.exit(1) |
| 197 |
|
| 198 |
if sys.argv[1] == '-r': |
| 199 |
revspec = sys.argv[2] |
| 200 |
else: |
| 201 |
revspec = "{\"" + sys.argv[1] + "\"}" |
| 202 |
|
| 203 |
normset = [] |
| 204 |
pdfset = [] |
| 205 |
for line in sys.stdin.readlines(): |
| 206 |
line = string.strip(line) |
| 207 |
if line[0] == 'N' and line[1] == ' ': |
| 208 |
normset.append(string.replace(line[2:], '"', '')) |
| 209 |
elif line[0] == 'P' and line[1] == ' ': |
| 210 |
pdfset.append(string.replace(line[2:], '"', '')) |
| 211 |
else: |
| 212 |
print "Wrong format of arguments given:", line |
| 213 |
sys.exit(1) |
| 214 |
|
| 215 |
print "normal:", normset |
| 216 |
print "pdf:", pdfset |
| 217 |
|
| 218 |
# create the build/install directories and subdirectories |
| 219 |
tmpdir = make_temp_dir() |
| 220 |
svndir = os.path.join(tmpdir, "svn") |
| 221 |
instdir = os.path.join(tmpdir, "inst") |
| 222 |
builddir = os.path.join(svndir, "gs") |
| 223 |
os.mkdir(svndir) |
| 224 |
os.mkdir(instdir) |
| 225 |
|
| 226 |
try: |
| 227 |
# do the svn checkout |
| 228 |
ret = run("svn checkout -r " + revspec + |
| 229 |
" " + gsconf.repository + "/trunk/gs", svndir) |
| 230 |
if ret != 0: |
| 231 |
raise StandardError, "ERROR: SVN checkout failed" |
| 232 |
|
| 233 |
# now configure and build Ghostscript |
| 234 |
ret = run("./autogen.sh --prefix=" + instdir, builddir) |
| 235 |
if ret != 0: |
| 236 |
raise StandardError, "ERROR: configure failed" |
| 237 |
|
| 238 |
os.chdir(builddir) |
| 239 |
change_gsproduct(os.path.join(builddir, "src/gscdef.c")) |
| 240 |
|
| 241 |
ret = run("make", builddir) |
| 242 |
if ret != 0: |
| 243 |
raise StandardError, "ERROR: make failed" |
| 244 |
|
| 245 |
ret = run("make install", builddir) |
| 246 |
if ret != 0: |
| 247 |
raise StandardError, "ERROR: make install failed" |
| 248 |
|
| 249 |
# install fonts |
| 250 |
fontdir = os.path.join(instdir, "share", "ghostscript", "fonts") |
| 251 |
os.mkdir(fontdir) |
| 252 |
ret = run("cp " + gsconf.fontdir + "* " + fontdir, instdir) |
| 253 |
if ret != 0: |
| 254 |
raise StandardError, "ERROR: font installation failed" |
| 255 |
|
| 256 |
# update baselines |
| 257 |
os.chdir(tmpdir) |
| 258 |
gscmd = os.path.join(instdir, "bin", "gs") |
| 259 |
for f in normset: |
| 260 |
for params in gsparamsets.testparamsets: |
| 261 |
norm_entry(gscmd, f, params.device, params.resolution, |
| 262 |
params.banding, revspec) |
| 263 |
for f in pdfset: |
| 264 |
for params in gsparamsets.pdftestparamsets: |
| 265 |
pdf_entry(gscmd, f, params.device, params.resolution, |
| 266 |
params.banding, revspec) |
| 267 |
|
| 268 |
except StandardError, e: |
| 269 |
print "ERROR:", e |
| 270 |
|
| 271 |
# clean up our mess |
| 272 |
kill_temp_dir(tmpdir) |