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