Adding a bdir() function

Adriaan de Groot <adridg-FlD2LfDziEhmR6Xm/[email protected]>
Newsgroups gmane.comp.tools.aap.devel
Message-ID <[email protected]>
The attached patch adds a bdir() function to RecPython.py. The purpose of this 
function is to prepend $BDIR to a (list of) filename. The primary use is in 
actions, where using a construction like > $BDIR/$-target may not be the 
right thing to do if $target already has $BDIR prefixed to it. It certainly 
helps in the Qt module (patch also attached). So instead, you can use 
`bdir(target)` which DTRT (IMO).

The check to see if $BDIR is already in the filename is a little primitive, 
though it might be broken by some creative soul with a build-me/ subdirectory 
in a project. Perhaps I should also check for the os name?
bdir.diff (text/x-diff, 918 B)
Index: RecPython.py
===================================================================
RCS file: /cvsroot/a-a-p/Exec/RecPython.py,v
retrieving revision 1.31
diff -u -3 -p -r1.31 RecPython.py
--- RecPython.py	18 Oct 2003 15:09:21 -0000	1.31
+++ RecPython.py	21 Oct 2003 17:07:19 -0000
@@ -295,6 +295,20 @@ def srcitem2obj(recdict, name, attrdict 
                                       attrdict["prefix"] + os.path.basename(n))
     return n
 
+def bdir(name):
+    """Prepend $BDIR to name if there is no BDIR there already."""
+    bdir=get_var_val(0,Global.globals,"_no","BDIR")
+    if bdir:
+      bdir += "/"
+    res=[]
+    for i in var2dictlist(name):
+      filename=i["name"]
+      if filename.startswith("build-") and filename.find("/")>0:
+	res.append(filename)
+      else:
+	res.append(bdir + filename)
+    return res
+
 
 def get_attr(fname):
     """Obtain the attribute dictionary for a file name.
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.