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

listpage = urllib2.urlopen("http://www.mpich.org/static/downloads/").read()
versions = re.findall(r'''href=["']([0-9]+\.[0-9]+\.[0-9]+)/["']''', listpage)
versions.sort(key = lambda x: map(int, x.split('.')))
version = versions[-1]

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

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