473,656 Members | 2,997 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

check disc space

Any ideas how to check for free disc space from Python. Platform
independent?
Thanks for any suggestion.
Thomas

Jul 18 '05 #1
6 4975
Thomas Schulz <th****@esands. com> wrote...
Any ideas how to check for free disc space from Python. Platform
independent?


Fortunately for you, my bad stomach will not allow me but a precious
hour of sleep this fine morning. :)

http://botanicus.net/dw/tmp/DiskFree.py

Tested: Win32, Linux, FreeBSD. I'm going to work in about 3 hours.
This _really_ sucks. :(
David.
Jul 18 '05 #2
Thanks for that.
I wonder if it would be worthwhile to have such a functionality
somewhere in the os module?

Thomas
David M. Wilson wrote:
Thomas Schulz <th****@esands. com> wrote...

Any ideas how to check for free disc space from Python. Platform
independent ?

Fortunately for you, my bad stomach will not allow me but a precious
hour of sleep this fine morning. :)

http://botanicus.net/dw/tmp/DiskFree.py

Tested: Win32, Linux, FreeBSD. I'm going to work in about 3 hours.
This _really_ sucks. :(
David.


Jul 18 '05 #3
"T. Schulz" wrote:
I wonder if it would be worthwhile to have such a functionality
somewhere in the os module?


two counter-arguments:

- the os module is traditionally used to provide access to posix-style
services provided by the OS (or the C library). in this case, os.statvfs
is such a function; calling out to "du" isn't

(shouldn't that be "df", btw? os.popen("du -k dir").split()[-5] sure
doesn't give the free diskspace on any platform I have access to...)

- what you mean with "free disc space" may depend on the platform
and the application; os.statvfs provides lots of additional information
that you can use on a Unix platform, and there are similar (but not
identical) metrics available on Windows.

(a third argument is that "free disc space" is a rather meaningless metric
on a modern operating system; it's hardly ever useful for anything except
"warning, warning, less than 5% free space" alerts. you really don't want
people to write "if os.getfreespace () >= len(buffer): f.write(buffer) " and
file a bug when write fails ;-)

</F>


Jul 18 '05 #4
"Fredrik Lundh" <fr*****@python ware.com> wrote...
- the os module is traditionally used to provide access to posix-style
services provided by the OS (or the C library). in this case, os.statvfs
is such a function; calling out to "du" isn't (shouldn't that be "df", btw? os.popen("du -k dir").split()[-5] sure
doesn't give the free diskspace on any platform I have access to...)
Um, yep. Fixed. *sheepish shrug*

(a third argument is that "free disc space" is a rather meaningless metric
on a modern operating system; it's hardly ever useful for anything except
"warning, warning, less than 5% free space" alerts.
Considering what I see python used for on a day-to-day basis, this
isn't "hardly ever useful". I have seen jobs fail as a direct result
of no disk space check. This should indeed be handled elsewhere and in
a different fashion, but sometimes the world just ain't the ideal
place you'd like to believe it is.

When you are performing 4gb deduplication runs on a cluster, and have
to wait a couple of days only to find out you don't have enough disk
space to write out the last 5 records of the result tables, I think
this silly little module can be justified.

And why not just use the POSIXy interface provided by os? Well, the
company I work for uses the same codebase for both Windows and Linux
clustering, which is a quite a feat. All support tools as such must
run under both operating systems too.

you really don't want
people to write "if os.getfreespace () >= len(buffer): f.write(buffer) " and
file a bug when write fails ;-)


Certainly not! :)

But "if estimated_space > int(free_space * 1.05): ..." might not be
such a bad thing when there is no other route to sanity available.

Thanks,
David.
Jul 18 '05 #5
Fredrik Lundh wrote:
(a third argument is that "free disc space" is a rather meaningless metric
on a modern operating system; it's hardly ever useful for anything except
"warning, warning, less than 5% free space" alerts. you really don't want
people to write "if os.getfreespace () >= len(buffer): f.write(buffer) " and
file a bug when write fails ;-)


Well, I think that for installation programs, downloaders and file
managers, for example, it would be useful.

yours,
Gerrit.

--
122. If any one give another silver, gold, or anything else to keep, he
shall show everything to some witness, draw up a contract, and then hand
it over for safe keeping.
-- 1780 BC, Hammurabi, Code of Law
--
Asperger's Syndrome - a personal approach:
http://people.nl.linux.org/~gerrit/english/

Jul 18 '05 #6

But "if estimated_space > int(free_space * 1.05): ..." might not be
such a bad thing when there is no other route to sanity available.


I support that.

In my current project, I know that I get 1GB of data during the next 15
minutes or so. I would like to make sure that there is enough space
available.

We develop on Linux but support Windows as well.
Certainly we get there if we use os.statvfs here and
win32api.GetDis kFree there. But I belive the question is quite common
and why shouldn't there be a os independent abstraction? Specially since
almost all current hardware uses some kind of file system to store things.

Thomas

Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2227
by: Alex Polite | last post by:
I need to put recursive data structures on disc and found out that cPickle doesn't like recursion. What are my options? alex -- Alex Polite http://polite.se
7
17541
by: YT | last post by:
Hello, I am this close | | to throwing myself out the window... I am trying to do a <UL><LI> series and i really really really want the disc size of the list to be nice and small. i've been doing now about 2.5 hours of testing and i can't get it to do anything consistent. On my system, the size of the disc is about the same size as the text height, but on a system on the other side of the room, the size of the disc is nice and small -...
1
1217
by: James | last post by:
After uppgrading from .NET v1.1 to .NET v2.0 we ca see massive usage of disc space(10 GB) in a subfolder in the following folder: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files IIS6 on Windows 2003 server web edition. This site contains a few hundred page and approximately 50 concurrrent users. The amount of data in the Temporary ASP.NET Files has increased with 2 GB within last 2 hours. We dont understand why? ...
5
1284
by: Herbert Lukas | last post by:
Hi, during the setup of german MSDN library VS 2006 juli (Disc 3619) the VS 2005 DVD was requested. I inserted both VS 2005 DVD German (Disc 3185) and English (Disc 3070) without success. Herbert
2
1818
vdraceil
by: vdraceil | last post by:
Hi friends,i just wanna know whether the presence of a disc in the drive can be detected by coding in vb6.0..if the disc is present i want to perform a set of actions, else i want to display 'insert disc please'..Experts kindly help
9
3092
by: DataSmash | last post by:
I simply want to capture the free disc space in a variable so that I can compare changes. I'm aware of a few commands like "df -h" or "du - k", but I can't figure out how to capture those values as a variable. I also looked at os.statvfs(), but that output doesn't seem to make any sense at all to me, knowing the size of the disc. Thanks for your help! R.D.
1
2116
by: =?Utf-8?B?T2FrZGVuZQ==?= | last post by:
I've just bought a new computer and want to load my Office software onto it. The software is on a disc, but the computer doesn't have a disc drive. I've tried loading the disc onto a flash drive and trying to set up from the flash drive but I get a message that the disc has been corrupted. Can anyone help me?
2
5036
DonRayner
by: DonRayner | last post by:
Hi all, I've been fighting with this problem for a couple of days and hopfully someone here has an answer. First off this is a comercial software package (JobBoss 5.02) using access 2000 runtime. the main mdb file is now at 1.33gb. The software is locked so I can't get at anything to make any changes. Problem is occuring when accounting goes to close the month of septmber which will also close our year end (no choice) The program will run...
1
1189
by: =?Utf-8?B?amlt?= | last post by:
Using the normal method my disc check and defragmenter will not work on c drive
0
8296
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8710
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1598
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.