Skip to content

Commit 999eeb2

Browse files
committed
Bug 812179 - Removed hacks for Python < 2.6 from config/ [r=ted]
1 parent 72663e9 commit 999eeb2

32 files changed

+309
-289
lines changed

config/Expression.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ def __init__(self, expression):
218218
self.offset = expression.offset
219219
self.content = expression.content[:3]
220220
def __str__(self):
221-
return 'Unexpected content at offset %i, "%s"'%(self.offset, self.content)
221+
return 'Unexpected content at offset {0}, "{1}"'.format(self.offset,
222+
self.content)
222223

223224
class Context(dict):
224225
"""

config/JarMaker.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
88
See the documentation for jar.mn on MDC for further details on the format.
99
'''
10-
1110
import sys
1211
import os
1312
import os.path
@@ -152,11 +151,12 @@ def finalizeJar(self, jarPath, chromebasepath, register,
152151
'..', 'chrome.manifest')
153152

154153
if self.useJarfileManifest:
155-
self.updateManifest(jarPath + '.manifest', chromebasepath % '',
154+
self.updateManifest(jarPath + '.manifest', chromebasepath.format(''),
156155
register)
157-
addEntriesToListFile(chromeManifest, ['manifest chrome/%s.manifest' % (os.path.basename(jarPath),)])
156+
addEntriesToListFile(chromeManifest, ['manifest chrome/{0}.manifest'
157+
.format(os.path.basename(jarPath))])
158158
if self.useChromeManifest:
159-
self.updateManifest(chromeManifest, chromebasepath % 'chrome/',
159+
self.updateManifest(chromeManifest, chromebasepath.format('chrome/'),
160160
register)
161161

162162
# If requested, add a root chrome manifest entry (assumed to be in the parent directory
@@ -258,9 +258,9 @@ def processJarSection(self, jarfile, lines, jardir):
258258
'''
259259

260260
# chromebasepath is used for chrome registration manifests
261-
# %s is getting replaced with chrome/ for chrome.manifest, and with
261+
# {0} is getting replaced with chrome/ for chrome.manifest, and with
262262
# an empty string for jarfile.manifest
263-
chromebasepath = '%s' + os.path.basename(jarfile)
263+
chromebasepath = '{0}' + os.path.basename(jarfile)
264264
if self.outputFormat == 'jar':
265265
chromebasepath = 'jar:' + chromebasepath + '.jar!'
266266
chromebasepath += '/'
@@ -272,7 +272,7 @@ def processJarSection(self, jarfile, lines, jardir):
272272
jarfilepath = jarfile + '.jar'
273273
try:
274274
os.makedirs(os.path.dirname(jarfilepath))
275-
except OSError, error:
275+
except OSError as error:
276276
if error.errno != errno.EEXIST:
277277
raise
278278
jf = ZipFile(jarfilepath, 'a', lock = True)
@@ -345,7 +345,8 @@ def _processEntryLine(self, m, outHelper, jf):
345345
if realsrc is None:
346346
if jf is not None:
347347
jf.close()
348-
raise RuntimeError('File "%s" not found in %s' % (src, ', '.join(src_base)))
348+
raise RuntimeError('File "{0}" not found in {1}'
349+
.format(src, ', '.join(src_base)))
349350
if m.group('optPreprocess'):
350351
outf = outHelper.getOutput(out)
351352
inf = open(realsrc)
@@ -401,7 +402,7 @@ def getOutput(self, name):
401402
# remove previous link or file
402403
try:
403404
os.remove(out)
404-
except OSError, e:
405+
except OSError as e:
405406
if e.errno != errno.ENOENT:
406407
raise
407408
return open(out, 'wb')
@@ -411,7 +412,7 @@ def ensureDirFor(self, name):
411412
if not os.path.isdir(outdir):
412413
try:
413414
os.makedirs(outdir)
414-
except OSError, error:
415+
except OSError as error:
415416
if error.errno != errno.EEXIST:
416417
raise
417418
return out
@@ -425,7 +426,7 @@ def symlink(self, src, dest):
425426
# remove previous link or file
426427
try:
427428
os.remove(out)
428-
except OSError, e:
429+
except OSError as e:
429430
if e.errno != errno.ENOENT:
430431
raise
431432
if sys.platform != "win32":

config/Preprocessor.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ def __init__(self):
7777

7878
def warnUnused(self, file):
7979
if self.actionLevel == 0:
80-
sys.stderr.write('%s: WARNING: no preprocessor directives found\n' % file)
80+
sys.stderr.write('{0}: WARNING: no preprocessor directives found\n'.format(file))
8181
elif self.actionLevel == 1:
82-
sys.stderr.write('%s: WARNING: no useful preprocessor directives found\n' % file)
82+
sys.stderr.write('{0}: WARNING: no useful preprocessor directives found\n'.format(file))
8383
pass
8484

8585
def setLineEndings(self, aLE):
@@ -96,7 +96,9 @@ def setMarker(self, aMarker):
9696
"""
9797
self.marker = aMarker
9898
if aMarker:
99-
self.instruction = re.compile('%s(?P<cmd>[a-z]+)(?:\s(?P<args>.*))?$'%aMarker, re.U)
99+
self.instruction = re.compile('{0}(?P<cmd>[a-z]+)(?:\s(?P<args>.*))?$'
100+
.format(aMarker),
101+
re.U)
100102
self.comment = re.compile(aMarker, re.U)
101103
else:
102104
class NoMatch(object):
@@ -129,9 +131,9 @@ def write(self, aLine):
129131
self.writtenLines += 1
130132
ln = self.context['LINE']
131133
if self.writtenLines != ln:
132-
self.out.write('//@line %(line)d "%(file)s"%(le)s'%{'line': ln,
133-
'file': self.context['FILE'],
134-
'le': self.LE})
134+
self.out.write('//@line {line} "{file}"{le}'.format(line=ln,
135+
file=self.context['FILE'],
136+
le=self.LE))
135137
self.writtenLines = ln
136138
filteredLine = self.applyFilters(aLine)
137139
if filteredLine != aLine:

config/buildlist.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
88
Usage: buildlist.py <filename> <entry> [<entry> ...]
99
'''
10+
from __future__ import print_function
1011

1112
import sys
1213
import os
@@ -20,21 +21,22 @@ def addEntriesToListFile(listFile, entries):
2021
try:
2122
if os.path.exists(listFile):
2223
f = open(listFile)
23-
existing = set([x.strip() for x in f.readlines()])
24+
existing = set(x.strip() for x in f.readlines())
2425
f.close()
2526
else:
2627
existing = set()
2728
f = open(listFile, 'a')
2829
for e in entries:
2930
if e not in existing:
30-
f.write("%s\n" % e)
31+
f.write("{0}\n".format(e))
3132
existing.add(e)
3233
f.close()
3334
finally:
3435
lock = None
3536

3637
if __name__ == '__main__':
3738
if len(sys.argv) < 3:
38-
print >>sys.stderr, "Usage: buildlist.py <list file> <entry> [<entry> ...]"
39+
print("Usage: buildlist.py <list file> <entry> [<entry> ...]",
40+
file=sys.stderr)
3941
sys.exit(1)
4042
addEntriesToListFile(sys.argv[1], sys.argv[2:])

config/check_source_count.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# not, an error message is printed, quoting ERROR_LOCATION, which should
1010
# probably be the filename and line number of the erroneous call to
1111
# check_source_count.py.
12-
12+
from __future__ import print_function
1313
import sys
1414
import os
1515
import re
@@ -32,17 +32,26 @@
3232
details[f] = num
3333

3434
if count == expected_count:
35-
print "TEST-PASS | check_source_count.py %s | %d" % (search_string, expected_count)
35+
print("TEST-PASS | check_source_count.py {0} | {1}"
36+
.format(search_string, expected_count))
3637

3738
else:
38-
print "TEST-UNEXPECTED-FAIL | check_source_count.py %s | " % (search_string),
39+
print("TEST-UNEXPECTED-FAIL | check_source_count.py {0} | "
40+
.format(search_string),
41+
end='')
3942
if count < expected_count:
40-
print "There are fewer occurrences of /%s/ than expected. This may mean that you have removed some, but forgotten to account for it %s." % (search_string, error_location)
43+
print("There are fewer occurrences of /{0}/ than expected. "
44+
"This may mean that you have removed some, but forgotten to "
45+
"account for it {1}.".format(search_string, error_location))
4146
else:
42-
print "There are more occurrences of /%s/ than expected. We're trying to prevent an increase in the number of %s's, using %s if possible. If it in unavoidable, you should update the expected count %s." % (search_string, search_string, replacement, error_location)
47+
print("There are more occurrences of /{0}/ than expected. We're trying "
48+
"to prevent an increase in the number of {1}'s, using {2} if "
49+
"possible. If it is unavoidable, you should update the expected "
50+
"count {3}.".format(search_string, search_string, replacement,
51+
error_location))
4352

44-
print "Expected: %d; found: %d" % (expected_count, count)
53+
print("Expected: {0}; found: {1}".format(expected_count, count))
4554
for k in sorted(details):
46-
print "Found %d occurences in %s" % (details[k],k)
55+
print("Found {0} occurences in {1}".format(details[k],k))
4756
sys.exit(-1)
4857

config/expandlibs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
descriptor contains. And for each of these LIBS, also apply the same
2727
rules.
2828
'''
29-
from __future__ import with_statement
3029
import sys, os, errno
3130
import expandlibs_config as conf
3231

@@ -36,7 +35,7 @@ def ensureParentDir(file):
3635
if dir and not os.path.exists(dir):
3736
try:
3837
os.makedirs(dir)
39-
except OSError, error:
38+
except OSError as error:
4039
if error.errno != errno.EEXIST:
4140
raise
4241

@@ -90,7 +89,8 @@ def __init__(self, content=None):
9089

9190
def __str__(self):
9291
'''Serializes the lib descriptor'''
93-
return '\n'.join('%s = %s' % (k, ' '.join(self[k])) for k in self.KEYS if len(self[k]))
92+
return '\n'.join('{0} = {1}'.format(k, ' '.join(self[k]))
93+
for k in self.KEYS if len(self[k]))
9494

9595
class ExpandArgs(list):
9696
def __init__(self, args):
@@ -135,4 +135,4 @@ def _expand_desc(self, arg):
135135
return objs
136136

137137
if __name__ == '__main__':
138-
print " ".join(ExpandArgs(sys.argv[1:]))
138+
print(" ".join(ExpandArgs(sys.argv[1:])))

config/expandlibs_exec.py

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
relevant linker options to change the order in which the linker puts the
2121
symbols appear in the resulting binary. Only works for ELF targets.
2222
'''
23-
from __future__ import with_statement
23+
from __future__ import print_function
2424
import sys
2525
import os
26-
from expandlibs import ExpandArgs, relativize, isObject, ensureParentDir, ExpandLibsDeps
26+
from expandlibs import (ExpandArgs, relativize, isObject, ensureParentDir,
27+
ExpandLibsDeps)
2728
import expandlibs_config as conf
2829
from optparse import OptionParser
2930
import subprocess
@@ -92,10 +93,10 @@ def makelist(self):
9293
if not len(objs): return
9394
fd, tmp = tempfile.mkstemp(suffix=".list",dir=os.curdir)
9495
if conf.EXPAND_LIBS_LIST_STYLE == "linkerscript":
95-
content = ['INPUT("%s")\n' % obj for obj in objs]
96+
content = ['INPUT("{0}")\n'.format(obj) for obj in objs]
9697
ref = tmp
9798
elif conf.EXPAND_LIBS_LIST_STYLE == "list":
98-
content = ["%s\n" % obj for obj in objs]
99+
content = ["{0}\n".format(obj) for obj in objs]
99100
ref = "@" + tmp
100101
else:
101102
os.close(fd)
@@ -139,9 +140,13 @@ def _getFoldedSections(self):
139140
def _getOrderedSections(self, ordered_symbols):
140141
'''Given an ordered list of symbols, returns the corresponding list
141142
of sections following the order.'''
142-
if not conf.EXPAND_LIBS_ORDER_STYLE in ['linkerscript', 'section-ordering-file']:
143-
raise Exception('EXPAND_LIBS_ORDER_STYLE "%s" is not supported' % conf.EXPAND_LIBS_ORDER_STYLE)
144-
finder = SectionFinder([arg for arg in self if isObject(arg) or os.path.splitext(arg)[1] == conf.LIB_SUFFIX])
143+
if conf.EXPAND_LIBS_ORDER_STYLE not in ['linkerscript',
144+
'section-ordering-file']:
145+
raise Exception('EXPAND_LIBS_ORDER_STYLE "{0}" is not supported'
146+
.format(conf.EXPAND_LIBS_ORDER_STYLE))
147+
finder = SectionFinder([arg for arg in self
148+
if isObject(arg) or
149+
os.path.splitext(arg)[1] == conf.LIB_SUFFIX])
145150
folded = self._getFoldedSections()
146151
sections = set()
147152
ordered_sections = []
@@ -182,32 +187,35 @@ def orderSymbols(self, order):
182187
linked_sections = [s for s in linked_sections if s in split_sections]
183188

184189
if conf.EXPAND_LIBS_ORDER_STYLE == 'section-ordering-file':
185-
option = '-Wl,--section-ordering-file,%s'
190+
option = '-Wl,--section-ordering-file,{0}'
186191
content = sections
187192
for linked_section in linked_sections:
188193
content.extend(split_sections[linked_section])
189-
content.append('%s.*' % linked_section)
194+
content.append('{0}.*'.format(linked_section))
190195
content.append(linked_section)
191196

192197
elif conf.EXPAND_LIBS_ORDER_STYLE == 'linkerscript':
193-
option = '-Wl,-T,%s'
198+
option = '-Wl,-T,{0}'
194199
section_insert_before = dict(SECTION_INSERT_BEFORE)
195200
for linked_section in linked_sections:
196-
content.append('SECTIONS {')
197-
content.append(' %s : {' % linked_section)
198-
content.extend(' *(%s)' % s for s in split_sections[linked_section])
199-
content.append(' }')
200-
content.append('}')
201-
content.append('INSERT BEFORE %s' % section_insert_before[linked_section])
201+
content.append('SECTIONS {{')
202+
content.append(' {0} : {{'.format(linked_section))
203+
content.extend(' *({0})'
204+
.format(s for s in split_sections[linked_section]))
205+
content.append(' }}')
206+
content.append('}}')
207+
content.append('INSERT BEFORE {0}'
208+
.format(section_insert_before[linked_section]))
202209
else:
203-
raise Exception('EXPAND_LIBS_ORDER_STYLE "%s" is not supported' % conf.EXPAND_LIBS_ORDER_STYLE)
210+
raise Exception('EXPAND_LIBS_ORDER_STYLE "{0}" is not supported'
211+
.format(conf.EXPAND_LIBS_ORDER_STYLE))
204212

205213
fd, tmp = tempfile.mkstemp(dir=os.curdir)
206214
f = os.fdopen(fd, "w")
207215
f.write('\n'.join(content)+'\n')
208216
f.close()
209217
self.tmp.append(tmp)
210-
self.append(option % tmp)
218+
self.append(option.format(tmp))
211219

212220
class SectionFinder(object):
213221
'''Instances of this class allow to map symbol names to sections in
@@ -216,15 +224,17 @@ class SectionFinder(object):
216224
def __init__(self, objs):
217225
'''Creates an instance, given a list of object files.'''
218226
if not conf.EXPAND_LIBS_ORDER_STYLE in ['linkerscript', 'section-ordering-file']:
219-
raise Exception('EXPAND_LIBS_ORDER_STYLE "%s" is not supported' % conf.EXPAND_LIBS_ORDER_STYLE)
227+
raise Exception('EXPAND_LIBS_ORDER_STYLE "{0}" is not supported'
228+
.format(conf.EXPAND_LIBS_ORDER_STYLE))
220229
self.mapping = {}
221230
for obj in objs:
222231
if not isObject(obj) and os.path.splitext(obj)[1] != conf.LIB_SUFFIX:
223-
raise Exception('%s is not an object nor a static library' % obj)
232+
raise Exception('{0} is not an object nor a static library'
233+
.format(obj))
224234
for symbol, section in SectionFinder._getSymbols(obj):
225235
sym = SectionFinder._normalize(symbol)
226236
if sym in self.mapping:
227-
if not section in self.mapping[sym]:
237+
if section not in self.mapping[sym]:
228238
self.mapping[sym].append(section)
229239
else:
230240
self.mapping[sym] = [section]
@@ -268,11 +278,11 @@ def _getSymbols(obj):
268278
return syms
269279

270280
def print_command(out, args):
271-
print >>out, "Executing: " + " ".join(args)
281+
print("Executing: " + " ".join(args), file=out)
272282
for tmp in [f for f in args.tmp if os.path.isfile(f)]:
273-
print >>out, tmp + ":"
283+
print(tmp + ":", file=out)
274284
with open(tmp) as file:
275-
print >>out, "".join([" " + l for l in file.readlines()])
285+
print("".join([" " + l for l in file.readlines()]), file=out)
276286
out.flush()
277287

278288
def main():
@@ -323,7 +333,10 @@ def main():
323333
return
324334
ensureParentDir(options.depend)
325335
with open(options.depend, 'w') as depfile:
326-
depfile.write("%s : %s\n" % (options.target, ' '.join(dep for dep in deps if os.path.isfile(dep) and dep != options.target)))
336+
depfile.write("{0} : {1}\n"
337+
.format(options.target, ' '.join(dep for dep in deps
338+
if os.path.isfile(dep) and
339+
dep != options.target)))
327340

328341

329342
if __name__ == '__main__':

0 commit comments

Comments
 (0)