#!/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:]:
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 = """\
import sys
import time
import types
+import string
Usage = """\
Usage: bench.py OPTIONS file.py
sys.exit(1)
-execfile(args[0])
+exec(string.replace(open(args[0]).read(), '\r', '\n'))
try:
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):
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]
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):
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):
"""
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)
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,
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)
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)
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
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)
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
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'], """\
""")
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']:
""")
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']:
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
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'], """\