| | 2123 | /* trying to emulate Graham's mod_wsgi, this will allows easy and fast migrations */ |
| | 2124 | void uwsgi_wsgi_file_config() { |
| | 2125 | |
| | 2126 | FILE *wsgifile ; |
| | 2127 | struct _node *wsgi_file_node = NULL; |
| | 2128 | PyObject *wsgi_compiled_node, *wsgi_file_module, *wsgi_file_dict; |
| | 2129 | PyObject *wsgi_file_callable ; |
| | 2130 | int ret; |
| | 2131 | |
| | 2132 | |
| | 2133 | wsgifile = fopen(uwsgi.wsgi_file, "r"); |
| | 2134 | if (!wsgifile) { |
| | 2135 | perror("fopen()"); |
| | 2136 | exit(1); |
| | 2137 | } |
| | 2138 | |
| | 2139 | wsgi_file_node = PyParser_SimpleParseFile(wsgifile, uwsgi.wsgi_file, Py_file_input); |
| | 2140 | if (!wsgi_file_node) { |
| | 2141 | PyErr_Print(); |
| | 2142 | fprintf(stderr,"failed to parse wsgi file %s\n", uwsgi.wsgi_file); |
| | 2143 | exit(1); |
| | 2144 | } |
| | 2145 | |
| | 2146 | fclose(wsgifile); |
| | 2147 | |
| | 2148 | wsgi_compiled_node = (PyObject *)PyNode_Compile(wsgi_file_node, uwsgi.wsgi_file); |
| | 2149 | |
| | 2150 | if (!wsgi_compiled_node) { |
| | 2151 | PyErr_Print(); |
| | 2152 | fprintf(stderr,"failed to compile wsgi file %s\n", uwsgi.wsgi_file); |
| | 2153 | exit(1); |
| | 2154 | } |
| | 2155 | |
| | 2156 | wsgi_file_module = PyImport_ExecCodeModule("uwsgi_wsgi_file", wsgi_compiled_node); |
| | 2157 | if (!wsgi_file_module) { |
| | 2158 | PyErr_Print(); |
| | 2159 | exit(1); |
| | 2160 | } |
| | 2161 | |
| | 2162 | Py_DECREF(wsgi_compiled_node); |
| | 2163 | |
| | 2164 | wsgi_file_dict = PyModule_GetDict(wsgi_file_module); |
| | 2165 | if (!wsgi_file_dict) { |
| | 2166 | PyErr_Print(); |
| | 2167 | exit(1); |
| | 2168 | } |
| | 2169 | |
| | 2170 | |
| | 2171 | wsgi_file_callable = PyDict_GetItemString(wsgi_file_dict, "application"); |
| | 2172 | if (!wsgi_file_callable) { |
| | 2173 | PyErr_Print(); |
| | 2174 | fprintf(stderr,"unable to find \"application\" callable in wsgi file %s\n", uwsgi.wsgi_file); |
| | 2175 | exit(1); |
| | 2176 | } |
| | 2177 | |
| | 2178 | if (!PyFunction_Check (wsgi_file_callable) && !PyCallable_Check (wsgi_file_callable)) { |
| | 2179 | fprintf(stderr,"\"application\" must be a callable object in wsgi file %s\n", uwsgi.wsgi_file); |
| | 2180 | exit(1); |
| | 2181 | } |
| | 2182 | |
| | 2183 | |
| | 2184 | ret = init_uwsgi_app (NULL, wsgi_file_callable); |
| | 2185 | |
| | 2186 | } |
| | 2187 | |
| | 2188 | |