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

dlpage = urllib2.urlopen("http://eigen.tuxfamily.org/index.php?title=Main_Page")
versions = re.findall(r'''http://bitbucket.org/eigen/eigen/get/([0-9.]+).tar.bz2''', dlpage.read())

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

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

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