stat st_rdev in python

Grant Edwards grante at visi.com
Sat Jul 28 05:48:05 CEST 2001


In article <9jsop4$si0$1 at netra.msu.montana.edu>, Louis Glassy wrote:

>Is there a way to find out unix device major/minor numbers
>_in_ Python 2.1, without using an external C module or program?

I asked the exact same question about two weeks ago.

>The tuple returned by os.stat() does not return the stat 
>st_rdev field, which contains the information I need.

Exactly.

>I see two options:  either write my own binding to stat(2)
>or do something like a popen on /bin/ls.

I ended up with something like this:

    s,o = commands.getstatusoutput("/usr/bin/stat "+devName)
    if s:
        raise "error running /usr/bin/stat"
    r = re.compile("Device type: ([0-9]{1,3}),([0-9]{1,3})")
    m = r.search(o)
    if not m:
        raise "error parsing stat output"
    major = int(m.group(1))
    minor = int(m.group(2))

Nasty, but it works (so far).
    
>These both work, though neither is attractive.  It'd be nice if there were
>an unaldulterated posix module that I could call and get what everything
>that stat(2) would return.

That would be awfully nice.  A wrapper for the mknod() library call would
also be nice.

>Suggestions?

If I had more time, I'd fix up the Posix library and submit a patch...

-- 
Grant Edwards                   grante             Yow!  .. I want FORTY-TWO
                                  at               TRYNEL FLOATATION SYSTEMS
                               visi.com            installed within SIX AND A
                                                   HALF HOURS!!!



More information about the Python-list mailing list