I'm dumb.

We needed to spider the entire Zenoss app for basic link checking. I was all for writing a simple Python script; I thought that would be easiest. As it turns out, wget has a -r option, which will recursively hit (and download) all the pages in the site. I had no idea. Don't know yet if it'll give us the error reporting we really need -- don't want to parse all those files individually -- but it's pretty cool to know it's there.

Read More...

Getting the dimensions of a video file in Python

There might be a better way to do this, but in a pinch, it works, as long as you have ffmpeg installed:

import subprocess, re
pattern = re.compile(r'Stream.*Video.*([0-9]{3,})x([0-9]{3,})')

def get_size(pathtovideo):
p = subprocess.Popen(['ffmpeg', '-i', pathtovideo],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
match = pattern.search(stderr)
if match:
x, y = map(int, match.groups()[0:1])
else:
x = y = 0
return x, y
Remember it's stderr, not stdout, because ffmpeg fails if you don't provide an output file. We don't really care, though, because it still prints out the stats of the infile.

Read More...

svn switch

I didn't learn about svn switch until recently. Turns out it's pretty handy! Basically, it's a subset of svn up that switches your working copy to a different URL. So if you're in the trunk, and you want to work in a branch but don't want to check out all the code fresh, you can just:
svn switch http://repo/branch/url .

And your working copy will update to the HEAD of the branch you specify (or, if you like, you can specify a revision with the usual -r option.

Example: Zenoss's build system does an svn checkout of the source trunk/branch/tag as an initial step. In order to save time (rpm builds took an hour), we trimmed down tasks that could be avoided; among other things, instead of checking out the code fresh each time, we would just svn update if the working copy already existed.

This worked great, until I noticed the other day that builds would occur against the trunk even if we were trying to build a release against a tag. The reason for this, of course, was that the working directory already existed, from our nightly rpm builds, so specifying a tag didn't matter. The build script would just svn up the trunk.

I made a quick change. svn up /my/working/copy became svn switch http://dev.zenoss.org/svn/path/to/branch /my/working/copy. If the working copy has the same URL as the one specified, it's a synonym of svn up; otherwise, we switch to the tag. Now we get the time-saving benefits of reusing already-checked-out code, while still building off of our branch of choice.

Read More...