Re: Using _recipe in python snippts

Bram Moolenaar <[email protected]>
Newsgroups gmane.comp.tools.aap.devel
Message-ID <[email protected]>
Adriaan de Groot wrote:

> In order to test if a variable is set, I've taken to using
> _recipe.has_key() - something like this:
> 
> :if _recipe.has_key("SUBDIRS"):
> 	:child $SUBDIRS
> 
> I couldn't quickly find another way to do this.

That works fine when $SUBDIRS is set (or not) in the recipe where you
use this.  I often use get(), so that an empty value is ignored (and
it's shorter! :-):

    :if _recipe.get("SUBDIRS"):
 	:child $SUBDIRS

> Now the problem is that _recipe doesn't always exist. In particular,
> suppose I have a main.aap in .,./a,and ./a/a that looks like this:

"_recipe" should always exist.  It stands for the scope of the current
recipe and there always is a current recipe.

> ==main.aap
> :child a/main.aap
> ==
> 
> Finally, in ./a/a/a, main.aap looks lile:
> ==main.aap
> :print $TOPDIR
> @if _recipe.has_key("SUBDIRS"):
> 	:child $SUBDIRS
> ==
> 
> If I run AAP on this setup, AAP tells me (paraphrased): recipe "a"# does
> not exist. I haven't quite figured out how to convice AAP that it _does_
> exist - adding :program targets in each recipe doesn't seem to make a
> difference.
> 
> So how _should_ I be testing for the existence of a variable in a Python
> snippet?

It looks like your $SUBDIRS is set in another recipe, thus in another
scope.  You should probably use the "_no" scope, which works like using
$SUBDIRS without specifying a scope (thus the name "no scope").

    @if _no.get("SUBDIRS"):
 	:child $SUBDIRS

Does that work for you?

I know that "_no" is a strange name to use for a scope, I still haven't
come up with a better name.

-- 
hundred-and-one symptoms of being an internet addict:
113. You are asked about a bus schedule, you wonder if it is 16 or 32 bits.

 /// 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 sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
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.