Re: detecting drives for windows and linux

2006-03-29 Thread Florian Diesch
[EMAIL PROTECTED] (Alex Martelli) wrote:

> Florian Diesch <[EMAIL PROTECTED]> wrote:
>...
>> >> are and want to do it anyway?) Linux puts the whole file system 
>> >> (including mounted iPods, ISOs and NTFS drives) in one hierarchy.
>> >
>> > Yes, but you may still want to distinguish (because, for example, hard
>> > linking doesn't work across filesystems, and mv is not atomic then).
>> 
>> Why not use os.stat?
>
> Each os.stat call gives you information about one file (or directory);
> it may be simpler and faster to get the information "in bulk" once and
> for all.

Depends on what you want to do. Offen you need informations like file size,
permissions or owner in any case.


For things like creating hardlinks it may be the best to just try it and
catch the exception.


>> > Running a df command is a good simple way to find out what drives are
>> > mounted to what mountpoints -- the mount command is an alternative, but
>> > its output may be slightly harder to parse than df's.
>> 
>> Executing df may be expensive if it needs to read some slow file systems.
>
> That's what the -n flag is for, if you're worried about that (although
> I believe it may not be available on all systems) -- 

GNU df doesn't have it.
Some of the various version of df at Solaris don't have it too. And they
have at least two different output formats.


> executing mount
> is the alternative (just putting up with some parsing difficulties
> depending, e.g., on what automounters may be doing).

I would prefer mount as ir is cheaper than df

>> Reading /etc/mtab is not difficult and much faster
>
> $ cat /etc/mtab
> cat: /etc/mtab: No such file or directory

Ok, wasn't that clever. On Solaris it's /etc/mntab, I don't have any BSD around

> Oops!  BSD systems don't have /etc/mtab... so, if you choose to get your
> info by reading it, you've just needlessly destroyed your program's
> compatibility with a large portion of the Unix-y universe.  popen a
> mount or df, and information will be easier to extract portably.

On the other hand I know of at least two boxes (no, not mine) where
ordinary users don't have permission to exec mount.





   Florian
-- 
Emacs doesn't crash!  It contains very little C, so there's very
little reason to have it crash. [Pascal Bourguignon in gnu.emacs.help]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: detecting drives for windows and linux

2006-03-27 Thread Alex Martelli
Florian Diesch <[EMAIL PROTECTED]> wrote:
   ...
> >> are and want to do it anyway?) Linux puts the whole file system 
> >> (including mounted iPods, ISOs and NTFS drives) in one hierarchy.
> >
> > Yes, but you may still want to distinguish (because, for example, hard
> > linking doesn't work across filesystems, and mv is not atomic then).
> 
> Why not use os.stat?

Each os.stat call gives you information about one file (or directory);
it may be simpler and faster to get the information "in bulk" once and
for all.

> > Running a df command is a good simple way to find out what drives are
> > mounted to what mountpoints -- the mount command is an alternative, but
> > its output may be slightly harder to parse than df's.
> 
> Executing df may be expensive if it needs to read some slow file systems.

That's what the -n flag is for, if you're worried about that (although I
believe it may not be available on all systems) -- executing mount is
the alternative (just putting up with some parsing difficulties
depending, e.g., on what automounters may be doing).

> Reading /etc/mtab is not difficult and much faster

$ cat /etc/mtab
cat: /etc/mtab: No such file or directory

Oops!  BSD systems don't have /etc/mtab... so, if you choose to get your
info by reading it, you've just needlessly destroyed your program's
compatibility with a large portion of the Unix-y universe.  popen a
mount or df, and information will be easier to extract portably.


Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: detecting drives for windows and linux

2006-03-27 Thread Florian Diesch
[EMAIL PROTECTED] (Alex Martelli) wrote:

> Max <[EMAIL PROTECTED]> wrote:
>
>> BWill wrote:
>> 
>> > oh, I wasn't expecting a single solution for both platforms, just some
>> > good solutions
>> > 
>> > thanks
>> 
>> Are you aware that this idea is somewhat foreign to Linux? (Maybe you
>> are and want to do it anyway?) Linux puts the whole file system 
>> (including mounted iPods, ISOs and NTFS drives) in one hierarchy.
>
> Yes, but you may still want to distinguish (because, for example, hard
> linking doesn't work across filesystems, and mv is not atomic then).

Why not use os.stat?


> Running a df command is a good simple way to find out what drives are
> mounted to what mountpoints -- the mount command is an alternative, but
> its output may be slightly harder to parse than df's.

Executing df may be expensive if it needs to read some slow file systems. 
Reading /etc/mtab is not difficult and much faster.


   Florian
-- 
Das toitsche Usenet ist die Wiederaufführung des Dreißigjährigen Krieges mit
den Mitteln einer Talkshow.  [Alexander Bartolich in dcpu]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: detecting drives for windows and linux

2006-03-26 Thread Alex Martelli
Max <[EMAIL PROTECTED]> wrote:

> BWill wrote:
> 
> > oh, I wasn't expecting a single solution for both platforms, just some
> > good solutions
> > 
> > thanks
> 
> Are you aware that this idea is somewhat foreign to Linux? (Maybe you
> are and want to do it anyway?) Linux puts the whole file system 
> (including mounted iPods, ISOs and NTFS drives) in one hierarchy.

Yes, but you may still want to distinguish (because, for example, hard
linking doesn't work across filesystems, and mv is not atomic then).

Running a df command is a good simple way to find out what drives are
mounted to what mountpoints -- the mount command is an alternative, but
its output may be slightly harder to parse than df's.


Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: detecting drives for windows and linux

2006-03-26 Thread Max
BWill wrote:

> oh, I wasn't expecting a single solution for both platforms, just some 
> good solutions
> 
> thanks

Are you aware that this idea is somewhat foreign to Linux? (Maybe you 
are and want to do it anyway?) Linux puts the whole file system 
(including mounted iPods, ISOs and NTFS drives) in one hierarchy.

--Max
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: detecting drives for windows and linux

2006-03-26 Thread Fulvio

Alle 03:17, domenica 26 marzo 2006, BWill ha scritto:
> Hi, I'm writing a file browser, but I'm not sure how I could go about
> detecting the drives available

I was just asking a similar question some days back. I'm planning to try a file catalogger.
I just remember something about Win32API, but I didn't find anything on the linux side.
Frankly I got some curious info that concerns 'Bacula', disk backup. And a part of it is use to browse and catalog file.

I think we should read some line of code on that program.

F

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: detecting drives for windows and linux

2006-03-25 Thread BWill
Tim Golden wrote:
> BWill wrote:
>> Hi, I'm writing a file browser, but I'm not sure how I could go about
>> detecting the drives available on windows and linux systems (preferably
>> using the standard modules if possible). I guess I could just try to
>> list root on each letter of the alphabet for windows and see if it
>> works, but that seems crude; besides, I want to know what kind of drive
>> each drive/partition is (i.e. is it local and is it a harddrive or
>> optical drive).
> 
> I'm not aware of any cross-platform way of doing this.
> On Windows you have a few options, but I'd go down
> the WMI route; it just makes life easier for doing this
> kind of thing. You might want to start by adapting this
> example:
> 
> http://tgolden.sc.sabren.com/python/wmi_cookbook.html#percentage_free
> 
> by removing the restriction to fixed disk (DriveType=3)
> 
> TJG
> 

oh, I wasn't expecting a single solution for both platforms, just some 
good solutions

thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: detecting drives for windows and linux

2006-03-25 Thread Tim Golden
BWill wrote:
> Hi, I'm writing a file browser, but I'm not sure how I could go about
> detecting the drives available on windows and linux systems (preferably
> using the standard modules if possible). I guess I could just try to
> list root on each letter of the alphabet for windows and see if it
> works, but that seems crude; besides, I want to know what kind of drive
> each drive/partition is (i.e. is it local and is it a harddrive or
> optical drive).

I'm not aware of any cross-platform way of doing this.
On Windows you have a few options, but I'd go down
the WMI route; it just makes life easier for doing this
kind of thing. You might want to start by adapting this
example:

http://tgolden.sc.sabren.com/python/wmi_cookbook.html#percentage_free

by removing the restriction to fixed disk (DriveType=3)

TJG

-- 
http://mail.python.org/mailman/listinfo/python-list


detecting drives for windows and linux

2006-03-25 Thread BWill
Hi, I'm writing a file browser, but I'm not sure how I could go about 
detecting the drives available on windows and linux systems (preferably 
using the standard modules if possible). I guess I could just try to 
list root on each letter of the alphabet for windows and see if it 
works, but that seems crude; besides, I want to know what kind of drive 
each drive/partition is (i.e. is it local and is it a harddrive or 
optical drive).

Thanks,

Brian
-- 
http://mail.python.org/mailman/listinfo/python-list