2010-10-25 15:54:10 +08:00
|
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
2011-02-24 18:46:00 +08:00
|
|
|
|
#include <vector>
|
|
|
|
|
|
2010-10-25 15:54:10 +08:00
|
|
|
|
#include "dbgpath.h"
|
|
|
|
|
|
|
|
|
|
#include <boost/tokenizer.hpp>
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DbgPythonPath::DbgPythonPath()
|
|
|
|
|
{
|
|
|
|
|
DWORD enviromentSize = 0;
|
|
|
|
|
|
|
|
|
|
enviromentSize = GetEnvironmentVariableA( "PYTHONPATH", NULL, enviromentSize );
|
|
|
|
|
|
2011-02-24 18:46:00 +08:00
|
|
|
|
std::vector<char> enviromentBuffer(enviromentSize);
|
|
|
|
|
|
|
|
|
|
if (!enviromentBuffer.empty())
|
|
|
|
|
{
|
|
|
|
|
GetEnvironmentVariableA( "PYTHONPATH", &enviromentBuffer[0], enviromentSize );
|
|
|
|
|
|
|
|
|
|
typedef boost::escaped_list_separator<char> char_separator_t;
|
|
|
|
|
typedef boost::tokenizer< char_separator_t > char_tokenizer_t;
|
|
|
|
|
|
|
|
|
|
std::string pytonPath( &enviromentBuffer[0] );
|
|
|
|
|
|
|
|
|
|
char_tokenizer_t token( pytonPath, char_separator_t( "", "; \t", "\"" ) );
|
|
|
|
|
|
|
|
|
|
for ( char_tokenizer_t::iterator it = token.begin(); it != token.end(); ++it )
|
|
|
|
|
{
|
|
|
|
|
if ( *it != "" )
|
|
|
|
|
m_pathList.push_back( *it );
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-10-25 15:54:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
std::string
|
|
|
|
|
DbgPythonPath::getStr() const
|
|
|
|
|
{
|
|
|
|
|
std::string str;
|
|
|
|
|
std::vector<std::string>::const_iterator it = m_pathList.begin();
|
|
|
|
|
|
|
|
|
|
for ( ; it != m_pathList.end(); ++it )
|
|
|
|
|
{
|
|
|
|
|
str += *it;
|
|
|
|
|
str += ";";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
DbgPythonPath::findPath(
|
|
|
|
|
const std::string &fileName,
|
|
|
|
|
std::string &fullFileName,
|
|
|
|
|
std::string &filePath ) const
|
|
|
|
|
{
|
2010-11-22 16:47:24 +08:00
|
|
|
|
std::vector< std::string > extPathList;
|
|
|
|
|
|
|
|
|
|
boost::python::object sys = boost::python::import( "sys");
|
|
|
|
|
|
|
|
|
|
boost::python::list pathList( sys.attr("path") );
|
|
|
|
|
|
|
|
|
|
boost::python::ssize_t n = boost::python::len(pathList);
|
|
|
|
|
for(boost::python::ssize_t i=0;i<n;i++)
|
|
|
|
|
extPathList.push_back( boost::python::extract<std::string>( pathList[i] ) );
|
|
|
|
|
|
2010-10-28 13:59:57 +08:00
|
|
|
|
bool pyExt = fileName.rfind( ".py" ) == fileName.length() - 3;
|
|
|
|
|
|
|
|
|
|
// 1. <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
DWORD bufSize =
|
|
|
|
|
SearchPathA(
|
|
|
|
|
NULL,
|
|
|
|
|
fileName.c_str(),
|
|
|
|
|
pyExt ? NULL : ".py",
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL );
|
|
|
|
|
|
|
|
|
|
if ( bufSize > 0 )
|
|
|
|
|
{
|
2011-04-13 15:28:56 +08:00
|
|
|
|
bufSize += 1;
|
2011-02-24 18:46:00 +08:00
|
|
|
|
std::vector<char> fullFileNameCStr(bufSize);
|
2010-10-28 13:59:57 +08:00
|
|
|
|
char *partFileNameCStr = NULL;
|
|
|
|
|
|
|
|
|
|
SearchPathA(
|
|
|
|
|
NULL,
|
|
|
|
|
fileName.c_str(),
|
|
|
|
|
pyExt ? NULL : ".py",
|
|
|
|
|
bufSize,
|
2011-02-24 18:46:00 +08:00
|
|
|
|
&fullFileNameCStr[0],
|
2011-04-13 15:28:56 +08:00
|
|
|
|
&partFileNameCStr );
|
2010-10-28 13:59:57 +08:00
|
|
|
|
|
2011-02-24 18:46:00 +08:00
|
|
|
|
fullFileName = std::string( &fullFileNameCStr[0] );
|
2011-04-13 15:28:56 +08:00
|
|
|
|
if ( !fullFileName.empty() )
|
|
|
|
|
{
|
|
|
|
|
filePath = std::string( &fullFileNameCStr[0], partFileNameCStr );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2010-10-28 13:59:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> m_pathList
|
2010-10-25 15:54:10 +08:00
|
|
|
|
|
2010-11-22 16:47:24 +08:00
|
|
|
|
std::vector<std::string>::const_iterator it = extPathList.begin();
|
2010-10-25 15:54:10 +08:00
|
|
|
|
|
2010-11-22 16:47:24 +08:00
|
|
|
|
for ( ; it != extPathList.end(); ++it )
|
2010-10-25 15:54:10 +08:00
|
|
|
|
{
|
|
|
|
|
DWORD bufSize =
|
|
|
|
|
SearchPathA(
|
|
|
|
|
(*it).c_str(),
|
|
|
|
|
fileName.c_str(),
|
2010-10-28 13:59:57 +08:00
|
|
|
|
pyExt ? NULL : ".py",
|
2010-10-25 15:54:10 +08:00
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL );
|
|
|
|
|
|
|
|
|
|
if ( bufSize > 0 )
|
|
|
|
|
{
|
2011-04-13 15:28:56 +08:00
|
|
|
|
bufSize += 1;
|
2011-04-13 23:51:54 +08:00
|
|
|
|
std::vector<char> fullFileNameCStr(bufSize);
|
2010-10-25 15:54:10 +08:00
|
|
|
|
char *partFileNameCStr = NULL;
|
|
|
|
|
|
2011-04-13 15:28:56 +08:00
|
|
|
|
bufSize = SearchPathA(
|
2010-10-25 15:54:10 +08:00
|
|
|
|
(*it).c_str(),
|
|
|
|
|
fileName.c_str(),
|
2010-10-28 13:59:57 +08:00
|
|
|
|
pyExt ? NULL : ".py",
|
2010-10-25 15:54:10 +08:00
|
|
|
|
bufSize,
|
2011-02-24 18:46:00 +08:00
|
|
|
|
&fullFileNameCStr[0],
|
2011-04-13 15:28:56 +08:00
|
|
|
|
&partFileNameCStr );
|
|
|
|
|
|
|
|
|
|
fullFileName = std::string( &fullFileNameCStr[0] );
|
|
|
|
|
if ( !fullFileName.empty() )
|
|
|
|
|
{
|
|
|
|
|
filePath = std::string( &fullFileNameCStr[0], partFileNameCStr );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2010-10-25 15:54:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-28 13:59:57 +08:00
|
|
|
|
return false;
|
2010-10-25 15:54:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|