Re: Adding a bdir() function
Bram Moolenaar <[email protected]>
| Newsgroups | gmane.comp.tools.aap.devel |
|---|---|
| Message-ID | <[email protected]> |
Adriaan de Groot wrote:
> 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?
I know we have gone over this function several times already, but I'm
the kind of person that isn't satisfied until it's perfect...
- Attributes in the list are lost. It should be too difficult to add
them back with dictlistattr2str().
- The path may be a full path, the "build-" may appear somewhere
halfway.
- Please use spaces around"="for readability.
> > 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.
The general rule is that "/" is used as a path separator whenever
possible. MS-Windows also mostly accepts this. Unfortunately, some
command-line commands do not allow it, this results in exceptions. And
then throw in some Cygwin tools that handle backslashes differently and
it gets even more complicated...
So, all paths should use "/" for path separator, unless "it doesn't
work".
--
TALL KNIGHT: Firstly. You must get us another shrubbery!
OTHER KNIGHTS: More shrubberies! More shrubberies for the ex-Knights of Ni!
ARTHUR: Not another shrubbery -
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
\\\ Project leader for A-A-P -- http://www.A-A-P.org ///
\\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html ///
-------------------------------------------------------
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/