All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clark Williams <williams@redhat.com>
To: "Raphaël Beamonte" <raphael.beamonte@gmail.com>
Cc: linux-rt-users@vger.kernel.org, dsommers@redhat.com
Subject: Re: [PATCH] Changes the getcmdpath method to use only python calls to find the paths
Date: Thu, 29 Nov 2012 15:44:16 -0600	[thread overview]
Message-ID: <20121129154416.5cfec3a9@redhat.com> (raw)
In-Reply-To: <1353540131-18978-1-git-send-email-raphael.beamonte@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1937 bytes --]

On Wed, 21 Nov 2012 18:22:11 -0500
Raphaël Beamonte <raphael.beamonte@gmail.com> wrote:

> 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 <raphael.beamonte@gmail.com>
> ---
>  rteval/rteval.py |   12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/rteval/rteval.py b/rteval/rteval.py
> index beba49f..5843d78 100644
> --- a/rteval/rteval.py
> +++ b/rteval/rteval.py
> @@ -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]
> -- 


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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

      reply	other threads:[~2012-11-29 21:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-21 23:22 [PATCH] Changes the getcmdpath method to use only python calls to find the paths Raphaël Beamonte
2012-11-29 21:44 ` Clark Williams [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121129154416.5cfec3a9@redhat.com \
    --to=williams@redhat.com \
    --cc=dsommers@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=raphael.beamonte@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.