| 2023 | } |
| 2024 | |
| 2025 | PyObject* ApplicationPy::sLoadFile(PyObject* /*self*/, PyObject* args) |
| 2026 | { |
| 2027 | const char* path = ""; |
| 2028 | const char* mod = ""; |
| 2029 | if (!PyArg_ParseTuple(args, "s|s", &path, &mod)) { |
| 2030 | return nullptr; |
| 2031 | } |
| 2032 | |
| 2033 | PY_TRY |
| 2034 | { |
| 2035 | Base::FileInfo fi(path); |
| 2036 | if (!fi.isFile() || !fi.exists()) { |
| 2037 | PyErr_Format(PyExc_IOError, "File %s doesn't exist.", path); |
| 2038 | return nullptr; |
| 2039 | } |
| 2040 | |
| 2041 | std::string module = mod; |
| 2042 | if (module.empty()) { |
| 2043 | std::string ext = fi.extension(); |
| 2044 | std::vector<std::string> modules = App::GetApplication().getImportModules(ext.c_str()); |
| 2045 | if (modules.empty()) { |
| 2046 | PyErr_Format(PyExc_IOError, "Filetype %s is not supported.", ext.c_str()); |
| 2047 | return nullptr; |
| 2048 | } |
| 2049 | |
| 2050 | module = modules.front(); |
| 2051 | } |
| 2052 | |
| 2053 | Application::Instance->open(path, module.c_str()); |
| 2054 | |
| 2055 | Py_Return; |
| 2056 | } |
| 2057 | PY_CATCH |
| 2058 | } |
| 2059 | |