#!/usr/bin/env python
import urllib2, re, glob, shutil

dlpage = urllib2.urlopen("http://matplotlib.org/downloads.html")
versions = re.findall(r'''matplotlib-([0-9.]+)\.tar\.gz''', dlpage.read())

versions.sort(key=lambda x: map(int, x.split(".")) )
version = versions[-1]

newBuildFile = "matplotlib-" + version + ".build"
buildFile, = glob.glob("matplotlib-*.build")

if buildFile != newBuildFile:
    print "mv {old} {new}".format(old=buildFile, new=newBuildFile)
    shutil.move(buildFile, newBuildFile)
