Changes the getcmdpath method to use only python calls to find the paths
PATCH 1/1 Changes the getcmdpath method to use only python calls to find the paths
In my previous patches, I introduced a getcmdpath method which intended to replace the direct calls to binary from clear paths, using the which binary to locate the place of the searched one. This behavior was in fact not the finest as the method itself used the full path to the which binary. In this patch, I corrected the getcmdpath command to use only python calls (os.path.isfile and os.access) to identify in the PATH environment variable the place where the binary is.
--- rteval/rteval.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
rteval/rteval.py +9 -3
@@ -68,10 +68,16 @@ from cputopology import CPUtopology pathSave={} def getcmdpath(which): + """ + getcmdpath is a method which allows finding an executable in the PATH + directories to call it from full path + """ if not pathSave.has_key(which): - cmd = '/usr/bin/which %s' % which - c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) - pathSave[which] = c.stdout.read().strip() + for path in os.environ['PATH'].split(':'): + cmdfile = os.path.join(path, which) + if os.path.isfile(cmdfile) and os.access(cmdfile, os.X_OK): + pathSave[which] = cmdfile + break if not pathSave[which]: raise RuntimeError, "Command '%s' is unknown on this system" % which return pathSave[which]
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Clark Williams
AppliedQuoted 28 lines · On Wed, 21 Nov 2012 18:22:11 -0500 Raphaël Beamonte…
In my previous patches, I introduced a getcmdpath method which intended to replace the direct calls to binary from clear paths, using the which binary to locate the place of the searched one. This behavior was in fact not the finest as the method itself used the full path to the which binary. In this patch, I corrected the getcmdpath command to use only python calls (os.path.isfile and os.access) to identify in the PATH environment variable the place where the binary is.
Signed-off-by Raphaël Beamonte <[email protected]>--- rteval/rteval.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)rteval/rteval.py +4
-1@@ -68,10 +68,16 @@ from cputopology import CPUtopology pathSave={} def getcmdpath(which): + """ + getcmdpath is a method which allows finding an executable in the PATH + directories to call it from full path + """ if not pathSave.has_key(which): - cmd = '/usr/bin/which %s' % which
rteval/rteval.py from cputopology import CPUtopology · line 83
Quoted 10 lines
rteval/rteval.py +5
-2- c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) - pathSave[which] = c.stdout.read().strip() + for path in os.environ['PATH'].split(':'): + cmdfile = os.path.join(path, which) + if os.path.isfile(cmdfile) and os.access(cmdfile, os.X_OK): + pathSave[which] = cmdfile + break if not pathSave[which]: raise RuntimeError, "Command '%s' is unknown on this system" % which return pathSave[which]
Applied to my rteval-1.0 branch. I haven't pushed it out yet since I'm still looking at some other issues. Will go out with the next push.
Clark