summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Noel <GregNoel@tigris.org>2009-03-02 03:19:29 +0000
committerGreg Noel <GregNoel@tigris.org>2009-03-02 03:19:29 +0000
commit1573ab84d1cece0367dfd7e804aee39d40f9f849 (patch)
treecbd8a625268ec290a2d2e03bbad4a94de8678919
parente42511a0e12bbd8d74b6dc1136898fea24e791df (diff)
downloadscons-1573ab84d1cece0367dfd7e804aee39d40f9f849.tar.gz
replace execfile() by equivalent exec statement
-rw-r--r--QMTest/TestSCons_time.py3
-rw-r--r--bench/bench.py3
-rw-r--r--src/engine/SCons/Variables/VariablesTests.py2
-rw-r--r--src/engine/SCons/Variables/__init__.py2
-rw-r--r--src/engine/SCons/compat/_scons_optparse.py2
-rw-r--r--src/script/scons-time.py32
-rw-r--r--test/Deprecated/Options/Options.py2
-rw-r--r--test/Deprecated/Options/chdir.py3
-rw-r--r--test/SConscript/SConscriptChdir.py15
-rw-r--r--test/SConscriptChdir.py15
-rw-r--r--test/Variables/Variables.py2
-rw-r--r--test/Variables/chdir.py3
12 files changed, 54 insertions, 30 deletions
diff --git a/QMTest/TestSCons_time.py b/QMTest/TestSCons_time.py
index 869e0cb4..07473934 100644
--- a/QMTest/TestSCons_time.py
+++ b/QMTest/TestSCons_time.py
@@ -46,6 +46,7 @@ scons_py = """\
#!/usr/bin/env python
import os
import sys
+import string
def write_args(fp, args):
fp.write(args[0] + '\\n')
for arg in args[1:]:
@@ -58,7 +59,7 @@ for arg in sys.argv[1:]:
write_args(profile, sys.argv)
break
sys.stdout.write('SCONS_LIB_DIR = ' + os.environ['SCONS_LIB_DIR'] + '\\n')
-execfile('SConstruct')
+exec(string.replace(open('SConstruct').read(), '\\r', '\\n'))
"""
aegis_py = """\
diff --git a/bench/bench.py b/bench/bench.py
index 07c0384c..d90d75ad 100644
--- a/bench/bench.py
+++ b/bench/bench.py
@@ -28,6 +28,7 @@ import getopt
import sys
import time
import types
+import string
Usage = """\
Usage: bench.py OPTIONS file.py
@@ -87,7 +88,7 @@ if len(args) != 1:
sys.exit(1)
-execfile(args[0])
+exec(string.replace(open(args[0]).read(), '\r', '\n'))
try:
diff --git a/src/engine/SCons/Variables/VariablesTests.py b/src/engine/SCons/Variables/VariablesTests.py
index 153b1aa6..f1caff74 100644
--- a/src/engine/SCons/Variables/VariablesTests.py
+++ b/src/engine/SCons/Variables/VariablesTests.py
@@ -54,7 +54,7 @@ def check(key, value, env):
def checkSave(file, expected):
gdict = {}
ldict = {}
- execfile(file, gdict, ldict)
+ exec string.replace(open(file).read(), '\r', '\n') in gdict, ldict
assert expected == ldict, "%s\n...not equal to...\n%s" % (expected, ldict)
class VariablesTestCase(unittest.TestCase):
diff --git a/src/engine/SCons/Variables/__init__.py b/src/engine/SCons/Variables/__init__.py
index e7b43160..3cc6694a 100644
--- a/src/engine/SCons/Variables/__init__.py
+++ b/src/engine/SCons/Variables/__init__.py
@@ -166,7 +166,7 @@ class Variables:
sys.path.insert(0, dir)
try:
values['__name__'] = filename
- execfile(filename, {}, values)
+ exec string.replace(open(filename).read(), '\r', '\n') in {}, values
finally:
if dir:
del sys.path[0]
diff --git a/src/engine/SCons/compat/_scons_optparse.py b/src/engine/SCons/compat/_scons_optparse.py
index 386dfea6..23f2ad31 100644
--- a/src/engine/SCons/compat/_scons_optparse.py
+++ b/src/engine/SCons/compat/_scons_optparse.py
@@ -920,7 +920,7 @@ class Values:
def read_file(self, filename, mode="careful"):
vars = {}
- execfile(filename, vars)
+ exec string.replace(open(filename).read(), '\r', '\n') in vars
self._update(vars, mode)
def ensure_value(self, attr, value):
diff --git a/src/script/scons-time.py b/src/script/scons-time.py
index 134124f6..019df312 100644
--- a/src/script/scons-time.py
+++ b/src/script/scons-time.py
@@ -79,6 +79,17 @@ def make_temp_file(**kw):
tempfile.template = save_template
return result
+def HACK_for_exec(cmd, *args):
+ '''
+ For some reason, Python won't allow an exec() within a function
+ that also declares an internal function (including lambda functions).
+ This function is a hack that calls exec() in a function with no
+ internal functions.
+ '''
+ if not args: exec(cmd)
+ elif len(args) == 1: exec cmd in args[0]
+ else: exec cmd in args[0], args[1]
+
class Plotter:
def increment_size(self, largest):
"""
@@ -830,7 +841,7 @@ class SConsTimer:
self.title = a
if self.config_file:
- execfile(self.config_file, self.__dict__)
+ exec string.replace(open(self.config_file).read(), '\r', '\n') in self.__dict__
if self.chdir:
os.chdir(self.chdir)
@@ -859,19 +870,18 @@ class SConsTimer:
if format == 'ascii':
- def print_function_timing(file, func):
+ for file in args:
try:
- f, line, func, time = self.get_function_profile(file, func)
+ f, line, func, time = \
+ self.get_function_profile(file, function_name)
except ValueError, e:
- sys.stderr.write("%s: func: %s: %s\n" % (self.name, file, e))
+ sys.stderr.write("%s: func: %s: %s\n" %
+ (self.name, file, e))
else:
if f.startswith(cwd_):
f = f[len(cwd_):]
print "%.3f %s:%d(%s)" % (time, f, line, func)
- for file in args:
- print_function_timing(file, function_name)
-
elif format == 'gnuplot':
results = self.collect_results(args, self.get_function_time,
@@ -950,7 +960,7 @@ class SConsTimer:
self.title = a
if self.config_file:
- execfile(self.config_file, self.__dict__)
+ HACK_for_exec(string.replace(open(self.config_file).read(), '\r', '\n'), self.__dict__)
if self.chdir:
os.chdir(self.chdir)
@@ -1070,7 +1080,7 @@ class SConsTimer:
object_name = args.pop(0)
if self.config_file:
- execfile(self.config_file, self.__dict__)
+ HACK_for_exec(string.replace(open(self.config_file).read(), '\r', '\n'), self.__dict__)
if self.chdir:
os.chdir(self.chdir)
@@ -1208,7 +1218,7 @@ class SConsTimer:
sys.exit(1)
if self.config_file:
- execfile(self.config_file, self.__dict__)
+ exec string.replace(open(self.config_file).read(), '\r', '\n') in self.__dict__
if args:
self.archive_list = args
@@ -1448,7 +1458,7 @@ class SConsTimer:
which = a
if self.config_file:
- execfile(self.config_file, self.__dict__)
+ HACK_for_exec(string.replace(open(self.config_file).read(), '\r', '\n'), self.__dict__)
if self.chdir:
os.chdir(self.chdir)
diff --git a/test/Deprecated/Options/Options.py b/test/Deprecated/Options/Options.py
index d04ad443..f4114789 100644
--- a/test/Deprecated/Options/Options.py
+++ b/test/Deprecated/Options/Options.py
@@ -241,7 +241,7 @@ opts.Save('options.saved', env)
def checkSave(file, expected):
gdict = {}
ldict = {}
- execfile(file, gdict, ldict)
+ exec string.replace(open(file).read(), '\r', '\n') in gdict, ldict
assert expected == ldict, "%s\n...not equal to...\n%s" % (expected, ldict)
# First test with no command line options
diff --git a/test/Deprecated/Options/chdir.py b/test/Deprecated/Options/chdir.py
index 0db8223a..547fe534 100644
--- a/test/Deprecated/Options/chdir.py
+++ b/test/Deprecated/Options/chdir.py
@@ -52,7 +52,8 @@ print "VARIABLE =", repr(env['VARIABLE'])
test.write(['bin', 'opts.cfg'], """\
import os
os.chdir(os.path.split(__name__)[0])
-execfile('opts2.cfg')
+import string
+exec(string.replace(open('opts2.cfg').read(), '\\r', '\\n'))
""")
test.write(['bin', 'opts2.cfg'], """\
diff --git a/test/SConscript/SConscriptChdir.py b/test/SConscript/SConscriptChdir.py
index 99810e3c..8169f08f 100644
--- a/test/SConscript/SConscriptChdir.py
+++ b/test/SConscript/SConscriptChdir.py
@@ -44,27 +44,32 @@ SConscript('dir5/SConscript')
""")
test.write(['dir1', 'SConscript'], """
-execfile("create_test.py")
+import string
+exec(string.replace(open("create_test.py").read(), '\\r', '\\n'))
""")
test.write(['dir2', 'SConscript'], """
-execfile("create_test.py")
+import string
+exec(string.replace(open("create_test.py").read(), '\\r', '\\n'))
""")
test.write(['dir3', 'SConscript'], """
import os.path
name = os.path.join('dir3', 'create_test.py')
-execfile(name)
+import string
+exec(string.replace(open(name).read(), '\\r', '\\n'))
""")
test.write(['dir4', 'SConscript'], """
-execfile("create_test.py")
+import string
+exec(string.replace(open("create_test.py").read(), '\\r', '\\n'))
""")
test.write(['dir5', 'SConscript'], """
import os.path
name = os.path.join('dir5', 'create_test.py')
-execfile(name)
+import string
+exec(string.replace(open(name).read(), '\\r', '\\n'))
""")
for dir in ['dir1', 'dir2', 'dir3','dir4', 'dir5']:
diff --git a/test/SConscriptChdir.py b/test/SConscriptChdir.py
index 99810e3c..8169f08f 100644
--- a/test/SConscriptChdir.py
+++ b/test/SConscriptChdir.py
@@ -44,27 +44,32 @@ SConscript('dir5/SConscript')
""")
test.write(['dir1', 'SConscript'], """
-execfile("create_test.py")
+import string
+exec(string.replace(open("create_test.py").read(), '\\r', '\\n'))
""")
test.write(['dir2', 'SConscript'], """
-execfile("create_test.py")
+import string
+exec(string.replace(open("create_test.py").read(), '\\r', '\\n'))
""")
test.write(['dir3', 'SConscript'], """
import os.path
name = os.path.join('dir3', 'create_test.py')
-execfile(name)
+import string
+exec(string.replace(open(name).read(), '\\r', '\\n'))
""")
test.write(['dir4', 'SConscript'], """
-execfile("create_test.py")
+import string
+exec(string.replace(open("create_test.py").read(), '\\r', '\\n'))
""")
test.write(['dir5', 'SConscript'], """
import os.path
name = os.path.join('dir5', 'create_test.py')
-execfile(name)
+import string
+exec(string.replace(open(name).read(), '\\r', '\\n'))
""")
for dir in ['dir1', 'dir2', 'dir3','dir4', 'dir5']:
diff --git a/test/Variables/Variables.py b/test/Variables/Variables.py
index eaac22dd..0e6a152c 100644
--- a/test/Variables/Variables.py
+++ b/test/Variables/Variables.py
@@ -235,7 +235,7 @@ opts.Save('variables.saved', env)
def checkSave(file, expected):
gdict = {}
ldict = {}
- execfile(file, gdict, ldict)
+ exec string.replace(open(file).read(), '\r', '\n') in gdict, ldict
assert expected == ldict, "%s\n...not equal to...\n%s" % (expected, ldict)
# First test with no command line variables
diff --git a/test/Variables/chdir.py b/test/Variables/chdir.py
index 711957c3..39eccb3e 100644
--- a/test/Variables/chdir.py
+++ b/test/Variables/chdir.py
@@ -52,7 +52,8 @@ print "VARIABLE =", repr(env['VARIABLE'])
test.write(['bin', 'opts.cfg'], """\
import os
os.chdir(os.path.split(__name__)[0])
-execfile('opts2.cfg')
+import string
+exec(string.replace(open('opts2.cfg').read(), '\\r', '\\n'))
""")
test.write(['bin', 'opts2.cfg'], """\