Re: Adding a bdir() function

Adriaan de Groot <adridg-FlD2LfDziEhmR6Xm/[email protected]>
Newsgroups gmane.comp.tools.aap.devel
Message-ID <[email protected]>
On Friday 24 October 2003 17:25, Alexander Rødseth wrote:
> > Adriaan de Groot wrote:
> > I see a few problems/doubts here:
> > - You explicitly use "/" instead of using os.path.join().  Python
> >   purists don't like this.
>
> os.sep.join is much faster, and therefore, I guess, to be preferred by
> Python purists. :-)

OK, given that os.sep.join is apparently problematic in Python 1.5 and 
therefore unusable, my new version of bdir() is as follows:

def bdir(name):
    """Prepend $BDIR to name if there is no BDIR there already."""
    bdir=get_var_val(0,Global.globals,"_no","BDIR")
    res=[]
    for i in var2dictlist(name):
      filename=i["name"]
      (head,tail) = os.path.split(filename)
      if head.startswith("build-") and tail:
        res.append(filename)
      else:
        res.append(os.path.join(bdir,filename))
    return res

It's slash-free, which meant using os.path.join and os.path.split instead of 
find("/"). Making it more discerning is harder, since the BDIR name is 
constructed like ("build-" + fixname(sysname) + fixname(release)). Perhaps a 
top-level OSNAME variable to store that in? 



> Have you given up on supporting systems that doesn't use a single slash
> as a path separator, btw?

It looks like it, based on code like this:

    # Reject suffix if it contains a path separator.
    if string.find(suf, "/") >= 0 or string.find(suf, "\\") >= 0:

elsewhere in RecPython.py. Here again (head,tail) = os.path.split(string) is a 
possible other approach to "finding" the / or \, but consider also that an 
AAP recipe that refers to directories is already unportable then (ie. my 
recipes are crawling with source files like lib/init.cc, which are going to 
break on weird-separator systems anyway.



-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.