From 9d5e76a42341596583924470feebcc637fcb8ac8 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Fri, 8 Nov 2024 08:13:26 -0700 Subject: [PATCH] Modernize stat usage Since Python 2.2, the object returned by an os.stat() call presents attributes matching the 10-tuple of stat values. Use these instead of indexing into the tuple. As usual for non-removed tests, minor tweaks made if needed - copyright header and DefautlEnvironment() call for performance. Signed-off-by: Mats Wichmann --- CHANGES.txt | 2 + RELEASE.txt | 4 + SCons/CacheDir.py | 2 +- SCons/Node/FS.py | 2 +- SCons/Node/FSTests.py | 4 +- SCons/Tool/install.py | 4 +- site_scons/Utilities.py | 2 +- test/Actions/append.py | 2 +- test/Actions/pre-post.py | 4 +- test/Chmod.py | 77 ++++++++++--------- test/Decider/MD5-timestamp-Repository.py | 2 +- test/Decider/MD5-timestamp.py | 2 +- test/Decider/timestamp.py | 4 +- test/Removed/BuildDir/Old/BuildDir.py | 6 +- .../BuildDir/Old/SConscript-build_dir.py | 22 +++--- test/VariantDir/SConscript-variant_dir.py | 13 ++-- test/VariantDir/VariantDir.py | 10 +-- test/VariantDir/errors.py | 13 ++-- test/ZIP/ZIP.py | 6 +- test/option/option--duplicate.py | 4 +- testing/framework/TestCmd.py | 14 ++-- testing/framework/TestCmdTests.py | 26 +++---- testing/framework/TestCommon.py | 2 +- testing/framework/TestCommonTests.py | 12 +-- 24 files changed, 123 insertions(+), 116 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index f074da86e7..b86d8f5875 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -181,6 +181,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER Only object-like macros are replaced (not function-like), and only on a whole-word basis; recursion is limited to five levels and does not error out if that limit is reached (issue #4523). + - Minor modernization: make use of stat object's st_mode, st_mtime + and other attributes rather than indexing into stat return. RELEASE 4.8.1 - Tue, 03 Sep 2024 17:22:20 -0700 diff --git a/RELEASE.txt b/RELEASE.txt index b35ece2657..1251be6cc0 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -164,6 +164,10 @@ FIXES only on a whole-word basis; recursion is limited to five levels and does not error out if that limit is reached (issue #4523). +- Minor modernization: make use of stat object's st_mode, st_mtime + and other attributes rather than indexing into stat return. + + IMPROVEMENTS ------------ diff --git a/SCons/CacheDir.py b/SCons/CacheDir.py index 7f8deb55e1..25e3f666f4 100644 --- a/SCons/CacheDir.py +++ b/SCons/CacheDir.py @@ -71,7 +71,7 @@ def CacheRetrieveFunc(target, source, env) -> int: except OSError: pass st = fs.stat(cachefile) - fs.chmod(t.get_internal_path(), stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE) + fs.chmod(t.get_internal_path(), stat.S_IMODE(st.st_mode) | stat.S_IWRITE) return 0 def CacheRetrieveString(target, source, env) -> str: diff --git a/SCons/Node/FS.py b/SCons/Node/FS.py index bdecffcfbd..ec0a69a7b4 100644 --- a/SCons/Node/FS.py +++ b/SCons/Node/FS.py @@ -762,7 +762,7 @@ def getmtime(self): st = self.stat() if st: - return st[stat.ST_MTIME] + return st.st_mtime else: return None diff --git a/SCons/Node/FSTests.py b/SCons/Node/FSTests.py index 9ae8c03e10..ae98bc5a59 100644 --- a/SCons/Node/FSTests.py +++ b/SCons/Node/FSTests.py @@ -774,7 +774,7 @@ def test_update(self) -> None: ni.update(fff) - mtime = st[stat.ST_MTIME] + mtime = st.st_mtime assert ni.timestamp == mtime, (ni.timestamp, mtime) size = st.st_size assert ni.size == size, (ni.size, size) @@ -786,7 +786,7 @@ def test_update(self) -> None: st = os.stat('fff') - mtime = st[stat.ST_MTIME] + mtime = st.st_mtime assert ni.timestamp != mtime, (ni.timestamp, mtime) size = st.st_size assert ni.size != size, (ni.size, size) diff --git a/SCons/Tool/install.py b/SCons/Tool/install.py index d553e31afe..fc20586ff0 100644 --- a/SCons/Tool/install.py +++ b/SCons/Tool/install.py @@ -176,7 +176,7 @@ def copyFunc(dest, source, env) -> int: else: copy2(source, dest) st = os.stat(source) - os.chmod(dest, stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE) + os.chmod(dest, stat.S_IMODE(st.st_mode) | stat.S_IWRITE) return 0 @@ -204,7 +204,7 @@ def copyFuncVersionedLib(dest, source, env) -> int: pass copy2(source, dest) st = os.stat(source) - os.chmod(dest, stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE) + os.chmod(dest, stat.S_IMODE(st.st_mode) | stat.S_IWRITE) installShlibLinks(dest, source, env) return 0 diff --git a/site_scons/Utilities.py b/site_scons/Utilities.py index 7ef45a33c6..620595d7ec 100644 --- a/site_scons/Utilities.py +++ b/site_scons/Utilities.py @@ -31,7 +31,7 @@ def whereis(filename): st = os.stat(f_ext) except: continue - if stat.S_IMODE(st[stat.ST_MODE]) & 0o111: + if stat.S_IMODE(st.st_mode) & stat.S_IXUSR: return f_ext return None diff --git a/test/Actions/append.py b/test/Actions/append.py index 01a9f23219..8205e1beff 100644 --- a/test/Actions/append.py +++ b/test/Actions/append.py @@ -63,7 +63,7 @@ def after(env, target, source): test.run(arguments='.') test.must_match('before.txt', 'Bar\n') -os.chmod(after_exe, os.stat(after_exe)[stat.ST_MODE] | stat.S_IXUSR) +os.chmod(after_exe, os.stat(after_exe).st_mode | stat.S_IXUSR) test.run(program=after_exe, stdout="Foo\n") test.pass_test() diff --git a/test/Actions/pre-post.py b/test/Actions/pre-post.py index ac6a96fd12..0d9f36fce9 100644 --- a/test/Actions/pre-post.py +++ b/test/Actions/pre-post.py @@ -50,7 +50,7 @@ def before(env, target, source): a=str(target[0]) with open(a, "wb") as f: f.write(b"Foo\\n") - os.chmod(a, os.stat(a)[stat.ST_MODE] | stat.S_IXUSR) + os.chmod(a, os.stat(a).st_mode | stat.S_IXUSR) with open("before.txt", "ab") as f: f.write((os.path.splitext(str(target[0]))[0] + "\\n").encode()) @@ -59,7 +59,7 @@ def after(env, target, source): a = "after_" + t with open(t, "rb") as fin, open(a, "wb") as fout: fout.write(fin.read()) - os.chmod(a, os.stat(a)[stat.ST_MODE] | stat.S_IXUSR) + os.chmod(a, os.stat(a).st_mode | stat.S_IXUSR) foo = env.Program(source='foo.c', target='foo') AddPreAction(foo, before) diff --git a/test/Chmod.py b/test/Chmod.py index 7af95b4130..87e7b15acb 100644 --- a/test/Chmod.py +++ b/test/Chmod.py @@ -51,6 +51,7 @@ def cat(env, source, target): f.write(infp.read()) Cat = Action(cat) +DefaultEnvironment(tools=[]) # test speedup env = Environment() env.Command( 'bar.out', @@ -154,92 +155,92 @@ def cat(env, source, target): """) test.run(options = '-n', arguments = '.', stdout = expect) -s = stat.S_IMODE(os.stat(test.workpath('f1'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f1')).st_mode) test.fail_test(s != 0o444) -s = stat.S_IMODE(os.stat(test.workpath('f1-File'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f1-File')).st_mode) test.fail_test(s != 0o444) -s = stat.S_IMODE(os.stat(test.workpath('d2'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('d2')).st_mode) test.fail_test(s != 0o555) -s = stat.S_IMODE(os.stat(test.workpath('d2-Dir'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('d2-Dir')).st_mode) test.fail_test(s != 0o555) test.must_not_exist('bar.out') -s = stat.S_IMODE(os.stat(test.workpath('f3'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f3')).st_mode) test.fail_test(s != 0o444) -s = stat.S_IMODE(os.stat(test.workpath('d4'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('d4')).st_mode) test.fail_test(s != 0o555) -s = stat.S_IMODE(os.stat(test.workpath('f5'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f5')).st_mode) test.fail_test(s != 0o444) test.must_not_exist('f6.out') test.must_not_exist('f7.out') -s = stat.S_IMODE(os.stat(test.workpath('Chmod-f7.in'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('Chmod-f7.in')).st_mode) test.fail_test(s != 0o444) -s = stat.S_IMODE(os.stat(test.workpath('f7.out-Chmod'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f7.out-Chmod')).st_mode) test.fail_test(s != 0o444) test.must_not_exist('f8.out') -s = stat.S_IMODE(os.stat(test.workpath('f9'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f9')).st_mode) test.fail_test(s != 0o444) -s = stat.S_IMODE(os.stat(test.workpath('f10'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f10')).st_mode) test.fail_test(s != 0o444) -s = stat.S_IMODE(os.stat(test.workpath('d11'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('d11')).st_mode) test.fail_test(s != 0o555) -s = stat.S_IMODE(os.stat(test.workpath('d12'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('d12')).st_mode) test.fail_test(s != 0o555) -s = stat.S_IMODE(os.stat(test.workpath('f13'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f13')).st_mode) test.fail_test(s != 0o444) -s = stat.S_IMODE(os.stat(test.workpath('f14'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f14')).st_mode) test.fail_test(s != 0o444) -s = stat.S_IMODE(os.stat(test.workpath('f15'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f15')).st_mode) test.fail_test(s != 0o444) -s = stat.S_IMODE(os.stat(test.workpath('d16'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('d16')).st_mode) test.fail_test(s != 0o555) -s = stat.S_IMODE(os.stat(test.workpath('d17'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('d17')).st_mode) test.fail_test(s != 0o555) -s = stat.S_IMODE(os.stat(test.workpath('d18'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('d18')).st_mode) test.fail_test(s != 0o555) test.run() -s = stat.S_IMODE(os.stat(test.workpath('f1'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f1')).st_mode) test.fail_test(s != 0o666) -s = stat.S_IMODE(os.stat(test.workpath('f1-File'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f1-File')).st_mode) test.fail_test(s != 0o666) -s = stat.S_IMODE(os.stat(test.workpath('d2'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('d2')).st_mode) test.fail_test(s != 0o777) -s = stat.S_IMODE(os.stat(test.workpath('d2-Dir'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('d2-Dir')).st_mode) test.fail_test(s != 0o777) test.must_match('bar.out', "bar.in\n") -s = stat.S_IMODE(os.stat(test.workpath('f3'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f3')).st_mode) test.fail_test(s != 0o666) -s = stat.S_IMODE(os.stat(test.workpath('d4'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('d4')).st_mode) test.fail_test(s != 0o777) -s = stat.S_IMODE(os.stat(test.workpath('f5'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f5')).st_mode) test.fail_test(s != 0o666) test.must_match('f6.out', "f6.in\n") test.must_match('f7.out', "f7.in\n") -s = stat.S_IMODE(os.stat(test.workpath('Chmod-f7.in'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('Chmod-f7.in')).st_mode) test.fail_test(s != 0o666) -s = stat.S_IMODE(os.stat(test.workpath('f7.out-Chmod'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f7.out-Chmod')).st_mode) test.fail_test(s != 0o666) test.must_match('f8.out', "f8.in\n") -s = stat.S_IMODE(os.stat(test.workpath('f9'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f9')).st_mode) test.fail_test(s != 0o666) -s = stat.S_IMODE(os.stat(test.workpath('f10'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f10')).st_mode) test.fail_test(s != 0o666) -s = stat.S_IMODE(os.stat(test.workpath('d11'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('d11')).st_mode) test.fail_test(s != 0o777) -s = stat.S_IMODE(os.stat(test.workpath('d12'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('d12')).st_mode) test.fail_test(s != 0o777) -s = stat.S_IMODE(os.stat(test.workpath('f13'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f13')).st_mode) test.fail_test(s != 0o444) -s = stat.S_IMODE(os.stat(test.workpath('f14'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f14')).st_mode) test.fail_test(s != 0o666) -s = stat.S_IMODE(os.stat(test.workpath('f15'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('f15')).st_mode) test.fail_test(s != 0o666) -s = stat.S_IMODE(os.stat(test.workpath('d16'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('d16')).st_mode) test.fail_test(s != 0o777) -s = stat.S_IMODE(os.stat(test.workpath('d17'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('d17')).st_mode) test.fail_test(s != 0o777) -s = stat.S_IMODE(os.stat(test.workpath('d18'))[stat.ST_MODE]) +s = stat.S_IMODE(os.stat(test.workpath('d18')).st_mode) test.fail_test(s != 0o777) test.pass_test() diff --git a/test/Decider/MD5-timestamp-Repository.py b/test/Decider/MD5-timestamp-Repository.py index 201bdfe496..35e24f4979 100644 --- a/test/Decider/MD5-timestamp-Repository.py +++ b/test/Decider/MD5-timestamp-Repository.py @@ -58,7 +58,7 @@ test.sleep() # delay for timestamps test.write(['Repository','content1.in'], "content1.in 2\n") test.touch(['Repository','content2.in']) -time_content = os.stat(os.path.join(repository,'content3.in'))[stat.ST_MTIME] +time_content = os.stat(os.path.join(repository,'content3.in')).st_mtime test.write(['Repository','content3.in'], "content3.in 2\n") test.touch(['Repository','content3.in'], time_content) diff --git a/test/Decider/MD5-timestamp.py b/test/Decider/MD5-timestamp.py index 3815639672..b8988402b0 100644 --- a/test/Decider/MD5-timestamp.py +++ b/test/Decider/MD5-timestamp.py @@ -54,7 +54,7 @@ test.write('content1.in', "content1.in 2\n") test.touch('content2.in') -time_content = os.stat('content3.in')[stat.ST_MTIME] +time_content = os.stat('content3.in').st_mtime test.write('content3.in', "content3.in 2\n") test.touch('content3.in', time_content) diff --git a/test/Decider/timestamp.py b/test/Decider/timestamp.py index d713a621dd..1fcb9e70d2 100644 --- a/test/Decider/timestamp.py +++ b/test/Decider/timestamp.py @@ -55,8 +55,8 @@ test.run(arguments = '.') test.up_to_date(arguments = '.') -time_match = os.stat('match2.out')[stat.ST_MTIME] -time_newer = os.stat('newer2.out')[stat.ST_MTIME] +time_match = os.stat('match2.out').st_mtime +time_newer = os.stat('newer2.out').st_mtime # Now make all the source files newer than (different timestamps from) # the last time the targets were built, and touch the target files diff --git a/test/Removed/BuildDir/Old/BuildDir.py b/test/Removed/BuildDir/Old/BuildDir.py index 1a1ba02f6e..7463f21eec 100644 --- a/test/Removed/BuildDir/Old/BuildDir.py +++ b/test/Removed/BuildDir/Old/BuildDir.py @@ -224,8 +224,8 @@ def filter_tempnam(err): def equal_stats(x,y): x = os.stat(x) y = os.stat(y) - return (stat.S_IMODE(x[stat.ST_MODE]) == stat.S_IMODE(y[stat.ST_MODE]) and - x[stat.ST_MTIME] == y[stat.ST_MTIME]) + return (stat.S_IMODE(x.st_mode) == stat.S_IMODE(y.st_mode) and + x.st_mtime == y.st_mtime) # Make sure we did duplicate the source files in build/var2, # and that their stats are the same: @@ -233,7 +233,7 @@ def equal_stats(x,y): test.must_exist(['work1', 'build', 'var2', 'f2.in']) test.fail_test(not equal_stats(test.workpath('work1', 'build', 'var2', 'f1.c'), test.workpath('work1', 'src', 'f1.c'))) test.fail_test(not equal_stats(test.workpath('work1', 'build', 'var2', 'f2.in'), test.workpath('work1', 'src', 'f2.in'))) - + # Make sure we didn't duplicate the source files in build/var3. test.must_not_exist(['work1', 'build', 'var3', 'f1.c']) test.must_not_exist(['work1', 'build', 'var3', 'f2.in']) diff --git a/test/Removed/BuildDir/Old/SConscript-build_dir.py b/test/Removed/BuildDir/Old/SConscript-build_dir.py index 0d1ba6abde..ed520370ee 100644 --- a/test/Removed/BuildDir/Old/SConscript-build_dir.py +++ b/test/Removed/BuildDir/Old/SConscript-build_dir.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Verify that specifying a build_dir argument to SConscript still works. @@ -108,7 +107,7 @@ def cat(env, source, target): # VariantDir('build/var9', '.') # SConscript('build/var9/src/SConscript') SConscript('src/SConscript', build_dir='build/var9', src_dir='.') -""") +""") test.subdir(['test', 'src'], ['test', 'alt']) @@ -152,8 +151,8 @@ def cat(env, source, target): def equal_stats(x,y): x = os.stat(x) y = os.stat(y) - return (stat.S_IMODE(x[stat.ST_MODE]) == stat.S_IMODE(y[stat.ST_MODE]) and - x[stat.ST_MTIME] == y[stat.ST_MTIME]) + return (stat.S_IMODE(x.st_mode) == stat.S_IMODE(y.st_mode) and + x.st_mtime == y.st_mtime) # Make sure we did duplicate the source files in build/var1, # and that their stats are the same: @@ -168,12 +167,12 @@ def equal_stats(x,y): test.must_exist(test.workpath('test', 'build', 'var2', file)) test.fail_test(not equal_stats(test.workpath('test', 'build', 'var2', file), test.workpath('test', 'src', file))) - + # Make sure we didn't duplicate the source files in build/var3. test.must_not_exist(test.workpath('test', 'build', 'var3', 'aaa.in')) test.must_not_exist(test.workpath('test', 'build', 'var3', 'bbb.in')) test.must_not_exist(test.workpath('test', 'build', 'var3', 'ccc.in')) - + #XXX We can't support var4 and var5 yet, because our VariantDir linkage #XXX is to an entire source directory. We haven't yet generalized our #XXX infrastructure to be able to take the SConscript file from one source @@ -200,12 +199,12 @@ def equal_stats(x,y): test.must_exist(test.workpath('build', 'var6', file)) test.fail_test(not equal_stats(test.workpath('build', 'var6', file), test.workpath('test', 'src', file))) - + # Make sure we didn't duplicate the source files in build/var7. test.must_not_exist(test.workpath('build', 'var7', 'aaa.in')) test.must_not_exist(test.workpath('build', 'var7', 'bbb.in')) test.must_not_exist(test.workpath('build', 'var7', 'ccc.in')) - + # Make sure we didn't duplicate the source files in build/var8. test.must_not_exist(test.workpath('build', 'var8', 'aaa.in')) test.must_not_exist(test.workpath('build', 'var8', 'bbb.in')) @@ -219,6 +218,7 @@ def equal_stats(x,y): """) test.write(['test2', 'SConscript'], """\ +DefaultEnvironment(tools=[]) # test speedup env = Environment() foo_obj = env.Object('foo.c') env.Program('foo', [foo_obj, 'bar.c']) diff --git a/test/VariantDir/SConscript-variant_dir.py b/test/VariantDir/SConscript-variant_dir.py index 1e28c47a98..43c3638a1f 100644 --- a/test/VariantDir/SConscript-variant_dir.py +++ b/test/VariantDir/SConscript-variant_dir.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Verify that specifying a variant_dir argument to SConscript works properly. @@ -64,6 +63,7 @@ def cat(env, source, target): with open(str(src), "rb") as ifp: ofp.write(ifp.read()) +DefaultEnvironment(tools=[]) # test speedup env = Environment(BUILDERS={'Cat':Builder(action=cat)}, BUILD='build') @@ -138,8 +138,8 @@ def cat(env, source, target): def equal_stats(x,y): x = os.stat(x) y = os.stat(y) - return (stat.S_IMODE(x[stat.ST_MODE]) == stat.S_IMODE(y[stat.ST_MODE]) and - x[stat.ST_MTIME] == y[stat.ST_MTIME]) + return (stat.S_IMODE(x.st_mode) == stat.S_IMODE(y.st_mode) and + x.st_mtime == y.st_mtime) # Make sure we did duplicate the source files in build/var1, # and that their stats are the same: @@ -205,6 +205,7 @@ def equal_stats(x,y): """) test.write(['test2', 'SConscript'], """\ +DefaultEnvironment(tools=[]) # test speedup env = Environment() foo_obj = env.Object('foo.c') env.Program('foo', [foo_obj, 'bar.c']) diff --git a/test/VariantDir/VariantDir.py b/test/VariantDir/VariantDir.py index bd329d8b1b..a173b86531 100644 --- a/test/VariantDir/VariantDir.py +++ b/test/VariantDir/VariantDir.py @@ -119,7 +119,7 @@ def buildIt(target, source, env): if fortran and env.Detect(fortran): if sys.platform =='win32': - env_prog = Environment(tools=['mingw'], + env_prog = Environment(tools=['mingw'], # BUILD = env['BUILD'], SRC = ENV['src'], CPPPATH=env['CPPPATH'], FORTRANPATH=env['FORTRANPATH'] ) else: @@ -276,8 +276,8 @@ def blank_output(err): def equal_stats(x,y): x = os.stat(x) y = os.stat(y) - return (stat.S_IMODE(x[stat.ST_MODE]) == stat.S_IMODE(y[stat.ST_MODE]) and - x[stat.ST_MTIME] == y[stat.ST_MTIME]) + return (stat.S_IMODE(x.st_mode) == stat.S_IMODE(y.st_mode) and + x.st_mtime == y.st_mtime) # Make sure we did duplicate the source files in build/var2, # and that their stats are the same: @@ -285,7 +285,7 @@ def equal_stats(x,y): test.must_exist(['work1', 'build', 'var2', 'f2.in']) test.fail_test(not equal_stats(test.workpath('work1', 'build', 'var2', 'f1.c'), test.workpath('work1', 'src', 'f1.c'))) test.fail_test(not equal_stats(test.workpath('work1', 'build', 'var2', 'f2.in'), test.workpath('work1', 'src', 'f2.in'))) - + # Make sure we didn't duplicate the source files in build/var3. test.must_not_exist(['work1', 'build', 'var3', 'f1.c']) test.must_not_exist(['work1', 'build', 'var3', 'f2.in']) @@ -381,7 +381,7 @@ def equal_stats(x,y): test.write( ['work3', 'SConstruct'], """\ SConscriptChdir(0) -VariantDir('build', '.', duplicate=1 ) +VariantDir('build', '.', duplicate=1 ) SConscript( 'build/SConscript' ) """) diff --git a/test/VariantDir/errors.py b/test/VariantDir/errors.py index 1ff3be3c4d..7400056e7e 100644 --- a/test/VariantDir/errors.py +++ b/test/VariantDir/errors.py @@ -65,6 +65,7 @@ def cat(env, source, target): with open(str(src), "r") as f2: f.write(f2.read()) +DefaultEnvironment(tools=[]) # test speedup env = Environment(BUILDERS={'Build':Builder(action=cat)}, SCANNERS=[Scanner(fake_scan, skeys = ['.in'])]) @@ -88,7 +89,7 @@ def cat(env, source, target): if sys.platform != 'win32': dir = os.path.join('ro-dir', 'build') test.subdir(dir) - os.chmod(dir, os.stat(dir)[stat.ST_MODE] & ~stat.S_IWUSR) + os.chmod(dir, os.stat(dir).st_mode & ~stat.S_IWUSR) test.run(chdir = 'ro-dir', arguments = ".", @@ -103,16 +104,16 @@ def cat(env, source, target): test.subdir(dir) SConscript = test.workpath(dir, 'SConscript') test.write(SConscript, '') -os.chmod(SConscript, os.stat(SConscript)[stat.ST_MODE] & ~stat.S_IWUSR) +os.chmod(SConscript, os.stat(SConscript).st_mode & ~stat.S_IWUSR) with open(SConscript, 'r'): - os.chmod(dir, os.stat(dir)[stat.ST_MODE] & ~stat.S_IWUSR) + os.chmod(dir, os.stat(dir).st_mode & ~stat.S_IWUSR) test.run(chdir = 'ro-SConscript', arguments = ".", status = 2, stderr = "scons: *** Cannot duplicate `%s' in `build': Permission denied. Stop.\n" % os.path.join('src', 'SConscript')) - os.chmod('ro-SConscript', os.stat('ro-SConscript')[stat.ST_MODE] | stat.S_IWUSR) + os.chmod('ro-SConscript', os.stat('ro-SConscript').st_mode | stat.S_IWUSR) test.run(chdir = 'ro-SConscript', arguments = ".", @@ -130,9 +131,9 @@ def cat(env, source, target): test.write([dir, 'SConscript'], '') file_in = test.workpath(dir, 'file.in') test.write(file_in, '') -os.chmod(file_in, os.stat(file_in)[stat.ST_MODE] & ~stat.S_IWUSR) +os.chmod(file_in, os.stat(file_in).st_mode & ~stat.S_IWUSR) with open(file_in, 'r'): - os.chmod(dir, os.stat(dir)[stat.ST_MODE] & ~stat.S_IWUSR) + os.chmod(dir, os.stat(dir).st_mode & ~stat.S_IWUSR) test.run(chdir = 'ro-src', arguments = ".", diff --git a/test/ZIP/ZIP.py b/test/ZIP/ZIP.py index 09115fea13..69f524e152 100644 --- a/test/ZIP/ZIP.py +++ b/test/ZIP/ZIP.py @@ -118,9 +118,9 @@ def marker(target, source, env): test.fail_test(test.zipfile_files("f3.xyzzy") != ['file16', 'file17', 'file18']) -f4_size = os.stat('f4.zip')[stat.ST_SIZE] -f4stored_size = os.stat('f4stored.zip')[stat.ST_SIZE] -f4deflated_size = os.stat('f4deflated.zip')[stat.ST_SIZE] +f4_size = os.stat('f4.zip').st_size +f4stored_size = os.stat('f4stored.zip').st_size +f4deflated_size = os.stat('f4deflated.zip').st_size test.fail_test(f4_size != f4deflated_size) test.fail_test(f4stored_size == f4deflated_size) diff --git a/test/option/option--duplicate.py b/test/option/option--duplicate.py index 74de64b646..927de86c93 100644 --- a/test/option/option--duplicate.py +++ b/test/option/option--duplicate.py @@ -28,8 +28,6 @@ SConscript settable option. """ -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - import os import sys import stat @@ -85,7 +83,7 @@ } def testLink(file, type): - nl = os.stat(file)[stat.ST_NLINK] + nl = os.stat(file).st_nlink islink = os.path.islink(file) assert criterion[type](nl, islink), \ "Expected %s to be %s (nl %d, islink %d)" \ diff --git a/testing/framework/TestCmd.py b/testing/framework/TestCmd.py index 56c282c990..4863a13c82 100644 --- a/testing/framework/TestCmd.py +++ b/testing/framework/TestCmd.py @@ -811,7 +811,7 @@ def where_is(file, path=None, pathext=None): st = os.stat(f) except OSError: continue - if stat.S_IMODE(st[stat.ST_MODE]) & 0o111: + if stat.S_IMODE(st.st_mode) & stat.S_IXUSR: return f return None @@ -1978,7 +1978,7 @@ def do_chmod(fname) -> None: pass else: os.chmod(fname, stat.S_IMODE( - st[stat.ST_MODE] | stat.S_IREAD)) + st.st_mode | stat.S_IREAD)) else: def do_chmod(fname) -> None: try: @@ -1987,7 +1987,7 @@ def do_chmod(fname) -> None: pass else: os.chmod(fname, stat.S_IMODE( - st[stat.ST_MODE] & ~stat.S_IREAD)) + st.st_mode & ~stat.S_IREAD)) if os.path.isfile(top): # If it's a file, that's easy, just chmod it. @@ -2047,7 +2047,7 @@ def do_chmod(fname) -> None: except OSError: pass else: - os.chmod(fname, stat.S_IMODE(st[stat.ST_MODE] | stat.S_IWRITE)) + os.chmod(fname, stat.S_IMODE(st.st_mode | stat.S_IWRITE)) else: def do_chmod(fname) -> None: try: @@ -2056,7 +2056,7 @@ def do_chmod(fname) -> None: pass else: os.chmod(fname, stat.S_IMODE( - st[stat.ST_MODE] & ~stat.S_IWRITE)) + st.st_mode & ~stat.S_IWRITE)) if os.path.isfile(top): do_chmod(top) @@ -2087,7 +2087,7 @@ def do_chmod(fname) -> None: pass else: os.chmod(fname, stat.S_IMODE( - st[stat.ST_MODE] | stat.S_IEXEC)) + st.st_mode | stat.S_IEXEC)) else: def do_chmod(fname) -> None: try: @@ -2096,7 +2096,7 @@ def do_chmod(fname) -> None: pass else: os.chmod(fname, stat.S_IMODE( - st[stat.ST_MODE] & ~stat.S_IEXEC)) + st.st_mode & ~stat.S_IEXEC)) if os.path.isfile(top): # If it's a file, that's easy, just chmod it. diff --git a/testing/framework/TestCmdTests.py b/testing/framework/TestCmdTests.py index 61c0c5da97..f7a437b106 100644 --- a/testing/framework/TestCmdTests.py +++ b/testing/framework/TestCmdTests.py @@ -47,15 +47,15 @@ def _is_readable(path): # XXX this doesn't take into account UID, it assumes it's our file - return os.stat(path)[stat.ST_MODE] & stat.S_IREAD + return os.stat(path).st_mode & stat.S_IREAD def _is_writable(path): # XXX this doesn't take into account UID, it assumes it's our file - return os.stat(path)[stat.ST_MODE] & stat.S_IWRITE + return os.stat(path).st_mode & stat.S_IWRITE def _is_executable(path): # XXX this doesn't take into account UID, it assumes it's our file - return os.stat(path)[stat.ST_MODE] & stat.S_IEXEC + return os.stat(path).st_mode & stat.S_IEXEC def _clear_dict(dict, *keys) -> None: for key in keys: @@ -268,17 +268,17 @@ def test_chmod(self) -> None: test.chmod(wdir_file1, stat.S_IREAD) test.chmod(['sub', 'file2'], stat.S_IWRITE) - file1_mode = stat.S_IMODE(os.stat(wdir_file1)[stat.ST_MODE]) + file1_mode = stat.S_IMODE(os.stat(wdir_file1).st_mode) assert file1_mode == 0o444, f'0{file1_mode:o}' - file2_mode = stat.S_IMODE(os.stat(wdir_sub_file2)[stat.ST_MODE]) + file2_mode = stat.S_IMODE(os.stat(wdir_sub_file2).st_mode) assert file2_mode == 0o666, f'0{file2_mode:o}' test.chmod('file1', stat.S_IWRITE) test.chmod(wdir_sub_file2, stat.S_IREAD) - file1_mode = stat.S_IMODE(os.stat(wdir_file1)[stat.ST_MODE]) + file1_mode = stat.S_IMODE(os.stat(wdir_file1).st_mode) assert file1_mode == 0o666, f'0{file1_mode:o}' - file2_mode = stat.S_IMODE(os.stat(wdir_sub_file2)[stat.ST_MODE]) + file2_mode = stat.S_IMODE(os.stat(wdir_sub_file2).st_mode) assert file2_mode == 0o444, f'0{file2_mode:o}' else: @@ -286,17 +286,17 @@ def test_chmod(self) -> None: test.chmod(wdir_file1, 0o700) test.chmod(['sub', 'file2'], 0o760) - file1_mode = stat.S_IMODE(os.stat(wdir_file1)[stat.ST_MODE]) + file1_mode = stat.S_IMODE(os.stat(wdir_file1).st_mode) assert file1_mode == 0o700, f'0{file1_mode:o}' - file2_mode = stat.S_IMODE(os.stat(wdir_sub_file2)[stat.ST_MODE]) + file2_mode = stat.S_IMODE(os.stat(wdir_sub_file2).st_mode) assert file2_mode == 0o760, f'0{file2_mode:o}' test.chmod('file1', 0o765) test.chmod(wdir_sub_file2, 0o567) - file1_mode = stat.S_IMODE(os.stat(wdir_file1)[stat.ST_MODE]) + file1_mode = stat.S_IMODE(os.stat(wdir_file1).st_mode) assert file1_mode == 0o765, f'0{file1_mode:o}' - file2_mode = stat.S_IMODE(os.stat(wdir_sub_file2)[stat.ST_MODE]) + file2_mode = stat.S_IMODE(os.stat(wdir_sub_file2).st_mode) assert file2_mode == 0o567, f'0{file2_mode:o}' @@ -3315,11 +3315,11 @@ def test_executable(self) -> None: def make_executable(fname) -> None: st = os.stat(fname) - os.chmod(fname, stat.S_IMODE(st[stat.ST_MODE]|0o100)) + os.chmod(fname, stat.S_IMODE(st.st_mode|0o100)) def make_non_executable(fname) -> None: st = os.stat(fname) - os.chmod(fname, stat.S_IMODE(st[stat.ST_MODE]&~0o100)) + os.chmod(fname, stat.S_IMODE(st.st_mode&~0o100)) test.executable(test.workdir, 0) # XXX skip these tests if euid == 0? diff --git a/testing/framework/TestCommon.py b/testing/framework/TestCommon.py index 470dbcb208..5038f1a665 100644 --- a/testing/framework/TestCommon.py +++ b/testing/framework/TestCommon.py @@ -215,7 +215,7 @@ def is_Sequence(e): hasattr(e, "__iter__")) def is_writable(f): - mode = os.stat(f)[stat.ST_MODE] + mode = os.stat(f).st_mode return mode & stat.S_IWUSR def separate_files(flist): diff --git a/testing/framework/TestCommonTests.py b/testing/framework/TestCommonTests.py index 3f7d3fd2e4..5ed2779c0a 100644 --- a/testing/framework/TestCommonTests.py +++ b/testing/framework/TestCommonTests.py @@ -222,7 +222,7 @@ def test_writable_file_exists(self) -> None: tc = TestCommon(workdir='') tc.write('file1', "file1\\n") f1 = tc.workpath('file1') - mode = os.stat(f1)[stat.ST_MODE] + mode = os.stat(f1).st_mode os.chmod(f1, mode | stat.S_IWUSR) tc.must_be_writable('file1') tc.pass_test() @@ -244,7 +244,7 @@ def test_non_writable_file_exists(self) -> None: tc = TestCommon(workdir='') tc.write('file1', "file1\\n") f1 = tc.workpath('file1') - mode = os.stat(f1)[stat.ST_MODE] + mode = os.stat(f1).st_mode os.chmod(f1, mode & ~stat.S_IWUSR) tc.must_be_writable('file1') tc.pass_test() @@ -267,7 +267,7 @@ def test_file_specified_as_list(self) -> None: tc.subdir('sub') tc.write(['sub', 'file1'], "sub/file1\\n") f1 = tc.workpath('sub', 'file1') - mode = os.stat(f1)[stat.ST_MODE] + mode = os.stat(f1).st_mode os.chmod(f1, mode | stat.S_IWUSR) tc.must_be_writable(['sub', 'file1']) tc.pass_test() @@ -1253,7 +1253,7 @@ def test_writable_file_exists(self) -> None: tc = TestCommon(workdir='') tc.write('file1', "file1\\n") f1 = tc.workpath('file1') - mode = os.stat(f1)[stat.ST_MODE] + mode = os.stat(f1).st_mode os.chmod(f1, mode | stat.S_IWUSR) tc.must_not_be_writable('file1') tc.pass_test() @@ -1275,7 +1275,7 @@ def test_non_writable_file_exists(self) -> None: tc = TestCommon(workdir='') tc.write('file1', "file1\\n") f1 = tc.workpath('file1') - mode = os.stat(f1)[stat.ST_MODE] + mode = os.stat(f1).st_mode os.chmod(f1, mode & ~stat.S_IWUSR) tc.must_not_be_writable('file1') tc.pass_test() @@ -1298,7 +1298,7 @@ def test_file_specified_as_list(self) -> None: tc.subdir('sub') tc.write(['sub', 'file1'], "sub/file1\\n") f1 = tc.workpath('sub', 'file1') - mode = os.stat(f1)[stat.ST_MODE] + mode = os.stat(f1).st_mode os.chmod(f1, mode & ~stat.S_IWUSR) tc.must_not_be_writable(['sub', 'file1']) tc.pass_test()