Adding bdir() function
Adriaan de Groot <[email protected]> Fri, 25 Nov 2005 15:54:15 +0100
| Newsgroups | gmane.comp.tools.aap.devel |
|---|---|
| Message-ID | <[email protected]> |
--nextPart1229386.dVP9z58AXN
Content-Type: multipart/mixed;
boundary="Boundary-01=_YWyhDogACifx6T9"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
--Boundary-01=_YWyhDogACifx6T9
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
[Now with docs and better code formatting.]
The attached patch implements a bdir() function which prepends $BDIR if=20
necessary to a filename. Optionally, the attributes of the filename are=20
stripped, which is needed if the filename is to be used in a shell command.
bdir() is used (quite a bit) in the updates to the Qt and KDE modules I'll =
be=20
posting shortly.
=2D-=20
These are your friends - Adem
GPG: FEA2 A3FE Adriaan de Groot
--Boundary-01=_YWyhDogACifx6T9
Content-Type: text/x-diff;
charset="us-ascii";
name="bdir.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="bdir.diff"
Index: RecPython.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/a-a-p/Exec/RecPython.py,v
retrieving revision 1.42
diff -u -3 -p -r1.42 RecPython.py
=2D-- RecPython.py 30 May 2005 11:39:49 -0000 1.42
+++ RecPython.py 25 Nov 2005 14:51:55 -0000
@@ -336,6 +336,29 @@ def srcitem2obj(recdict, name, attrdict=20
attrdict["prefix"] + os.path.basenam=
e(n))
return n
=20
+def bdir(name, with_attr =3D 1):
+ """Prepend $BDIR to name if there is no BDIR there already.
+ If (optional) with_attr is 0, strip attributes and return
+ only a filename."""
+ bdir =3D get_var_val(0,Global.globals,"_no","BDIR")
+ bdirprefix =3D "build-" + get_var_val(0, Global.globals, "_no", "OSNAM=
E")
+
+ res =3D var2dictlist(name)
+ for i in res:
+ filename =3D i["name"]
+ # Common case: no bdir found. Prepend bdir.
+ if filename.find(bdirprefix) < 0 :
+ i["name"] =3D os.path.join(bdir,filename)
+
+ # Convert back to string, with or without attributes
+ if with_attr:
+ return dictlist2str(res)
+ else:
+ rv =3D ""
+ for i in res:
+ rv +=3D (i["name"]+" ")
+ return rv
+
=20
def get_attr(fname):
"""Obtain the attribute dictionary for a file name.
Index: doc/ref-python.sgml
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/a-a-p/Exec/doc/ref-python.sgml,v
retrieving revision 1.18
diff -u -3 -p -r1.18 ref-python.sgml
=2D-- doc/ref-python.sgml 21 Jun 2004 12:24:31 -0000 1.18
+++ doc/ref-python.sgml 25 Nov 2005 14:51:55 -0000
@@ -163,6 +163,10 @@
<entry> Prepend $BASEDIR to every item in the argument. </entry>
</row>
<row>
+ <entry><link linkend=3D"python-bdir"> bdir() </link></entry>
+ <entry> Prepend $BDIR as needed to an argument, optionally strippi=
ng attributes. </entry>
+ </row>
+ <row>
<entry> </entry>
<entry></entry>
</row>
@@ -285,6 +289,37 @@
</varlistentry>
=20
=20
+ <varlistentry id=3D'python-bdir'>
+ <term><cmdsynopsis>
+ <command>bdir(file, with_attributes=3D1)</command>
+ </cmdsynopsis></term>
+ <listitem>
+ <para>
+ Prepend $BDIR to the single filename "file", but only if this is n=
eeded -- that is,
+ if $BDIR isn't already there. This makes the filename point into $=
BDIR, which is useful
+ for creating temporary files (say, generating C from Yacc input). =
Unlike just prepending
+ $BDIR, though, bdir() only prepends $BDIR if needed (so if the Yac=
c input was already in $BDIR
+ because it was generated from another source, bdir() will do the r=
ight thing and prepending $BDIR/
+ won't).
+ <programlisting>
+ :sys uic -tr i18n $source > `bdir(target,0)`
+</programlisting>
+ In this example, the output is written to the target file, and the=
target is forced
+ into the build directory.
+ In general, bdir() is used most when there are multi-stage compila=
tions going on,
+ and should probably be well-hidden in &Aap; modules.
+ </para>
+ <para>
+ The function bdir() returns a string. If "with_attributes" has a n=
on-zero value, the attributes
+ for the file are preserved in the string. This is useful for furth=
er processing by &Aap;.
+ For the case where you want just the filename in the build directo=
ry, set
+ "with_attributes" to 0, as in the example above (if you don't, you=
get very strange filenames
+ depending on the attributes attached to the file).
+ </para>
+ </listitem>
+ </varlistentry>
+
+
<varlistentry id=3D'python-childdir'>
<term><cmdsynopsis>
<command>childdir(arg)</command>
--Boundary-01=_YWyhDogACifx6T9--
--nextPart1229386.dVP9z58AXN
Content-Type: application/pgp-signature
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (FreeBSD)
iD8DBQBDhyWYdqzuAf6io/4RAtLXAJ9MArYrXcRGZmY/+MrIjf0f5LngIQCfeixm
u8eU9JGdIgR4osTOQeGQbZk=
=SfDd
-----END PGP SIGNATURE-----
--nextPart1229386.dVP9z58AXN--
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click