summaryrefslogtreecommitdiff
path: root/bin/sconsexamples.py
diff options
context:
space:
mode:
authorLuca Falavigna <dktrkranz@debian.org>2010-06-15 14:28:22 +0000
committerLuca Falavigna <dktrkranz@debian.org>2010-06-15 14:28:22 +0000
commit738149c9bfb9965d013d01ef99f9bb1c2819e7e8 (patch)
tree0397d9bf3b12c903dc73419585df231397ff343c /bin/sconsexamples.py
parente7885e3af440eaef38a9301fd92a105afc8ddebb (diff)
Imported Upstream version 2.0.0upstream/2.0.0
Diffstat (limited to 'bin/sconsexamples.py')
-rw-r--r--bin/sconsexamples.py63
1 files changed, 28 insertions, 35 deletions
diff --git a/bin/sconsexamples.py b/bin/sconsexamples.py
index 0a409bc..6d3b2de 100644
--- a/bin/sconsexamples.py
+++ b/bin/sconsexamples.py
@@ -66,13 +66,11 @@
# output from SCons, and insert it into the text as appropriate.
# Error output gets passed through to your error output so you
# can see if there are any problems executing the command.
-#
import os
import os.path
import re
import sgmllib
-import string
import sys
sys.path.append(os.path.join(os.getcwd(), 'etc'))
@@ -93,7 +91,7 @@ import TestCmd
# Override it with our own regular expression that adds underscore.
sgmllib.entityref = re.compile('&([a-zA-Z][-_.a-zA-Z0-9]*)[^-_a-zA-Z0-9]')
-class DataCollector:
+class DataCollector(object):
"""Generic class for collecting data between a start tag and end
tag. We subclass for various types of tags we care about."""
def __init__(self):
@@ -156,12 +154,11 @@ Prompt = {
# command output.
Stdin = """\
-import string
import SCons.Defaults
platform = '%s'
-class Curry:
+class Curry(object):
def __init__(self, fun, *args, **kwargs):
self.fun = fun
self.pending = args[:]
@@ -174,15 +171,15 @@ class Curry:
else:
kw = kwargs or self.kwargs
- return apply(self.fun, self.pending + args, kw)
+ return self.fun(*self.pending + args, **kw)
def Str(target, source, env, cmd=""):
result = []
for cmd in env.subst_list(cmd, target=target, source=source):
- result.append(string.join(map(str, cmd)))
- return string.join(result, '\\n')
+ result.append(" ".join(map(str, cmd)))
+ return '\\n'.join(result)
-class ToolSurrogate:
+class ToolSurrogate(object):
def __init__(self, tool, variable, func):
self.tool = tool
self.variable = variable
@@ -212,7 +209,7 @@ ToolList = {
('mslink', 'LINKCOM', Cat)]
}
-tools = map(lambda t: apply(ToolSurrogate, t), ToolList[platform])
+tools = map(lambda t: ToolSurrogate(*t), ToolList[platform])
SCons.Defaults.ConstructionEnvironment.update({
'PLATFORM' : platform,
@@ -223,10 +220,7 @@ SConscript('SConstruct')
"""
class MySGML(sgmllib.SGMLParser):
- """A subclass of the standard Python 2.2 sgmllib SGML parser.
-
- Note that this doesn't work with the 1.5.2 sgmllib module, because
- that didn't have the ability to work with ENTITY declarations.
+ """A subclass of the standard Python sgmllib SGML parser.
"""
def __init__(self):
sgmllib.SGMLParser.__init__(self)
@@ -270,7 +264,7 @@ class MySGML(sgmllib.SGMLParser):
sys.stdout.write('&#' + ref + ';')
def start_scons_example(self, attrs):
- t = filter(lambda t: t[0] == 'name', attrs)
+ t = [t for t in attrs if t[0] == 'name']
if t:
name = t[0][1]
try:
@@ -286,7 +280,7 @@ class MySGML(sgmllib.SGMLParser):
def end_scons_example(self):
e = self.e
- files = filter(lambda f: f.printme, e.files)
+ files = [f for f in e.files if f.printme]
if files:
sys.stdout.write('<programlisting>')
for f in files:
@@ -294,7 +288,7 @@ class MySGML(sgmllib.SGMLParser):
i = len(f.data) - 1
while f.data[i] == ' ':
i = i - 1
- output = string.replace(f.data[:i+1], '__ROOT__', '')
+ output = f.data[:i+1].replace('__ROOT__', '')
sys.stdout.write(output)
if e.data and e.data[0] == '\n':
e.data = e.data[1:]
@@ -307,7 +301,7 @@ class MySGML(sgmllib.SGMLParser):
e = self.e
except AttributeError:
self.error("<file> tag outside of <scons_example>")
- t = filter(lambda t: t[0] == 'name', attrs)
+ t = [t for t in attrs if t[0] == 'name']
if not t:
self.error("no <file> name attribute found")
try:
@@ -331,7 +325,7 @@ class MySGML(sgmllib.SGMLParser):
e = self.e
except AttributeError:
self.error("<directory> tag outside of <scons_example>")
- t = filter(lambda t: t[0] == 'name', attrs)
+ t = [t for t in attrs if t[0] == 'name']
if not t:
self.error("no <directory> name attribute found")
try:
@@ -350,7 +344,7 @@ class MySGML(sgmllib.SGMLParser):
self.afunclist = self.afunclist[:-1]
def start_scons_example_file(self, attrs):
- t = filter(lambda t: t[0] == 'example', attrs)
+ t = [t for t in attrs if t[0] == 'example']
if not t:
self.error("no <scons_example_file> example attribute found")
exname = t[0][1]
@@ -358,11 +352,11 @@ class MySGML(sgmllib.SGMLParser):
e = self.examples[exname]
except KeyError:
self.error("unknown example name '%s'" % exname)
- fattrs = filter(lambda t: t[0] == 'name', attrs)
+ fattrs = [t for t in attrs if t[0] == 'name']
if not fattrs:
self.error("no <scons_example_file> name attribute found")
fname = fattrs[0][1]
- f = filter(lambda f, fname=fname: f.name == fname, e.files)
+ f = [f for f in e.files if f.name == fname]
if not f:
self.error("example '%s' does not have a file named '%s'" % (exname, fname))
self.f = f[0]
@@ -377,7 +371,7 @@ class MySGML(sgmllib.SGMLParser):
delattr(self, 'f')
def start_scons_output(self, attrs):
- t = filter(lambda t: t[0] == 'example', attrs)
+ t = [t for t in attrs if t[0] == 'example']
if not t:
self.error("no <scons_output> example attribute found")
exname = t[0][1]
@@ -408,20 +402,19 @@ class MySGML(sgmllib.SGMLParser):
i = 0
while f.data[i] == '\n':
i = i + 1
- lines = string.split(f.data[i:], '\n')
+ lines = f.data[i:].split('\n')
i = 0
while lines[0][i] == ' ':
i = i + 1
- lines = map(lambda l, i=i: l[i:], lines)
- path = string.replace(f.name, '__ROOT__', t.workpath('ROOT'))
+ lines = [l[i:] for l in lines]
+ path = f.name.replace('__ROOT__', t.workpath('ROOT'))
dir, name = os.path.split(f.name)
if dir:
dir = t.workpath('WORK', dir)
if not os.path.exists(dir):
os.makedirs(dir)
- content = string.join(lines, '\n')
- content = string.replace(content,
- '__ROOT__',
+ content = '\n'.join(lines)
+ content = content.replace('__ROOT__',
t.workpath('ROOT'))
t.write(t.workpath('WORK', f.name), content)
i = len(o.prefix)
@@ -431,19 +424,19 @@ class MySGML(sgmllib.SGMLParser):
p = o.prefix[i:]
for c in o.commandlist:
sys.stdout.write(p + Prompt[o.os])
- d = string.replace(c.data, '__ROOT__', '')
+ d = c.data.replace('__ROOT__', '')
sys.stdout.write('<userinput>' + d + '</userinput>\n')
- e = string.replace(c.data, '__ROOT__', t.workpath('ROOT'))
- args = string.split(e)[1:]
+ e = c.data.replace('__ROOT__', t.workpath('ROOT'))
+ args = e.split()[1:]
os.environ['SCONS_LIB_DIR'] = scons_lib_dir
t.run(interpreter = sys.executable,
program = scons_py,
- arguments = '-f - ' + string.join(args),
+ arguments = '-f - ' + ' '.join(args),
chdir = t.workpath('WORK'),
stdin = Stdin % o.os)
- out = string.replace(t.stdout(), t.workpath('ROOT'), '')
+ out = t.stdout().replace(t.workpath('ROOT'), '')
if out:
- lines = string.split(out, '\n')
+ lines = out.split('\n')
if lines:
while lines[-1] == '':
lines = lines[:-1]