/* * Load the Python DLL, and get all of the necessary entry points * Windows only (dynamic load) */ int loadPython() { #ifdef WIN32 HINSTANCE dll; char dllpath[_MAX_PATH + 1]; /* Determine the path */ sprintf(dllpath, "%spython%02d.dll", f_homepathraw, ntohl(f_cookie.pyvers)); /* Load the DLL */ dll = LoadLibraryEx(dllpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); if (dll) { VS(dllpath); VS("\n"); } else { sprintf(dllpath, "%spython%02d.dll", f_temppathraw, ntohl(f_cookie.pyvers)); dll = LoadLibraryEx(dllpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ); if (dll) { VS(dllpath); VS("\n"); } } if (dll == 0) { FATALERROR("Error loading Python DLL: "); FATALERROR(dllpath); FATALERROR("\n"); return -1; } mapNames(dll); #endif return 0; }
/* * use this from a dll instead of loadPython() * it will attach to an existing pythonXX.dll, * or load one if needed. */ int attachPython(int *loadedNew) { HMODULE dll; char nm[_MAX_PATH + 1]; /* Get python's name */ sprintf(nm, "python%02d.dll", ntohl(f_cookie.pyvers)); /* See if it's loaded */ dll = GetModuleHandle(nm); if (dll == 0) { *loadedNew = 1; return loadPython(); } mapNames(dll); *loadedNew = 0; return 0; }
/* * use this from a dll instead of loadPython() * it will attach to an existing pythonXX.dll, * or load one if needed. */ int attachPython(ARCHIVE_STATUS *status, int *loadedNew) { #ifdef WIN32 HMODULE dll; char nm[_MAX_PATH + 1]; int pyvers = ntohl(status->cookie.pyvers); /* Get python's name */ sprintf(nm, "python%02d.dll", pyvers); /* See if it's loaded */ dll = GetModuleHandleA(nm); if (dll == 0) { *loadedNew = 1; return loadPython(status); } mapNames(dll, pyvers); *loadedNew = 0; #endif return 0; }
/* * Load the Python DLL, and get all of the necessary entry points */ int loadPython(ARCHIVE_STATUS *status) { HINSTANCE dll; char dllpath[_MAX_PATH + 1]; int pyvers = ntohl(status->cookie.pyvers); #ifdef WIN32 /* Determine the path */ sprintf(dllpath, "%spython%02d.dll", status->homepathraw, pyvers); /* Load the DLL */ dll = LoadLibraryExA(dllpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); if (dll) { VS("%s\n", dllpath); } else { sprintf(dllpath, "%spython%02d.dll", status->temppathraw, pyvers); dll = LoadLibraryExA(dllpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ); if (dll) { VS("%s\n", dllpath); } } if (dll == 0) { FATALERROR("Error loading Python DLL: %s (error code %d)\n", dllpath, GetLastError()); return -1; } mapNames(dll, pyvers); #else uint32_t pyvers_major; uint32_t pyvers_minor; int dlopenMode = RTLD_NOW | RTLD_GLOBAL; pyvers_major = pyvers / 10; pyvers_minor = pyvers % 10; /* Determine the path */ #ifdef __APPLE__ /* Try to load python library both from temppath and homepath */ /* First try with plain "Python" lib, then "Python" lib and finally "libpython*.dylib". */ #define pylibTemplate "%sPython" #define dotPylibTemplate "%s.Python" #define dyPylibTemplate "%slibpython%01d.%01d.dylib" if ( checkFile(dllpath, pylibTemplate, status->temppath) != 0 && checkFile(dllpath, pylibTemplate, status->homepath) != 0 && checkFile(dllpath, dotPylibTemplate, status->temppath) != 0 && checkFile(dllpath, dotPylibTemplate, status->homepath) != 0 /* Python might be compiled as a .dylib (using --enable-shared) so lets try that one */ && checkFile(dllpath, dyPylibTemplate, status->temppath, pyvers_major, pyvers_minor) != 0 && checkFile(dllpath, dyPylibTemplate, status->homepath, pyvers_major, pyvers_minor) != 0 ) { FATALERROR("Python library not found.\n"); return -1; } #elif AIX /* On AIX 'ar' archives are used for both static and shared object. * To load a shared object from a library, it should be loaded like this: * dlopen("libpython2.6.a(libpython2.6.so)", RTLD_MEMBER) */ /* Search for Python library archive: e.g. 'libpython2.6.a' */ #define pylibTemplate "%slibpython%01d.%01d.a" if ( checkFile(dllpath, pylibTemplate, status->temppath, pyvers_major, pyvers_minor) != 0 && checkFile(dllpath, pylibTemplate, status->homepath, pyvers_major, pyvers_minor) != 0) { FATALERROR("Python library not found.\n"); return -1; } /* Append the shared object member to the library path * to make it look like this: * libpython2.6.a(libpython2.6.so) */ sprintf(dllpath + strlen(dllpath), "(libpython%01d.%01d.so)", pyvers_major, pyvers_minor); /* Append the RTLD_MEMBER to the open mode for 'dlopen()' * in order to load shared object member from library. */ dlopenMode |= RTLD_MEMBER; #elif __CYGWIN__ #define pylibTemplate "%slibpython%01d.%01d.dll" printf( "status->temppath=%s\n",status->temppath); printf( "status->homepath=%s\n",status->homepath); if ( checkFile(dllpath, pylibTemplate, status->temppath, pyvers_major, pyvers_minor) != 0 && checkFile(dllpath, pylibTemplate, status->homepath, pyvers_major, pyvers_minor) != 0) { FATALERROR("Python library not found.\n"); return -1; } #else #define pylibTemplate "%slibpython%01d.%01d.so.1.0" if ( checkFile(dllpath, pylibTemplate, status->temppath, pyvers_major, pyvers_minor) != 0 && checkFile(dllpath, pylibTemplate, status->homepath, pyvers_major, pyvers_minor) != 0) { FATALERROR("Python library not found.\n"); return -1; } #endif /* Load the DLL */ dll = dlopen(dllpath, dlopenMode); if (dll) { VS("%s\n", dllpath); } if (dll == 0) { FATALERROR("Error loading Python lib '%s': %s\n", dllpath, dlerror()); return -1; } mapNames(dll, pyvers); #endif return 0; }
/* * Load the Python DLL, and get all of the necessary entry points */ int loadPython() { HINSTANCE dll; char dllpath[_MAX_PATH + 1]; #ifdef WIN32 /* Determine the path */ sprintf(dllpath, "%spython%02d.dll", f_homepathraw, ntohl(f_cookie.pyvers)); /* Load the DLL */ dll = LoadLibraryExA(dllpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); if (dll) { VS("%s\n", dllpath); } else { sprintf(dllpath, "%spython%02d.dll", f_temppathraw, ntohl(f_cookie.pyvers)); dll = LoadLibraryExA(dllpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ); if (dll) { VS("%s\n", dllpath); } } if (dll == 0) { FATALERROR("Error loading Python DLL: %s (error code %d)\n", dllpath, GetLastError()); return -1; } mapNames(dll); #else /* Determine the path */ #ifdef __APPLE__ struct stat sbuf; sprintf(dllpath, "%sPython", f_workpath ? f_workpath : f_homepath); /* Workaround for virtualenv: it renames the Python framework. */ /* A proper solution would be to let Build.py found out the correct * name and embed it in the PKG as metadata. */ if (stat(dllpath, &sbuf) < 0) sprintf(dllpath, "%s.Python", f_workpath ? f_workpath : f_homepath); #else sprintf(dllpath, "%slibpython%01d.%01d.so.1.0", f_workpath ? f_workpath : f_homepath, ntohl(f_cookie.pyvers) / 10, ntohl(f_cookie.pyvers) % 10); #endif /* Load the DLL */ dll = dlopen(dllpath, RTLD_NOW|RTLD_GLOBAL); if (dll) { VS("%s\n", dllpath); } if (dll == 0) { FATALERROR("Error loading Python lib '%s': %s\n", dllpath, dlerror()); return -1; } mapNames(dll); #endif return 0; }
/* * Load the Python DLL, and get all of the necessary entry points */ int loadPython(ARCHIVE_STATUS *status) { dylib_t dll; char dllpath[PATH_MAX + 1]; char dllname[64]; int pyvers = ntohl(status->cookie.pyvers); #ifdef AIX /* * On AIX 'ar' archives are used for both static and shared object. * To load a shared object from a library, it should be loaded like this: * dlopen("libpython2.6.a(libpython2.6.so)", RTLD_MEMBER) */ uint32_t pyvers_major; uint32_t pyvers_minor; #endif strcpy(dllname, status->cookie.pylibname); if (status->temppath[0] != '\0') { /* Look for Python library in temppath - onefile mode. */ #ifdef WIN32 /* On Windows pass path containing back slashes. */ strcpy(dllpath, status->temppathraw); #else strcpy(dllpath, status->temppath); #endif } else { /* Look for Python library in homepath - onedir mode. */ /* Use temppath as home. This is for default onedir mode.*/ #ifdef WIN32 /* On Windows pass path containing back slashes. */ strcpy(dllpath, status->homepathraw); #else strcpy(dllpath, status->homepath); #endif } #ifdef AIX pyvers_major = pyvers / 10; pyvers_minor = pyvers % 10; /* Append the shared object member to the library path * to make it look like this: * libpython2.6.a(libpython2.6.so) */ sprintf(dllpath + strlen(dllpath), "(libpython%01d.%01d.so)", pyvers_major, pyvers_minor); #endif /* Append Python library name to dllpath. */ strcat(dllpath, dllname); VS("Python library: %s\n", dllpath); /* Load the DLL */ dll = pyi_dlopen(dllpath); /* Check success of loading Python library. */ if (dll == 0) { #ifdef WIN32 FATALERROR("Error loading Python DLL: %s (error code %d)\n", dllpath, GetLastError()); #else FATALERROR("Error loading Python lib '%s': %s\n", dllpath, dlerror()); #endif return -1; } mapNames(dll, pyvers); return 0; }
bool TableView::addFile(const QString& alias, openstudio::SqlFile sqlFile) { if (alias.isEmpty() || !sqlFile.connectionOpen()) return false; setSortingEnabled(false); detail::DataDictionaryTable ddTable = sqlFile.dataDictionary(); detail::DataDictionaryTable::iterator iter; for (iter=ddTable.begin();iter!=ddTable.end();++iter) { // skip runPeriod if (sqlFile.reportingFrequencyFromDB((*iter).reportingFrequency) && *(sqlFile.reportingFrequencyFromDB((*iter).reportingFrequency)) != ReportingFrequency::RunPeriod) { int row = addRow(); item(row, m_slHeaders.indexOf("Alias"))->setText(alias); item(row, m_slHeaders.indexOf("File"))->setText(openstudio::toQString(sqlFile.energyPlusSqliteFile())); item(row, m_slHeaders.indexOf("Environment Period"))->setText(openstudio::toQString((*iter).envPeriod)); item(row, m_slHeaders.indexOf("Reporting Frequency"))->setText(openstudio::toQString((*iter).reportingFrequency)); item(row, m_slHeaders.indexOf("Key Value"))->setText(openstudio::toQString((*iter).keyValue)); item(row, m_slHeaders.indexOf("Variable Name"))->setText(openstudio::toQString((*iter).name)); item(row, m_slHeaders.indexOf("File"))->setData(Qt::UserRole, RVD_TIMESERIES); } // end skip runPeriod } /* illuminance maps */ std::vector<std::string> mapNames(sqlFile.illuminanceMapNames()); std::vector<std::string>::iterator nameIter; for (nameIter=mapNames.begin(); nameIter!=mapNames.end(); ++nameIter) { // retrieve mapIndex for map name to retrieve environment period and zone name QString envPeriod = ""; QString keyValue = ""; boost::optional<int> mapIndex = sqlFile.illuminanceMapIndex(*nameIter); if (mapIndex) { boost::optional<std::string> strValue; boost::optional<int> intValue; std::stringstream s; s << "select Environment from daylightmaps where MapNumber=" << *mapIndex; strValue = sqlFile.execAndReturnFirstString(s.str()); if (strValue) envPeriod = openstudio::toQString(*strValue); s.str(""); s << "select Zone from daylightmaps where MapNumber=" << *mapIndex; intValue = sqlFile.execAndReturnFirstInt(s.str()); if (intValue) { s.str(""); s << "select ZoneName from zones where ZoneIndex=" << *intValue; strValue = sqlFile.execAndReturnFirstString(s.str()); if (strValue) keyValue = openstudio::toQString(*strValue); } } int row = addRow(); item(row, m_slHeaders.indexOf("Alias"))->setText(alias); item(row, m_slHeaders.indexOf("File"))->setText(openstudio::toQString(sqlFile.energyPlusSqliteFile())); item(row, m_slHeaders.indexOf("Environment Period"))->setText(envPeriod); // environment period /* update based on email from Dan 8/10/10 item(row, 3)->setText("Illuminance"); // reporting frequency item(row, 4)->setText(keyValue); // illuminance zone? item(row, 5)->setText(openstudio::toQString(*nameIter)); */ item(row, m_slHeaders.indexOf("Reporting Frequency"))->setText("Hourly"); // reporting frequency item(row, m_slHeaders.indexOf("Key Value"))->setText(keyValue); // illuminance zone item(row, m_slHeaders.indexOf("Variable Name"))->setText("Illuminance Map"); // Variable Name item(row, m_slHeaders.indexOf("File"))->setData(Qt::UserRole, RVD_ILLUMINANCEMAP); item(row, m_slHeaders.indexOf("Alias"))->setData(Qt::UserRole, openstudio::toQString(*nameIter)); // map name for retrieving from database } resizeColumnToContents(m_slHeaders.indexOf("Alias")); hideColumn(m_slHeaders.indexOf("File")); resizeColumnToContents(m_slHeaders.indexOf("Variable Name")); resizeColumnToContents(m_slHeaders.indexOf("Key Value")); resizeColumnToContents(m_slHeaders.indexOf("Reporting Frequency")); // resizeColumnToContents(5); setSortingEnabled(true); emit( fileAdded() ); return true; }