from .browser_engine import BrowserEngine
import os


def get_engine(file, url):
    def inner(f):

        def wapper(*args, **kwargs):
            try:
                if file:
                    log_name = os.path.split(file)[-1].split(".")[0]
                    engine = BrowserEngine(log_name, url)
                else:
                    engine = BrowserEngine(url=url)
                ret = f(engine, *args, **kwargs)
                if engine.driver: engine.driver.quit()
                if engine: del engine
                return ret
            except Exception as e:
                print(e)

        return wapper

    return inner
