Re: [Tutor] Test If File System is mounted in Linux

2006-03-18 Thread Pawel Kraszewski
Dnia piątek, 17 marca 2006 19:22, Bill Campbell napisał:

 If you're sure it's a Linux system, fine.  Like /etc/mtab, this isn't
 portable.  Looking at some of the systems we have here:

Fortezza mentioned it the way I assumed he has Linux:

 If there a semi-standard way to test if a file system has been mounted
 or not using Python? In the Linux command line, I can type mount and
 see all mounted file system, and then see if the one I am looking for is

But, generally - you are right. Each system has its own rules for accessing 
mount table. Anyway - this would be a great exercise to make a portable 
pure-python library to get this information.

-- 
 Pawel
 www.kraszewscy.net
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Test If File System is mounted in Linux

2006-03-17 Thread fortezza-pyt
If there a semi-standard way to test if a file system has been mounted 
or not using Python? In the Linux command line, I can type mount and 
see all mounted file system, and then see if the one I am looking for is 
in the list. While I could replicate this with
Python, I am curious if there is an easier way.

Thank You,

Fortezza

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Test If File System is mounted in Linux

2006-03-17 Thread Noufal Ibrahim

On Fri, March 17, 2006 1:06 pm, fortezza-pyt wrote:
 If there a semi-standard way to test if a file system has been mounted
 or not using Python? In the Linux command line, I can type mount and
 see all mounted file system, and then see if the one I am looking for is
 in the list. While I could replicate this with
 Python, I am curious if there is an easier way.

A quick Google search gives this
http://bebop.bigasterisk.com/python/docs/MtPython
Non standard perhaps but someone seems to have implemented a module that
does something like this.


-- 
-NI

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Test If File System is mounted in Linux

2006-03-17 Thread Michael Lange
On Fri, 17 Mar 2006 00:36:35 -0700
fortezza-pyt [EMAIL PROTECTED] wrote:

 If there a semi-standard way to test if a file system has been mounted 
 or not using Python? In the Linux command line, I can type mount and 
 see all mounted file system, and then see if the one I am looking for is 
 in the list. While I could replicate this with
 Python, I am curious if there is an easier way.
 

Hi Fortezza,

try os.path.ismount() .

HTH

Michael
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Test If File System is mounted in Linux

2006-03-17 Thread Bill Campbell
On Fri, Mar 17, 2006, Michael Lange wrote:
On Fri, 17 Mar 2006 00:36:35 -0700
fortezza-pyt [EMAIL PROTECTED] wrote:

 If there a semi-standard way to test if a file system has been mounted 
 or not using Python? In the Linux command line, I can type mount and 
 see all mounted file system, and then see if the one I am looking for is 
 in the list. While I could replicate this with
 Python, I am curious if there is an easier way.
 

Hi Fortezza,

try os.path.ismount() .

That's fine if one knows what the mount points are.

The more general problem is to get a list of mounted file systems.

The most standard way I've found to get a list of mounted systems is to
parse the output of the gdf program from the gnu fileutils compiled with
the program prefix `g' so it's called gdf.  The gdf program handles a lot
of the dirty work, and its output is standard regardless of the underlying
system, which you can't say about the system's mount or df commands.

The routine below is one I've used for years (actually I used a perl
version for a long time before switching primarily to python :-).

# This aren't real file systems.
pseudofilesys = \
dict(map((lambda x: (x, 1)), ('none', 'shmfs', 'procfs', 'tmpfs')))

gdf_cols = ('filesys', 'blocks', 'used', 'avail', 'use', 'dir')

def mounted():
'''Get Mounted File Systems'''
df = os.popen('gdf 2/dev/null', 'r')
df.readline() # skip first line
mounted = []
for line in df.readlines():
line = line.strip()
rec = dict(zip(gdf_cols, line.split(None, 5)))
filesys = rec['filesys']
dir = rec.get('dir')
if (
dir and not (filesys.find(':') = 0
or pseudofilesys.get(filesys))
): mounted.append(dir)
df.close()
return mounted

Bill
--
INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Systems, Inc.
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:(206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

``I presume you all know who I am.  I am humble Abraham Lincoln.  I have been
solicited by many friends to become a candidate for the legistlature.  My
politics are short and sweet, like the old woman's dance.  I am in favor of
a national bank ... in favor of the internal improvements system, and a
high protective tariff.'' -- Abraham Lincoln, 1832
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Test If File System is mounted in Linux

2006-03-17 Thread Adam
On 17/03/06, Bill Campbell [EMAIL PROTECTED] wrote:
 On Fri, Mar 17, 2006, Michael Lange wrote:
 On Fri, 17 Mar 2006 00:36:35 -0700
 fortezza-pyt [EMAIL PROTECTED] wrote:
 
  If there a semi-standard way to test if a file system has been mounted
  or not using Python? In the Linux command line, I can type mount and
  see all mounted file system, and then see if the one I am looking for is
  in the list. While I could replicate this with
  Python, I am curious if there is an easier way.
 
 
 Hi Fortezza,
 
 try os.path.ismount() .

 That's fine if one knows what the mount points are.

 The more general problem is to get a list of mounted file systems.

How about just reading the mtab? That's usually /etc/mtab it should be
readable as a user and it means you don't have to rely on any other
programs.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Test If File System is mounted in Linux

2006-03-17 Thread Pawel Kraszewski
Dnia piątek, 17 marca 2006 18:41, Adam napisał:

  The more general problem is to get a list of mounted file systems.

 How about just reading the mtab? That's usually /etc/mtab it should be
 readable as a user and it means you don't have to rely on any other
 programs.

Or always-up-to-date  user readable '/proc/mounts' ?

-- 
 Pawel Kraszewski
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Test If File System is mounted in Linux

2006-03-17 Thread Bill Campbell
On Fri, Mar 17, 2006, Adam wrote:
On 17/03/06, Bill Campbell [EMAIL PROTECTED] wrote:
 On Fri, Mar 17, 2006, Michael Lange wrote:
 On Fri, 17 Mar 2006 00:36:35 -0700
 fortezza-pyt [EMAIL PROTECTED] wrote:
 
  If there a semi-standard way to test if a file system has been mounted
  or not using Python? In the Linux command line, I can type mount and
  see all mounted file system, and then see if the one I am looking for is
  in the list. While I could replicate this with
  Python, I am curious if there is an easier way.
 
 
 Hi Fortezza,
 
 try os.path.ismount() .

 That's fine if one knows what the mount points are.

 The more general problem is to get a list of mounted file systems.

How about just reading the mtab? That's usually /etc/mtab it should be
readable as a user and it means you don't have to rely on any other
programs.

The words usually, and should are the kickers.  In the 24 years I've been
making my living on various versions of Unix type systems, I've seen a lot
of cases where this type of assumption either fails totally or gets me in
trouble because the vendor didn't do it the way they should.

This is the reason I started building standard open source tools for all
the systems we support (Richard Stallman would probably have said I was
creating GNU/Xenix and GNU/OpenServer systems back when we supported many
SCO systems :-).  My fingers automatically type gfind, gdu, etc., even on
Linux systems where I make symbolic links as necessary so I don't have to
remember what type of system I'm typing on.

One of the basic tenets of the *nix philosophy is ``build on the work of
others'', and it's a lot easier to leave figuring out the guts of various
systems to the authors of the gnu fileutils than it is to reinvent their
work every time I want to do something.

Bill
--
INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:(206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

A fake fortuneteller can be tolerated.  But an authentic soothsayer should
be shot on sight.  Cassandra did not get half the kicking around she deserved.
-- R.A. Heinlein
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Test If File System is mounted in Linux

2006-03-17 Thread Bill Campbell
On Fri, Mar 17, 2006, Pawel Kraszewski wrote:
Dnia piątek, 17 marca 2006 18:41, Adam napisał:

  The more general problem is to get a list of mounted file systems.

 How about just reading the mtab? That's usually /etc/mtab it should be
 readable as a user and it means you don't have to rely on any other
 programs.

Or always-up-to-date  user readable '/proc/mounts' ?

If you're sure it's a Linux system, fine.  Like /etc/mtab, this isn't
portable.  Looking at some of the systems we have here:

Linux -- systems from Caldera OpenLinux 2.3 through SuSE 10.0,
have /proc/mounts and /etc/mtab.

FreeBSD 4.8 Stable -- has /proc file system, but no /proc/mounts,
and no /etc/mtab (yeah 4.8 is out of date, but it's been up 632
days and I want to see how long it will stay up :-).

OS X 10.4.5 (Tiger) -- no /proc/mounts or /etc/fstab

SCO OpenServer 5.0.6a -- no /proc/mounts or /etc/fstab

All of these systems have the gnu gdf which returns information
in the same format.

Bill
--
INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Systems, Inc.
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:(206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

``Fix reason firmly in her seat and call to her tribunal every fact,
every opinion. Question with boldness even the existence of a God;
because, if there is one, he must more approve of the homage of 
reason, than that of blindfolded fear.''  --Thomas Jefferson
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor