@dir_app.route('/results/')
def get_result_dir_info():
    ''' Retrieve results directory information.

    The backend's results directory is determined by WORK_DIR. All the 
    directories there are formatted and returned as results. If WORK_DIR does
    not exist, an empty listing will be returned (shown as a 'failure below').

    **Successful JSON Response**

    .. sourcecode:: javascript

        {
            'listing': [
                '/bar',
                '/foo'
            ]
        }

    **Failure JSON Response**

    .. sourcecode:: javascript

        {
            'listing': []
        }
    '''
    dir_info = []

    try:
        dir_listing = os.listdir(WORK_DIR)
    except __HOLE__:
        # The WORK_DIR hasn't been created, so we don't have any results!
        pass
    else:
        for obj in dir_listing:
            # Ignore hidden files
            if obj[0] == '.': continue

            # Create a path to the listed object and strip the work dir leader.
            # If the result isn't a directory, ignore it.
            obj = os.path.join(WORK_DIR, obj)
            if not os.path.isdir(obj): continue
            dir_info.append(obj.replace(WORK_DIR, ''))

        sorted(dir_info, key=lambda s: s.lower())

    if request.query.callback:
        return "%s(%s)" % (request.query.callback, {'listing': dir_info})
    return {'listing': dir_info}
dataset/ETHPy150Open apache/climate/ocw-ui/backend/directory_helpers.py/get_result_dir_info