[yast-commit] r41705 - in /trunk/python-bindings/src: Makefile.am YPython.cc YPython.h YPythonNamespace.cc
Author: juhliarik Date: Thu Nov 1 15:08:41 2007 New Revision: 41705 URL: http://svn.opensuse.org/viewcvs/yast?rev=41705&view=rev Log: solved problem with adding namespace Modified: trunk/python-bindings/src/Makefile.am trunk/python-bindings/src/YPython.cc trunk/python-bindings/src/YPython.h trunk/python-bindings/src/YPythonNamespace.cc Modified: trunk/python-bindings/src/Makefile.am URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/Makefile.am?r... ============================================================================== --- trunk/python-bindings/src/Makefile.am (original) +++ trunk/python-bindings/src/Makefile.am Thu Nov 1 15:08:41 2007 @@ -52,8 +52,6 @@ -lycp -ly2 \ -Xlinker --no-whole-archive \ -ly2util \ - -ly2 \ - -lYCPDeclarations \ -version-info 2:0 libYCP_la_LIBADD = libYCPTypes.la #libYCPDeclarations.la Modified: trunk/python-bindings/src/YPython.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPython.cc?re... ============================================================================== --- trunk/python-bindings/src/YPython.cc (original) +++ trunk/python-bindings/src/YPython.cc Thu Nov 1 15:08:41 2007 @@ -603,6 +603,23 @@ return Term_NewString(ycp_Term->asTerm()->name().c_str(), value); } +/** + * init namespace + * @param char * name of module + * @param char * name of function + * @return namespace of YCP + */ + +static Y2Namespace * getNs (const char * ns_name, const char * func_name) { + Import import(ns_name); // has a static cache + Y2Namespace *ns = import.nameSpace(); + if (ns == NULL) { + y2error ("... for a Python call of %s", func_name); + } else { + ns->initialize (); + } + return ns; +} /** * Convert Python Function to YCPCode. @@ -612,57 +629,28 @@ **/ YCPValue YPython::fromPythonFunToReference (PyObject* pyFun) { - - FunctionTypePtr sym_tp = new FunctionType(Type::Any); - PyObject *fun_code = PyFunction_GetCode(pyFun); - char *fun_name = PyString_AsString(((PyCodeObject *) fun_code)->co_name); + PyObject *fun_code = PyFunction_GetCode(pyFun); + string fun_name = PyString_AsString(((PyCodeObject *) fun_code)->co_name); string file_path = PyString_AsString(((PyCodeObject *) fun_code)->co_filename); - - //printf ("meno funckie %s\n", fun_name); - //printf ("meno suboru %s\n", file_path.c_str()); + //found last "/" in path size_t found = file_path.find_last_of("/"); //extract module name from path string module_name = file_path.substr(found+1); - - file_path = YCPPathSearch::find (YCPPathSearch::Module, module_name); - - if (file_path.empty()) - file_path = YCPPathSearch::find (YCPPathSearch::Include, module_name); - - if (file_path.empty()) - file_path = YCPPathSearch::find (YCPPathSearch::Client, module_name); - - if (file_path.empty()) { - y2error("Finding file where is function %s failed", fun_name); - return YCPNull(); - } - - //found last "/" in path - found = file_path.find_last_of("/"); - - string path = file_path.substr(0,found+1); - - setenv("PYTHONPATH", path.c_str(), 1); - - YPython::loadModule (file_path); - - //extract module name from path - module_name = file_path.substr(found+1); - //delete last 3 chars from module name ".py" - module_name.erase(module_name.size()-3); //delete ".py" + module_name.erase(module_name.size()-3); + - //found last "/" in path - Y2Namespace *ns = new YPythonNamespace (module_name); + Y2Namespace *ns = getNs (module_name.c_str(),fun_name.c_str()); if (ns) { - TableEntry *sym_te = ns->table ()->find (fun_name); + cout <<"ns bolo najdene!!! "<< endl; + TableEntry *sym_te = ns->table ()->find (fun_name.c_str()); if (sym_te == NULL) { - y2error ("No such symbol %s::%s", module_name.c_str(), fun_name); + y2error ("No such symbol %s::%s", module_name.c_str(), fun_name.c_str()); return YCPNull(); } SymbolEntryPtr sym_entry = sym_te->sentry(); @@ -670,7 +658,7 @@ return YCPReference(sym_entry); } else { - y2error("Creating namespace for function %s failed", fun_name); + y2error("Creating namespace for function %s failed", fun_name.c_str()); return YCPNull(); } Modified: trunk/python-bindings/src/YPython.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPython.h?rev... ============================================================================== --- trunk/python-bindings/src/YPython.h (original) +++ trunk/python-bindings/src/YPython.h Thu Nov 1 15:08:41 2007 @@ -70,14 +70,14 @@ **/ static YPython * yPython(); - /** + /** * Access the static _pMainDicts * **/ PyObject* pMainDicts(); - /** + /** * static _pMainDicts includes dictionaries of all imported python modules * **/ Modified: trunk/python-bindings/src/YPythonNamespace.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPythonNamesp... ============================================================================== --- trunk/python-bindings/src/YPythonNamespace.cc (original) +++ trunk/python-bindings/src/YPythonNamespace.cc Thu Nov 1 15:08:41 2007 @@ -154,7 +154,7 @@ PyObject * fun_code; //code of function //Declarations (using YPCDelcarations python module) - YCPDeclarations *decl = YCPDeclarations::instance(); + //YCPDeclarations *decl = YCPDeclarations::instance(); //YCPDeclarations *decl = new YCPDeclarations(); FunctionTypePtr sym_tp; @@ -192,7 +192,7 @@ fun_code = PyFunction_GetCode(pFunc); num = ((PyCodeObject *) fun_code)->co_argcount; - + /* if (decl->exists((PyFunctionObject *)pFunc) && decl->numParams((PyFunctionObject *)pFunc) == num){ @@ -203,14 +203,14 @@ for (int i=0; i < tmp; i++){ sym_tp->concat(list_of_types[i]); } - }else{ + }else{*/ sym_tp = new FunctionType(Type::Any); //y2milestone ("Number of parameters: %d", num); //add types and number of arguments into SymbolEntry table for (long j = 0; j < num; j++) { sym_tp->concat(Type::Any); } - } + //} //y2milestone ("Callable function %s", PyString_AsString(item)); // symbol entry for the function SymbolEntry *fun_se = new SymbolEntry ( -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
juhliarik@svn.opensuse.org