Changeset 250:8f2584d3fd20 for uwsgi.c

Show
Ignore:
Timestamp:
03/04/10 16:54:26 (5 months ago)
Author:
roberto@…
Branch:
default
Message:

wsgi file support

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • uwsgi.c

    r249 r250  
    607607                {"proxy-node", required_argument, 0, LONG_ARGS_PROXY_NODE}, 
    608608                {"proxy-max-connections", required_argument, 0, LONG_ARGS_PROXY_MAX_CONNECTIONS}, 
     609                {"wsgi-file", required_argument, 0, LONG_ARGS_WSGI_FILE}, 
    609610                {0, 0, 0, 0} 
    610611        }; 
     
    11731174                uwsgi_wsgi_config (); 
    11741175        } 
     1176        else if (uwsgi.wsgi_file != NULL) { 
     1177                uwsgi_wsgi_file_config(); 
     1178        } 
    11751179#ifdef UWSGI_XML 
    11761180        else if (uwsgi.xml_config != NULL) { 
     
    18661870                Py_INCREF (my_callable); 
    18671871        } 
    1868  
     1872        else if (uwsgi.wsgi_file) { 
     1873                wi->wsgi_callable = my_callable; 
     1874                Py_INCREF (my_callable); 
     1875        } 
    18691876        else { 
    18701877 
     
    21142121#endif 
    21152122 
     2123/* trying to emulate Graham's mod_wsgi, this will allows easy and fast migrations */ 
     2124void 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 
    21162189void uwsgi_wsgi_config () { 
    21172190 
     
    24602533                        uwsgi.binary_path = optarg; 
    24612534                        break; 
     2535                case LONG_ARGS_WSGI_FILE: 
     2536                        uwsgi.single_interpreter = 1; 
     2537                        uwsgi.wsgi_file = optarg; 
     2538                        break; 
    24622539#ifdef UWSGI_PROXY 
    24632540                case LONG_ARGS_PROXY_NODE: