-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure-files.py
168 lines (154 loc) · 5.42 KB
/
configure-files.py
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
#
# This file is part of the "UpLib 1.7.11" release.
# Copyright (C) 2003-2011 Palo Alto Research Center, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
import sys, os, re, socket, pprint
def read_substitutions_file (filepath):
substitutions = {}
linecounter = 0
fp = open(filepath)
for line in fp:
linecounter += 1
line = line.strip()
if (not line) or (line[0] == '#'):
# blank or comment line
continue
values = re.split(r"\s+", line, 1)
if (len(values) < 1) or not values[0].strip():
sys.stderr.write("Bad value on line %d in file %s: '%s'!\n" % (linecounter, filepath, line.strip()))
sys.exit(1)
name = values[0].strip()
if len(values) > 1:
value = values[1].strip()
else:
value = None
if value and (value[0] != '@' or value[-1] != '@'):
substitutions[name] = value.replace("\\", "\\\\")
else:
substitutions[name] = ''
fp.close()
return substitutions
FILES_TO_CONFIGURE = [
"site.config",
"Makefile",
"python/Makefile",
"python/uplib/plibUtil.py",
"java/Makefile",
"java/build-topdf-library.sh",
"java/machine.config",
"c/Makefile",
"c/findimages/Makefile",
"commandline/Makefile",
"commandline/uplib-check-angel",
"commandline/uplib-make-repository",
"commandline/uplib-ps2pdf",
"commandline/uplib-pdf2ps",
"commandline/uplib-openoffice-convert-to-pdf",
"commandline/uplib-openoffice-convert-to-pdf-via-server",
"commandline/uplib-add-document",
"commandline/uplib-get-document",
"commandline/uplib-portal",
"commandline/uplib-version",
"commandline/uplib-janitor",
"commandline/uplib-certificate",
"commandline/readup",
"commandline/uplib-setup-openoffice",
"commandline/uplib-cache-url",
"commandline/mount_uvfs",
"commandline/mount_uvfs2",
"commandline/uplib-topdf",
"commandline/uplib-webkit2pdf",
"extensions/Makefile",
"doc/Makefile",
"doc/info.html",
"doc/collections.html",
"doc/searching.html",
"doc/extensions.html",
"doc/FAQ.html",
"doc/about.html",
"doc/index.html",
"doc/manual.txt",
]
if sys.platform == 'win32':
FILES_TO_CONFIGURE += [
"win32/Makefile",
"win32/cmdprogs/Makefile",
"win32/cmdprogs/uplib-check-angel.bat",
"win32/cmdprogs/uplib-make-repository.bat",
"win32/cmdprogs/uplib-ps2pdf.bat",
"win32/cmdprogs/uplib-add-document.bat",
"win32/cmdprogs/uplib-get-document.bat",
"win32/cmdprogs/uplib-portal.bat",
"win32/cmdprogs/uplib-topdf.bat",
"win32/cmdprogs/uplib-janitor.bat",
"win32/cmdprogs/uplib-certificate.bat",
"win32/cmdprogs/readup.bat",
"win32/cmdprogs/uplib-tiff-split.bat",
"win32/cmdprogs/uplib-openoffice-convert-to-pdf.bat",
"win32/cmdprogs/uplib-check-windows-service-right.py",
"win32/createWinShortcuts.py",
]
else:
FILES_TO_CONFIGURE += [
"unix/Makefile",
"unix/linux/Makefile",
"unix/macosx/Makefile",
"unix/macosx/uplib-print-pdf-to-repository",
"unix/macosx/com.parc.uplib.ToPDFAgent.plist",
]
# optional files -- might be there, might not
for pathname in ["tests/Makefile",]:
if os.path.exists(pathname + ".in"):
FILES_TO_CONFIGURE.append(pathname)
if len(sys.argv) < 2:
sys.stderr.write("Usage: REPLACEMENTS-FILE\n")
sys.exit(2)
if not os.path.exists(sys.argv[1]):
sys.stderr.write("Replacements file %s does not exist!\n" % sys.argv[1])
sys.exit(3)
# read the substitutions
substitutions = {}
for filename in sys.argv[1:]:
sys.stderr.write("reading %s...\n" % filename)
newsubs = read_substitutions_file(filename)
substitutions.update(newsubs)
for key, value in substitutions.items():
if not value:
sys.stderr.write("No value for %s...\n" % key)
substitutions[re.compile('@' + key + '@')] = value
del substitutions[key]
# now apply them
for filename in FILES_TO_CONFIGURE:
if not os.path.exists(filename + ".in"):
sys.stderr.write("No such file %s!\n" % filename)
sys.exit(5)
else:
sys.stderr.write("Doing %s...\n" % filename)
infp = open(filename + ".in")
outfp = open(filename, 'w')
for line in infp:
for expression, replacement in substitutions.items():
try:
line = expression.sub(replacement, line, 0)
except:
sys.stderr.write("Exception processing line <%s> with expr <%s> and replacement <%s>\n" % (line.strip(), expression.pattern, replacement))
sys.exit(6)
outfp.write(line)
outfp.close()
infp.close()
sys.stderr.write("Done.\n")
sys.exit(0)