Skip to main content

Getting free diskspace in python

To calculate the amount of free disk space in Python, you can use the os.stafvfs() function. For some reason, I can never find the docs for os.statvfs() on the first or second try (it's in the "Files and Directories" section in the os module), and I never remember how it works, so I'm posting this as a note to myself, and maybe to help out anybody else wanting to do the same thing. A simple free space function can be written as:

import os

def freespace(p):
    Returns the number of free bytes on the drive that ``p`` is on
    s = os.statvfs(p)
    return s.f_bsize * s.f_bavail
I use the f_bavail attribute instead of f_bfree, since the latter includes blocks that are reserved for the the super-user's use. I'm not sure, however, on the distinction between f_bsize and f_frsize.

Lunar Eclipse

I stayed up a little past my bedtime last night to watch the eclipse, and to try and take some pictures. I've never had much luck taking pictures of the moon, but these ones turned out not too bad. What amazed me the most after looking through the pictures is just how fast the moon moves through the sky! I was using a 300mm lens on a D70 (equivalent to 450mm on a 35mm camera), and trying to bracket the exposure between shots. In just a few seconds between shots the moon moved a significant amount through the frame! Partial lunar eclipse Full lunar eclipse

Got my wireless working in Linux 2.6.24

I previously posted that I had problems getting my wireless device working with the new 2.6.24 kernel, running into a kernel oops in the process. In kernels prior to 2.6.24 I used the bcm43xx driver, and let NetworkManager handle connecting to wireless networks. I've since had some time to play around with 2.6.24 a bit more, and I'm happy to say wireless is working now! Here's what I did: - Install b43-fwcutter - Add b43 to /etc/modules - Add ', ATTR{type}="1"' after the MAC address to the line in /etc/udev/rules.d/z25_persistent-net.rules that contains your wireless device. This ensures that udev will assign the same interface name to the wireless device as it had before, which means you don't have to reconfigure your firewall!

Review: Orthodoxy by G.K. Chesterton

This post started out as a simple review of a book my parents bought for me for Christmas. However, since I've found my new hero as a result of reading this book (my wife now asks who I like more, Alton Brown, or Chesterton), I feel I have to say a little bit more... My parents bought me Orthodoxy by G.K. Chesterton for Christmas. I was a few weeks before I was able to get to it, but once I read the first few pages I couldn't put it down. I finished it just a few days later wondering how I could have never read anything by Chesterton before. He has a very unique style, very funny, with deep insights into human nature and society. He uses metaphor extremely effectively, and quite frequently to humorous effect throughout his works. His works have had an influence on other writers I love, including J.R.R. Tolkien and C.S. Lewis. Orthodoxy was written in 1908, 100 years ago now. And yet amazingly it's still relevant today. In the second paragraph of the book he describes how he has always wanted to write a book about an English yachtsman who miscalculated his course and arrives back at England meanwhile believing he has discovered a new island in the South Seas. "What could be more delightful than to have in the same few minutes all the fascinating terrors of going abroad combined with all the humane security of coming home again?" Later he explains why he mentions this: "But I have a peculiar reason for mentioning the man in a yacht, who discovered England. For I am that man in a yacht. I discovered England...I am the man who with the utmost daring discovered what had been discovered before." After this, I was most definitely hooked. Orthodoxy is a book that explains Chesterton's reasons for being a Catholic and at the same time is a defence against or a response to the relativism of his day.

All the will-worshippers, from Nietzsche to Mr. Davidson, are really quite empty of volition. They cannot will, they can hardly wish. And if any one wants a proof of this, it can be found quite easily. It can be found in this fact: that they always talk of will as something that expands and breaks out. But it is quite the opposite. Every act of will is an act of self-limitation. To desire action is to desire limitation. In that sense every act is an act of self-sacrifice. When you choose anything, you reject everything else. That objection, which men of this school used to make to the act of marriage, is really an objection to every act. Every act is an irrevocable selection and exclusion. Just as when you marry one woman you give up all the others, so when you take one course of action you give up all the other courses. If you become King of England, you give up the post of Beadle in Brompton. If you go to Rome, you sacrifice a rich suggestive life in Wimbledon. It is the existence of this negative or limiting side of will that makes most of the talk of the anarchic will-worshippers little better than nonsense. For instance, Mr. John Davidson tells us to have nothing to do with "Thou shalt not"; but it is surely obvious that "Thou shalt not" is only one of the necessary corollaries of "I will." "I will go to the Lord Mayor's Show, and thou shalt not stop me." Anarchism adjures us to be bold creative artists, and care for no laws or limits. But it is impossible to be an artist and not care for laws and limits. Art is limitation; the essence of every picture is the frame. If you draw a giraffe, you must draw him with a long neck. If, in your bold creative way, you hold yourself free to draw a giraffe with a short neck, you will really find that you are not free to draw a giraffe. The moment you step into the world of facts, you step into a world of limits. You can free things from alien or accidental laws, but not from the laws of their own nature. You may, if you like, free a tiger from his bars; but do not free him from his stripes. Do not free a camel of the burden of his hump: you may be freeing him from being a camel.
(emphasis mine here, and in following quotes; quoted from Project Gutenburg's eBook available online.) This newfound fascination with Chesterton lead me to the Internet. There's some good information on G. K. Chesterton's wikipedia page. I also found a great resource at the American Chesterton Society. They've got a bunch of Chesterton's essays and other works online. From his "Why I Am A Catholic" article,
The truth about the Catholic attitude towards heresy, or as some would say, towards liberty, can best be expressed perhaps by the metaphor of a map. The Catholic Church carries a sort of map of the mind which looks like the map of a maze, but which is in fact a guide to the maze. It has been compiled from knowledge which, even considered as human knowledge, is quite without any human parallel.
I like this quote in particular,
[Catholicism] does not, in the conventional phrase, accept the conclusions of science, for the simple reason that science has not concluded. To conclude is to shut up; and the man of science is not at all likely to shut up.
I find this especially relevant. Today there is the widespread belief that science is the sole source of knowledge. Anything that can be known, science can and eventually will discover. This is not to say that Chesterton (or myself) was down on science. It's just important to recognize the limits of what science can tell us. At some level all laws of science are just hypotheses or theories. The universe appears to obey these laws, but the jump between saying these laws are good models for explaining natural phenomena, and saying that natural phenomena occur exactly according to these laws is a jump across an abyss, with nothing connecting either side. This is central to much of the evolution vs. so-called "intelligent design" argument raging in the US right now. I also enjoyed his his essay on A Piece of Chalk,
One of the wise and awful truths which this brown-paper art reveals, is this, that white is a colour. It is not a mere absence of colour; it is a shining and affirmative thing, as fierce as red, as definite as black. When, so to speak, your pencil grows red-hot, it draws roses; when it grows white-hot, it draws stars. And one of the two or three defiant verities of the best religious morality, of real Christianity, for example, is exactly this same thing; the chief assertion of religious morality is that white is a colour. Virtue is not the absence of vices or the avoidance of moral dangers; virtue is a vivid and separate thing, like pain or a particular smell. Mercy does not mean not being cruel, or sparing people revenge or punishment; it means a plain and positive thing like the sun, which one has either seen or not seen.
I can't wait to get my hands on another Chesterton book!

Stephen Colbert defines Hell

And he gives a great definition too! It could have been taken straight from the Catechism. Follow the jump on over to the American Papist who has a YouTube clip of The Colbert Report from Monday night. I saw this on TV and was hoping it would show up on YouTube...Stephen Colbert certainly knows his faith...or pretends to at least. It's hard to tell sometimes if he's serious or not.

Being pro-life in Canada

Jen, over at "Et tu?", has written another moving post, this time about her conversion from being pro-choice to being pro-life. Before becoming Catholic, I'm not sure what I would have said with regards to the abortion debate, I didn't give it much thought. I probably would have said something along the lines of, "it's not desirable, but ok in extreme cases." After my conversion to Catholicism however, things couldn't be more clear. Human life begins at conception. Intentionally killing an innocent person is wrong. Therefore, killing a child in the womb is wrong. To me, it's that simple. And I really hope that one day everybody will understand it that way. Monday marked the 20th year since abortion was decriminalized in Canada. Depending on where you get your news, you may or may not have been aware of this. The three major newspapers here in the GTA had very different coverage that day (on their websites at least - I don't subscribe to any of them at the moment). The Toronto Star didn't have any mention if at all. The Globe and Mail had the pro-choice side covered well, but the pro-life side was not represented at all. The National Post seemed to have stories from both sides of the "debate". I put "debate" in quotes, since there's actually very little discussion about this issue in the public arena. Just last week the CBC reported that a pro-life advertisement was pulled from buses in St. John's. The ad read, "Nine months… the length of time an abortion is allowed in Canada. Abortion. Have we gone too far?" Pretty tame compared to some other pro-life messages out there. A message to spark debate, hopefully? Nope, not allowed, it's too "misleading". I agree with what Michael Coren says in his piece in the National Post, it's time for the debate to be resurrected.

Linux 2.6.24: First impressions - disappointed

The linux-kbuild-2.6.24 package was finally available in Debian today. (Small aside: why does it always take a few days after the release of the linux-image packages before the linux-kbuild package is available?) I need to use the proprietary nvidia drivers on my machines, so I have to wait for the kbuild backage before I can compile and install the nvidia driver for the new kernel. Anyway...after a short 'sudo m-a a-i -l 2.6.24-1-amd64 nvidia', I could reboot into the shiny new kernel! New kernels always seem faster, so I was getting excited after booting up. After logging in though, I couldn't connect to my wireless network. I had previously been using the bcm43xx driver, and looking through the changelog, I discovered it had been deprecated in favor of the new b43 / b43legacy drivers. Ok, no problem, just load the new module...wait for network-manager to pick it up...wait for it...wait...wait...Screw it. Edit /etc/network/interfaces, uncomment the stuff for the wireless device, and then 'ifup eth2'. Kernel oops. Well that sucks. Back to 2.6.23 I go. Incidentally, it's not just this oops in 2.6.24 that has me disappointed. Everything since 2.6.18 has been a bit risky. It used to be that upgrading a kernel within the same major.minor release was a relatively safe thing to do. I actively use two different kernels on my machine at home: - 2.6.21 since it supports the raw1394 interface that dvgrab requires to download video from my camcorder, but wireless is very flaky - 2.6.23 since wireless is more robust I still occasionally get lockups, forcing a hard reboot. Maybe this is my fault, I am running the proprietary nvidia driver, and I do use suspend to ram quite a bit, even though it thinks my hardware isn't supported. Maybe too much is changing too fast between kernel releases, not allowing userspace to keep up? Not sure, all I know is I'm doing much more rebooting in my Linux machine than I used to.

OpenWRT to the rescue!

Last night I thought I bricked my old Linksys WRT54G wireless router. I wanted to see if the latest firmware would resolve some problems I had with my wireless connection being dropped. After the firmware upgrade, I didn't have the dropped connection problem any more...I had a new problem - I couldn't connect to the router at all! No wireless access, no LAN access. The most I could do was ping it. I decided to check out OpenWRT to see if my hardware was supported, and how one was supposed to go about flashing new firmware onto the router. Luckily the TFTP method worked, and now I'm back up and running! Maybe it's my imagination, but it seems like the connection is faster now...

Eight hours is precious

Last night Thomas slept for a full eight hours for the first time! What an amazing feeling to have uninterrupted sleep again! This is a huge relief, much more so for Melissa than for me. She's been wonderful waking up for all the mid-night feedings and letting me sleep. Hopefully this is the start of many a full night's sleep to come!