Re: expand2list

Bram Moolenaar <[email protected]> Fri, 17 Sep 2004 20:37:05 +0200
Newsgroups gmane.comp.tools.aap.user
Message-ID <[email protected]>
Tim Hemel wrote:

> > > Is the following behaviour intended?
> > > 
> > > expand2list("patches-*") results in ['patches-*'] when there is no
> > > wildcard match. I would expect to see an empty list instead.
> > 
> > Yes, when there is no match the original item is used.  Helps when a
> > file name actually contains a * or ?.
> > 
> > Is this a problem?
> 
> It forces me to use constructs like these:
> 
> 	@l = expand2list(_no.PATCHES)
> 	@if l[0] == _no.PATCHES: l = []
> 	@for p in l:
> 		:sys cd $WRKDIR/$WRKSRC && patch -p1 <  `var_abspath(p)`
> 
> If a filename would contain a wildcard and I'd have to expand it, i
> think the * or ? should be escaped.

Expanding is done in several places, also for sources and targets of a
dependency.  Thus I have to be a bit careful about changing the function
that does the work, it doesn't affect expand2list() only.

Problem is that there currently is no way to escape wildcards.  The
Python glob.glob() function doesn't support it.

Try the change below.  The result is that it's impossible to use files
that actually do have wildcard characters in them (that is possible on
Unix).

An alternative would be to produce an error message when there is no
match.  You can then use try/except to make the list empty.


*** /home/mool/tmp/Dictlist.py	Fri Oct 31 11:17:09 2003
--- Dictlist.py	Fri Sep 17 19:40:26 2004
***************
*** 344,350 ****
      """
      Call dict_expand() for every dict in the list "dl".
      Expand wildcards "*", "?" and "[abc]".
!     Returns a new dictlist, possibly with more entries.
      """
      ret = []
      for dict in dl:
--- 344,351 ----
      """
      Call dict_expand() for every dict in the list "dl".
      Expand wildcards "*", "?" and "[abc]".
!     When there are no matches while there are wildcards, the item is not added.
!     Returns a new dictlist, possibly with more (or less) entries.
      """
      ret = []
      for dict in dl:
***************
*** 358,365 ****
              # Expand wildcars.
              exp = glob.glob(n)
              if not exp:
!                 # No match, add without expanding.
!                 ret.append(dict)
              else:
                  # Add a dictionary to the list for each match.
                  # Add the first match without duplicating the dict.
--- 359,367 ----
              # Expand wildcars.
              exp = glob.glob(n)
              if not exp:
!                 # If no match and has no wildcards: add without expanding.
!                 if not has_wildcard(n):
!                     ret.append(dict)
              else:
                  # Add a dictionary to the list for each match.
                  # Add the first match without duplicating the dict.
-- 
DENNIS: Look,  strange women lying on their backs in ponds handing out
        swords ... that's no basis for a system of government.  Supreme
        executive power derives from a mandate from the masses, not from some
        farcical aquatic ceremony.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\  Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///


-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php