# -*- coding: utf-8 -*-
"""
DESCRIPTION.
OBJ mesh importer.
Import files in blender scene.
DEPRECATED
"""
__version__ = "0.2"

import logging
import bpy
import os

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)


def import_obj(path):
    bpy.ops.object.select_all(action='DESELECT')

    path = path.replace('\\', '/')
    if os.path.isfile(path) and path.endswith('.obj'):
        return bpy.ops.wm.obj_import(filepath=path, global_scale=0.001, clamp_size=0, forward_axis='Y', up_axis='Z')
    if os.path.isdir(path):
        file_list = sorted(os.listdir(path))
        obj_list = [dict(name=item) for item in file_list if item.endswith('.obj')]
        return bpy.ops.wm.obj_import(directory=path, files=obj_list, global_scale=0.001, clamp_size=0, forward_axis='Y', up_axis='Z')

    return logger.info("Path must be a directory or *.obj file!")

