[Scons-users] How to identify a Node object as File or Directory type

M Busche spammymatt94 at yahoo.com
Fri Jun 15 17:01:52 EDT 2012


Gary,

Thank you for your reply.  Due to my extreme noobishness, it took me quite a while to figure out what I needed to import to get isinstance to work for me (without simultaneously introducing a naming conflict).  Here's what I came up with:

matt at meteor:scons.test$ cat SConstruct
from SCons.Node import FS
d = Dir('blech')
print isinstance(d, FS.Dir)
matt at meteor:scons.test$ scons -Q
True
scons: `.' is up to date.


Does this look correct and as simple as possible?


Thanks,
Matt


matt at meteor:scons.test$ cat SConstruct
from SCons.Node.FS import Dir
d = Dir('blech')
print isinstance(d, Dir)
matt at meteor:scons.test$ scons -Q
TypeError: __init__() takes exactly 4 arguments (2 given):
  File "/home/matt/dev/scons.test/SConstruct", line 2:
    d = Dir('blech')


So the class def is not in scope.  So I tried this:

matt at meteor:scons.test$ cat SConstruct
from SCons.Node.FS import Dir
d = Dir('blech')
print isinstance(d, Dir)
matt at meteor:scons.test$ scons -Q
TypeError: __init__() takes exactly 4 arguments (2 given):
  File "/home/matt/dev/scons.test/SConstruct", line 2:
    d = Dir('blech')

This result did not surprise me.  I gather there's a function Dir() defined in the SCons package whereas Dir in subpackage FS is a class and the two names conflict?  I have not yet learned how to deal with such conflicts in Python.  I ignorantly tried something java-ish at it:  isinstance(d, SCons.Node.FS.Dir) and got abused.

This does work:

matt at meteor:scons.test$ cat SConstruct
d = Dir('blech')
from SCons.Node.FS import Dir
print isinstance(d, Dir)
matt at meteor:scons.test$ scons -Q
True
scons: `.' is up to date.
matt at meteor:scons.test$

But obviously that is totally unsatisfactory.  Again, thank you for your patience.

Matt



----- Original Message -----
From: Gary Oberbrunner <garyo at oberbrunner.com>
To: M Busche <spammymatt94 at yahoo.com>; SCons users mailing list <scons-users at scons.org>
Cc:
Sent: Friday, June 15, 2012 12:53 PM
Subject: Re: [Scons-users] How to identify a Node object as File or Directory type

On Fri, Jun 15, 2012 at 1:48 PM, M Busche <spammymatt94 at yahoo.com> wrote:

>

> OK, so the directory blech does not yet exist, but I was still expecting d.isdir() to return true.  How am I supposed to interrogate d to determine that it is a Dir type Node?


d.isdir() checks on disk, so it won't work for what you want.  I don't
think there is a public API for this, but you can look at d.__class__
or use isinstance(d, Dir).

--
Gary



More information about the Scons-users mailing list