walk upwards from the current directory until we find this topfile

def getTopdir(topfile, start=None):
    """walk upwards from the current directory until we find this topfile"""
    if not start:
        start = os.getcwd()
    here = start
    toomany = 20
    while toomany > 0:
        if os.path.exists(os.path.join(here, topfile)):
            return here
        next = os.path.dirname(here)
        if next == here:
            break                       # we've hit the root
        here = next
        toomany -= 1
    output("Unable to find topfile '{}' anywhere "
           "from {} upwards".format(topfile, start))
    sys.exit(1)