Dumps a detailed report of the turicreate/sframe directory structure
    and files, along with the output of os.lstat for each.  This is useful
    for debugging purposes.

def dump_directory_structure(out = sys.stdout):
    """
    Dumps a detailed report of the turicreate/sframe directory structure
    and files, along with the output of os.lstat for each.  This is useful
    for debugging purposes.
    """

    "Dumping Installation Directory Structure for Debugging: "

    import sys, os
    from os.path import split, abspath, join
    from itertools import chain
    main_dir = split(abspath(sys.modules[__name__].__file__))[0]

    visited_files = []

    def on_error(err):
        visited_files.append( ("  ERROR", str(err)) )

    for path, dirs, files in os.walk(main_dir, onerror = on_error):
        for fn in chain(files, dirs):
            name = join(path, fn)
            try:
                visited_files.append( (name, repr(os.lstat(name))) )
            except:
                visited_files.append( (name, "ERROR calling os.lstat.") )

    def strip_name(n):
        if n[:len(main_dir)] == main_dir:
            return "<root>/" + n[len(main_dir):]
        else:
            return n

    out.write("\n".join( ("  %s: %s" % (strip_name(name), stats))
                     for name, stats in sorted(visited_files)))

    out.flush()