@home.before_app_first_request
def fixup_upload_management():
    return
    USER_DATA_DIR = 'user-data'
    to_delete = set()
    for user_folder_name in os.listdir(USER_DATA_DIR):
        if ((user_folder_name == 'uploads') or (user_folder_name == 'zip_temp')):
            continue
        if os.path.isdir(os.path.join(USER_DATA_DIR, user_folder_name)):
            user_data.clear_data_table_upload_filenames(user_folder_name)
            full_path = os.path.join(USER_DATA_DIR, user_folder_name)
            uploads_path = os.path.join(full_path, 'uploads')
            for file in os.listdir(full_path):
                full_file = os.path.join(full_path, file)
                if (os.path.isfile(full_file) and full_file.lower().endswith('.json') and (file != '__user_properties__.json')):
                    if (file == 'user_properties.json'):
                        to_delete.add(os.path.join(full_path, 'user_properties.json'))
                        continue
                    document_name = file[:(- 5)]
                    subdir_name = os.path.join(uploads_path, document_name)
                    try:
                        os.mkdir(subdir_name)
                    except OSError:
                        pass
                    with open(full_file, 'r') as json_file:
                        json_obj = json.load(json_file)
                        eml_node = mp_io.from_json(json_obj)
                    data_table_nodes = []
                    eml_node.find_all_descendants(names.DATATABLE, data_table_nodes)
                    for data_table_node in data_table_nodes:
                        object_name_node = data_table_node.find_descendant(names.OBJECTNAME)
                        if object_name_node:
                            object_name = object_name_node.content
                            object_path = os.path.join(uploads_path, object_name)
                            target_path = os.path.join(subdir_name, object_name)
                            if os.path.isfile(object_path):
                                to_delete.add(object_path)
                                copyfile(object_path, target_path)
                    other_entity_nodes = []
                    eml_node.find_all_descendants(names.OTHERENTITY, other_entity_nodes)
                    for other_entity_node in other_entity_nodes:
                        object_name_node = other_entity_node.find_descendant(names.OBJECTNAME)
                        if object_name_node:
                            object_name = object_name_node.content
                            object_path = os.path.join(uploads_path, object_name)
                            if os.path.isfile(object_path):
                                to_delete.add(object_path)
                                copyfile(object_path, os.path.join(subdir_name, object_name))
                    for path in os.listdir(subdir_name):
                        path = os.path.join(subdir_name, path)
                        if (os.path.isfile(path) and path.endswith('ezeml_tmp')):
                            to_delete.add(path)
            for file in os.listdir(uploads_path):
                uploads_folder = os.path.join(uploads_path, file)
                if os.path.isdir(uploads_folder):
                    for uploaded_file in os.listdir(uploads_folder):
                        user_data.add_data_table_upload_filename(uploaded_file, user_folder_name, file)
            for path in os.listdir(full_path):
                path = os.path.join(full_path, path)
                if (os.path.isfile(path) and path.endswith('ezeml_tmp')):
                    to_delete.add(path)
    for file in to_delete:
        os.remove(file)
@home.before_app_first_request
def fixup_upload_management():
    return
    USER_DATA_DIR = 'user-data'
    to_delete = set()
    for user_folder_name in os.listdir(USER_DATA_DIR):
        if ((user_folder_name == 'uploads') or (user_folder_name == 'zip_temp')):
            continue
        if os.path.isdir(os.path.join(USER_DATA_DIR, user_folder_name)):
            user_data.clear_data_table_upload_filenames(user_folder_name)
            full_path = os.path.join(USER_DATA_DIR, user_folder_name)
            uploads_path = os.path.join(full_path, 'uploads')
            for file in os.listdir(full_path):
                full_file = os.path.join(full_path, file)
                if (os.path.isfile(full_file) and full_file.lower().endswith('.json') and (file != '__user_properties__.json')):
                    if (file == 'user_properties.json'):
                        to_delete.add(os.path.join(full_path, 'user_properties.json'))
                        continue
                    document_name = file[:(- 5)]
                    subdir_name = os.path.join(uploads_path, document_name)
                    try:
                        os.mkdir(subdir_name)
                    except OSError:
                        pass
                    with open(full_file, 'r') as json_file:
                        json_obj = json.load(json_file)
                        eml_node = mp_io.from_json(json_obj)
                    data_table_nodes = []
                    eml_node.find_all_descendants(names.DATATABLE, data_table_nodes)
                    for data_table_node in data_table_nodes:
                        object_name_node = data_table_node.find_descendant(names.OBJECTNAME)
                        if object_name_node:
                            object_name = object_name_node.content
                            object_path = os.path.join(uploads_path, object_name)
                            target_path = os.path.join(subdir_name, object_name)
                            if os.path.isfile(object_path):
                                to_delete.add(object_path)
                                copyfile(object_path, target_path)
                    other_entity_nodes = []
                    eml_node.find_all_descendants(names.OTHERENTITY, other_entity_nodes)
                    for other_entity_node in other_entity_nodes:
                        object_name_node = other_entity_node.find_descendant(names.OBJECTNAME)
                        if object_name_node:
                            object_name = object_name_node.content
                            object_path = os.path.join(uploads_path, object_name)
                            if os.path.isfile(object_path):
                                to_delete.add(object_path)
                                copyfile(object_path, os.path.join(subdir_name, object_name))
                    for path in os.listdir(subdir_name):
                        path = os.path.join(subdir_name, path)
                        if (os.path.isfile(path) and path.endswith('ezeml_tmp')):
                            to_delete.add(path)
            for file in os.listdir(uploads_path):
                uploads_folder = os.path.join(uploads_path, file)
                if os.path.isdir(uploads_folder):
                    for uploaded_file in os.listdir(uploads_folder):
                        user_data.add_data_table_upload_filename(uploaded_file, user_folder_name, file)
            for path in os.listdir(full_path):
                path = os.path.join(full_path, path)
                if (os.path.isfile(path) and path.endswith('ezeml_tmp')):
                    to_delete.add(path)
    for file in to_delete:
        os.remove(file)