import re


def parse_version_directory(dirname):
    """Get version number from version directory name."""
    m = re.match(r'''v(\d{1,5})$''', dirname)
    if not m:
        raise Exception("Bad version directory name: %s" % (dirname))
    v = int(m.group(1))
    if v == 0:
        raise Exception("Bad version directory name: %s, v0 no allowed" % (dirname))
    return v