Re: [Scons-dev] Contribution to SCons development.
On Sun, Dec 7, 2014 at 2:25 AM, Gary Oberbrunner wrote: > > > On Sat, Dec 6, 2014 at 1:03 PM, wrote: > >> I found one here: >> http://computer-programming-forum.com/56-python/46da865fb41a1dc3.htm >> >> Ansible worked on that as well: >> https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/basic.py >> >> (_symbolic_mode_to_octal, _apply_operation_to_mode, >> _get_octal_mode_from_symbolic_perms) >> > > Good detective work! The second is a bit more modern in style, but they > both seem workable. > Okay, so I have been approaching this issue wrongly from the beginning. So now what exactly do I do with this function? How do I make use of it? Thanks. -- Shreedhar Manek ___ Scons-dev mailing list Scons-dev@scons.org https://pairlist2.pair.net/mailman/listinfo/scons-dev
Re: [Scons-dev] Contribution to SCons development.
On Sat, Dec 6, 2014 at 1:03 PM, wrote: > I found one here: > http://computer-programming-forum.com/56-python/46da865fb41a1dc3.htm > > Ansible worked on that as well: > https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/basic.py > > (_symbolic_mode_to_octal, _apply_operation_to_mode, > _get_octal_mode_from_symbolic_perms) > Good detective work! The second is a bit more modern in style, but they both seem workable. -- Gary > > > Le 6 déc. 2014 à 16:24, Gary Oberbrunner a écrit : > > > > On Sat, Dec 6, 2014 at 9:37 AM, Shreedhar Manek > wrote: > >> 256 is octal 0400, so it looks like it's only getting the S_IRUSR part. And that's because I steered you wrong; these are bitmasks, so you have to use bitwise OR: S_IRUSR | S_IRGRP | S_IROTH >>> >> This was it. Thanks! >> >> Should I replace *all *integers with their counterpart string? Or only >> select ones? >> > > Well, first, don't forget your real goal is to allow SCons users to > actually use a *string* to set the mode bits. These constants you're > using are in the 'stat' module (so 'import stat' will fix your bug below), > but they are still numeric absolute constants. > > I think the original issue ( > http://scons.tigris.org/issues/show_bug.cgi?id=2494) asks for allowing > users to use actual strings like the chmod command-line utility, which > allows relative modes like "ug+rw,o-rwx" as well as numeric absolute modes > like "777" (that's still a string, note). (see the chmod man page, for > instance http://linux.die.net/man/1/chmod.) SCons users could already > just do 'import stat' and use the named constants, but those are absolute; > the desired chmod modes are *relative *to the current state. The main > task for this issue is, I think, to parse those relative modes (relative to > the file's current state) and compute the desired final mode. > > If you can write a function parse_mode_string(mode_string, > original_mode_bits), that's 90% of the work. (Actually I'm surprised there > isn't one already written out there somewhere.) > > -- Gary > > >> Replacing the first 0777 with S_IRWXU | S_IRWXG | S_IRWXO in >> >> test.write('SConstruct', """ >> Execute(Chmod('f1', 0666)) >> Execute(Chmod(('f1-File'), 0666)) >> Execute(Chmod('d2', S_IRWXU | S_IRWXG | S_IRWXO)) >> Execute(Chmod(Dir('d2-Dir'), 0777)) >> def cat(env, source, target): >> target = str(target[0]) >> f = open(target, "wb") >> for src in source: >> f.write(open(str(src), "rb").read()) >> f.close() >> Cat = Action(cat) >> env = Environment() >> env.Command('bar.out', 'bar.in', [Cat, >> Chmod("f3", 0666), >> Chmod("d4", 0777)]) >> env = Environment(FILE = 'f5') >> env.Command('f6.out', 'f6.in', [Chmod('$FILE', 0666), Cat]) >> env.Command('f7.out', 'f7.in', [Cat, >> Chmod('Chmod-$SOURCE', 0666), >> Chmod('${TARGET}-Chmod', 0666)]) >> >> # Make sure Chmod works with a list of arguments >> env = Environment(FILE = 'f9') >> env.Command('f8.out', 'f8.in', [Chmod(['$FILE', File('f10')], 0666), >> Cat]) >> Execute(Chmod(['d11', Dir('d12')], 0777)) >> """) >> >> gives the following error, >> >> STDERR >> = >> NameError: name 'S_IRWXU' is not defined: >> File "/tmp/testcmd.23013.se_zJm/SConstruct", line 4: >> Execute(Chmod('d2', S_IRWXU | S_IRWXG | S_IRWXO)) >> >> FAILED test of /home/shrox/scons/src/script/scons.py >> at line 598 of /home/shrox/scons/QMTest/TestCommon.py (_complete) >> from line 701 of /home/shrox/scons/QMTest/TestCommon.py (run) >> from line 390 of /home/shrox/scons/QMTest/TestSCons.py (run) >> from line 123 of test/Chmod.py >> >> >> >> -- >> Shreedhar Manek >> >> ___ >> Scons-dev mailing list >> Scons-dev@scons.org >> https://pairlist2.pair.net/mailman/listinfo/scons-dev >> >> > > > -- > Gary > ___ > Scons-dev mailing list > Scons-dev@scons.org > https://pairlist2.pair.net/mailman/listinfo/scons-dev > > > > ___ > Scons-dev mailing list > Scons-dev@scons.org > https://pairlist2.pair.net/mailman/listinfo/scons-dev > > -- Gary ___ Scons-dev mailing list Scons-dev@scons.org https://pairlist2.pair.net/mailman/listinfo/scons-dev
Re: [Scons-dev] Contribution to SCons development.
I found one here: http://computer-programming-forum.com/56-python/46da865fb41a1dc3.htm Ansible worked on that as well: https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/basic.py (_symbolic_mode_to_octal, _apply_operation_to_mode, _get_octal_mode_from_symbolic_perms) Le 6 déc. 2014 à 16:24, Gary Oberbrunner a écrit : > > > On Sat, Dec 6, 2014 at 9:37 AM, Shreedhar Manek > wrote: > 256 is octal 0400, so it looks like it's only getting the S_IRUSR part. And > that's because I steered you wrong; these are bitmasks, so you have to use > bitwise OR: S_IRUSR | S_IRGRP | S_IROTH > > This was it. Thanks! > > Should I replace all integers with their counterpart string? Or only select > ones? > > Well, first, don't forget your real goal is to allow SCons users to actually > use a string to set the mode bits. These constants you're using are in the > 'stat' module (so 'import stat' will fix your bug below), but they are still > numeric absolute constants. > > I think the original issue > (http://scons.tigris.org/issues/show_bug.cgi?id=2494) asks for allowing users > to use actual strings like the chmod command-line utility, which allows > relative modes like "ug+rw,o-rwx" as well as numeric absolute modes like > "777" (that's still a string, note). (see the chmod man page, for instance > http://linux.die.net/man/1/chmod.) SCons users could already just do 'import > stat' and use the named constants, but those are absolute; the desired chmod > modes are relative to the current state. The main task for this issue is, I > think, to parse those relative modes (relative to the file's current state) > and compute the desired final mode. > > If you can write a function parse_mode_string(mode_string, > original_mode_bits), that's 90% of the work. (Actually I'm surprised there > isn't one already written out there somewhere.) > > -- Gary > > > Replacing the first 0777 with S_IRWXU | S_IRWXG | S_IRWXO in > > test.write('SConstruct', """ > Execute(Chmod('f1', 0666)) > Execute(Chmod(('f1-File'), 0666)) > Execute(Chmod('d2', S_IRWXU | S_IRWXG | S_IRWXO)) > Execute(Chmod(Dir('d2-Dir'), 0777)) > def cat(env, source, target): > target = str(target[0]) > f = open(target, "wb") > for src in source: > f.write(open(str(src), "rb").read()) > f.close() > Cat = Action(cat) > env = Environment() > env.Command('bar.out', 'bar.in', [Cat, > Chmod("f3", 0666), > Chmod("d4", 0777)]) > env = Environment(FILE = 'f5') > env.Command('f6.out', 'f6.in', [Chmod('$FILE', 0666), Cat]) > env.Command('f7.out', 'f7.in', [Cat, > Chmod('Chmod-$SOURCE', 0666), > Chmod('${TARGET}-Chmod', 0666)]) > > # Make sure Chmod works with a list of arguments > env = Environment(FILE = 'f9') > env.Command('f8.out', 'f8.in', [Chmod(['$FILE', File('f10')], 0666), Cat]) > Execute(Chmod(['d11', Dir('d12')], 0777)) > """) > > gives the following error, > > STDERR > = > NameError: name 'S_IRWXU' is not defined: > File "/tmp/testcmd.23013.se_zJm/SConstruct", line 4: > Execute(Chmod('d2', S_IRWXU | S_IRWXG | S_IRWXO)) > > FAILED test of /home/shrox/scons/src/script/scons.py > at line 598 of /home/shrox/scons/QMTest/TestCommon.py (_complete) > from line 701 of /home/shrox/scons/QMTest/TestCommon.py (run) > from line 390 of /home/shrox/scons/QMTest/TestSCons.py (run) > from line 123 of test/Chmod.py > > > > -- > Shreedhar Manek > > ___ > Scons-dev mailing list > Scons-dev@scons.org > https://pairlist2.pair.net/mailman/listinfo/scons-dev > > > > > -- > Gary > ___ > Scons-dev mailing list > Scons-dev@scons.org > https://pairlist2.pair.net/mailman/listinfo/scons-dev ___ Scons-dev mailing list Scons-dev@scons.org https://pairlist2.pair.net/mailman/listinfo/scons-dev
Re: [Scons-dev] Contribution to SCons development.
On Sat, Dec 6, 2014 at 9:37 AM, Shreedhar Manek wrote: > 256 is octal 0400, so it looks like it's only getting the S_IRUSR part. >>> And that's because I steered you wrong; these are bitmasks, so you have to >>> use bitwise OR: S_IRUSR | S_IRGRP | S_IROTH >>> >> > This was it. Thanks! > > Should I replace *all *integers with their counterpart string? Or only > select ones? > Well, first, don't forget your real goal is to allow SCons users to actually use a *string* to set the mode bits. These constants you're using are in the 'stat' module (so 'import stat' will fix your bug below), but they are still numeric absolute constants. I think the original issue ( http://scons.tigris.org/issues/show_bug.cgi?id=2494) asks for allowing users to use actual strings like the chmod command-line utility, which allows relative modes like "ug+rw,o-rwx" as well as numeric absolute modes like "777" (that's still a string, note). (see the chmod man page, for instance http://linux.die.net/man/1/chmod.) SCons users could already just do 'import stat' and use the named constants, but those are absolute; the desired chmod modes are *relative *to the current state. The main task for this issue is, I think, to parse those relative modes (relative to the file's current state) and compute the desired final mode. If you can write a function parse_mode_string(mode_string, original_mode_bits), that's 90% of the work. (Actually I'm surprised there isn't one already written out there somewhere.) -- Gary > Replacing the first 0777 with S_IRWXU | S_IRWXG | S_IRWXO in > > test.write('SConstruct', """ > Execute(Chmod('f1', 0666)) > Execute(Chmod(('f1-File'), 0666)) > Execute(Chmod('d2', S_IRWXU | S_IRWXG | S_IRWXO)) > Execute(Chmod(Dir('d2-Dir'), 0777)) > def cat(env, source, target): > target = str(target[0]) > f = open(target, "wb") > for src in source: > f.write(open(str(src), "rb").read()) > f.close() > Cat = Action(cat) > env = Environment() > env.Command('bar.out', 'bar.in', [Cat, > Chmod("f3", 0666), > Chmod("d4", 0777)]) > env = Environment(FILE = 'f5') > env.Command('f6.out', 'f6.in', [Chmod('$FILE', 0666), Cat]) > env.Command('f7.out', 'f7.in', [Cat, > Chmod('Chmod-$SOURCE', 0666), > Chmod('${TARGET}-Chmod', 0666)]) > > # Make sure Chmod works with a list of arguments > env = Environment(FILE = 'f9') > env.Command('f8.out', 'f8.in', [Chmod(['$FILE', File('f10')], 0666), Cat]) > Execute(Chmod(['d11', Dir('d12')], 0777)) > """) > > gives the following error, > > STDERR > = > NameError: name 'S_IRWXU' is not defined: > File "/tmp/testcmd.23013.se_zJm/SConstruct", line 4: > Execute(Chmod('d2', S_IRWXU | S_IRWXG | S_IRWXO)) > > FAILED test of /home/shrox/scons/src/script/scons.py > at line 598 of /home/shrox/scons/QMTest/TestCommon.py (_complete) > from line 701 of /home/shrox/scons/QMTest/TestCommon.py (run) > from line 390 of /home/shrox/scons/QMTest/TestSCons.py (run) > from line 123 of test/Chmod.py > > > > -- > Shreedhar Manek > > ___ > Scons-dev mailing list > Scons-dev@scons.org > https://pairlist2.pair.net/mailman/listinfo/scons-dev > > -- Gary ___ Scons-dev mailing list Scons-dev@scons.org https://pairlist2.pair.net/mailman/listinfo/scons-dev
Re: [Scons-dev] Contribution to SCons development.
> > 256 is octal 0400, so it looks like it's only getting the S_IRUSR part. >> And that's because I steered you wrong; these are bitmasks, so you have to >> use bitwise OR: S_IRUSR | S_IRGRP | S_IROTH >> > This was it. Thanks! Should I replace *all *integers with their counterpart string? Or only select ones? Replacing the first 0777 with S_IRWXU | S_IRWXG | S_IRWXO in test.write('SConstruct', """ Execute(Chmod('f1', 0666)) Execute(Chmod(('f1-File'), 0666)) Execute(Chmod('d2', S_IRWXU | S_IRWXG | S_IRWXO)) Execute(Chmod(Dir('d2-Dir'), 0777)) def cat(env, source, target): target = str(target[0]) f = open(target, "wb") for src in source: f.write(open(str(src), "rb").read()) f.close() Cat = Action(cat) env = Environment() env.Command('bar.out', 'bar.in', [Cat, Chmod("f3", 0666), Chmod("d4", 0777)]) env = Environment(FILE = 'f5') env.Command('f6.out', 'f6.in', [Chmod('$FILE', 0666), Cat]) env.Command('f7.out', 'f7.in', [Cat, Chmod('Chmod-$SOURCE', 0666), Chmod('${TARGET}-Chmod', 0666)]) # Make sure Chmod works with a list of arguments env = Environment(FILE = 'f9') env.Command('f8.out', 'f8.in', [Chmod(['$FILE', File('f10')], 0666), Cat]) Execute(Chmod(['d11', Dir('d12')], 0777)) """) gives the following error, STDERR = NameError: name 'S_IRWXU' is not defined: File "/tmp/testcmd.23013.se_zJm/SConstruct", line 4: Execute(Chmod('d2', S_IRWXU | S_IRWXG | S_IRWXO)) FAILED test of /home/shrox/scons/src/script/scons.py at line 598 of /home/shrox/scons/QMTest/TestCommon.py (_complete) from line 701 of /home/shrox/scons/QMTest/TestCommon.py (run) from line 390 of /home/shrox/scons/QMTest/TestSCons.py (run) from line 123 of test/Chmod.py -- Shreedhar Manek ___ Scons-dev mailing list Scons-dev@scons.org https://pairlist2.pair.net/mailman/listinfo/scons-dev
Re: [Scons-dev] Contribution to SCons development.
On Sat, Dec 6, 2014 at 4:35 AM, Shreedhar Manek wrote: > >>> I change the integer the equivalent string in chmod.py (eg. 0444 >>> to S_IRWXU and S_IRWXG and S_IRWXO) but there is problem ahead into the >>> program and the test fails at this point - >>> >> >> Watch out, 0444 is not the same as S_IRWXU and S_IRWXG and S_IRWXO, >> which would be because of the "and"s. 0444 is S_IRUSR or S_IRGRP or >> S_IROTH. >> >>> >>> > Ah, of course. Thanks! > > > >> s = S_IMODE(os.stat(test.workpath('f1'))[ST_MODE]) >>> test.fail_test(s != 0444) >>> >>> What do I do about this? >>> >> >> How does it fail? What is the value of s at that point? >> > > The value of s at that point in decimal is 256. I cannot figure why > though, as the only change that I've made is switching 0444 by S_IRUSR or > S_IRGRP or S_IROTH. > > 256 is octal 0400, so it looks like it's only getting the S_IRUSR part. And that's because I steered you wrong; these are bitmasks, so you have to use bitwise OR: S_IRUSR | S_IRGRP | S_IROTH -- Gary ___ Scons-dev mailing list Scons-dev@scons.org https://pairlist2.pair.net/mailman/listinfo/scons-dev
Re: [Scons-dev] Contribution to SCons development.
> > >> I change the integer the equivalent string in chmod.py (eg. 0444 >> to S_IRWXU and S_IRWXG and S_IRWXO) but there is problem ahead into the >> program and the test fails at this point - >> > > Watch out, 0444 is not the same as S_IRWXU and S_IRWXG and S_IRWXO, > which would be because of the "and"s. 0444 is S_IRUSR or S_IRGRP or > S_IROTH. > >> >> Ah, of course. Thanks! > s = S_IMODE(os.stat(test.workpath('f1'))[ST_MODE]) >> test.fail_test(s != 0444) >> >> What do I do about this? >> > > How does it fail? What is the value of s at that point? > The value of s at that point in decimal is 256. I cannot figure why though, as the only change that I've made is switching 0444 by S_IRUSR or S_IRGRP or S_IROTH. -- Shreedhar Manek ___ Scons-dev mailing list Scons-dev@scons.org https://pairlist2.pair.net/mailman/listinfo/scons-dev