import os

def search_path (path, filename):
    
    """
    Linearly steps out of the given path until it finds the given filename.

    Returns None, or the path where the file exists
    """
    
    path = os.path.abspath(path)
    slices = path.split('/')
    print slices

    for i in xrange(len(slices), 0, -1):
        curpath = os.path.join('/'.join(slices[:i]), filename)
        print curpath
        if os.path.isfile(curpath):
            return os.path.split(curpath)[0]

    return None 

def delete_visible (path):
    
    """
    Utility function that only deletes non-hidden folders and files from
    the given path. It recursively explores folders, such that, if there
    are hidden files/folders inside a sub-folder then it will not delete
    the entire folder.

    Returns False if no hidden contents were found in the folder.
    Otherwise, returns true.
    """
    
    found_hidden = False
    for f in os.listdir(path):
        
        if f.startswith('.'):
            found_hidden = True
            continue

        fpath = os.path.join(path, f)
        if os.path.isdir(fpath):
            if not delete_visible(fpath):
                os.rmdir(fpath)
        elif os.path.isfile(fpath):
            os.remove(fpath)
    
    return found_hidden
