mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 04:13:22 +08:00
added: boost build command line script
[0.1.x] refactored: DbgPythonPath class [0.1.x] added: FileExists function [0.0.x] refactored: DbgPythonPath class [0.0.x] added: FileExists function git-svn-id: https://pykd.svn.codeplex.com/svn@72409 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
789b00119a
commit
8c1103f19b
@ -896,11 +896,10 @@ py( PDEBUG_CLIENT4 client, PCSTR args )
|
|||||||
delete[] pythonArgs;
|
delete[] pythonArgs;
|
||||||
|
|
||||||
// íàéòè ïóòü ê ôàéëó
|
// íàéòè ïóòü ê ôàéëó
|
||||||
std::string scriptName;
|
std::string fullScriptName;
|
||||||
std::string filePath;
|
|
||||||
DbgPythonPath dbgPythonPath;
|
DbgPythonPath dbgPythonPath;
|
||||||
|
|
||||||
if ( !dbgPythonPath.findPath( argsList[0], scriptName, filePath ) )
|
if ( !dbgPythonPath.getFullFileName( argsList[0], fullScriptName ) )
|
||||||
{
|
{
|
||||||
dbgClient->eprintln( L"script file not found" );
|
dbgClient->eprintln( L"script file not found" );
|
||||||
}
|
}
|
||||||
@ -909,7 +908,7 @@ py( PDEBUG_CLIENT4 client, PCSTR args )
|
|||||||
|
|
||||||
python::object result;
|
python::object result;
|
||||||
|
|
||||||
result = python::exec_file( scriptName.c_str(), global, global );
|
result = python::exec_file( fullScriptName.c_str(), global, global );
|
||||||
}
|
}
|
||||||
catch( boost::python::error_already_set const & )
|
catch( boost::python::error_already_set const & )
|
||||||
{
|
{
|
||||||
|
118
pykd/dbgpath.cpp
118
pykd/dbgpath.cpp
@ -1,120 +1,44 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
#include "dbgpath.h"
|
#include "dbgpath.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include <boost/tokenizer.hpp>
|
#include <boost/tokenizer.hpp>
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DbgPythonPath::DbgPythonPath()
|
DbgPythonPath::DbgPythonPath()
|
||||||
{
|
{
|
||||||
DWORD enviromentSize = 0;
|
|
||||||
|
|
||||||
enviromentSize = GetEnvironmentVariableA( "PYTHONPATH", NULL, enviromentSize );
|
|
||||||
|
|
||||||
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 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
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
|
|
||||||
{
|
|
||||||
std::vector< std::string > extPathList;
|
|
||||||
|
|
||||||
boost::python::object sys = boost::python::import("sys");
|
boost::python::object sys = boost::python::import("sys");
|
||||||
|
|
||||||
boost::python::list pathList(sys.attr("path"));
|
boost::python::list pathList(sys.attr("path"));
|
||||||
|
|
||||||
boost::python::ssize_t n = boost::python::len(pathList);
|
boost::python::ssize_t n = boost::python::len(pathList);
|
||||||
|
|
||||||
for (boost::python::ssize_t i = 0; i < n ; i++)
|
for (boost::python::ssize_t i = 0; i < n ; i++)
|
||||||
extPathList.push_back( boost::python::extract<std::string>( pathList[i] ) );
|
m_extactedPathList.push_back(boost::python::extract<std::string>(pathList[i]));
|
||||||
|
}
|
||||||
|
|
||||||
bool pyExt = fileName.rfind( ".py" ) == fileName.length() - 3;
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// 1. Èùåì â ðàáî÷åé äèðåêòîðèè
|
bool DbgPythonPath::getFullFileName(const std::string &fileName, std::string &fullFileName) const
|
||||||
DWORD bufSize =
|
|
||||||
SearchPathA(
|
|
||||||
NULL,
|
|
||||||
fileName.c_str(),
|
|
||||||
pyExt ? NULL : ".py",
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
NULL );
|
|
||||||
|
|
||||||
if ( bufSize > 0 )
|
|
||||||
{
|
{
|
||||||
bufSize += 1;
|
bool fileHasPyExt = fileName.rfind(".py") == fileName.length() - 3;
|
||||||
std::vector<char> fullFileNameCStr(bufSize);
|
fullFileName = fileName;
|
||||||
char *partFileNameCStr = NULL;
|
|
||||||
|
|
||||||
SearchPathA(
|
if (!fileHasPyExt)
|
||||||
NULL,
|
fullFileName += ".py";
|
||||||
fileName.c_str(),
|
|
||||||
pyExt ? NULL : ".py",
|
|
||||||
bufSize,
|
|
||||||
&fullFileNameCStr[0],
|
|
||||||
&partFileNameCStr );
|
|
||||||
|
|
||||||
fullFileName = std::string( &fullFileNameCStr[0] );
|
if (FileExists(fullFileName.c_str()))
|
||||||
if ( !fullFileName.empty() )
|
|
||||||
{
|
|
||||||
filePath = std::string( &fullFileNameCStr[0], partFileNameCStr );
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Èùåì âî âñåõ äèðåêòîðèÿõ, óêàçàííûõ â m_pathList
|
std::vector<std::string>::const_iterator it = m_extactedPathList.begin();
|
||||||
|
for ( ; it != m_extactedPathList.end(); ++it)
|
||||||
std::vector<std::string>::const_iterator it = extPathList.begin();
|
|
||||||
|
|
||||||
for ( ; it != extPathList.end(); ++it )
|
|
||||||
{
|
{
|
||||||
DWORD bufSize =
|
DWORD bufSize = SearchPathA(
|
||||||
SearchPathA(
|
|
||||||
(*it).c_str(),
|
(*it).c_str(),
|
||||||
fileName.c_str(),
|
fullFileName.c_str(),
|
||||||
pyExt ? NULL : ".py",
|
NULL,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
@ -127,21 +51,21 @@ DbgPythonPath::findPath(
|
|||||||
|
|
||||||
bufSize = SearchPathA(
|
bufSize = SearchPathA(
|
||||||
(*it).c_str(),
|
(*it).c_str(),
|
||||||
fileName.c_str(),
|
fullFileName.c_str(),
|
||||||
pyExt ? NULL : ".py",
|
NULL,
|
||||||
bufSize,
|
bufSize,
|
||||||
&fullFileNameCStr[0],
|
&fullFileNameCStr[0],
|
||||||
&partFileNameCStr);
|
&partFileNameCStr);
|
||||||
|
|
||||||
fullFileName = std::string( &fullFileNameCStr[0] );
|
if (bufSize > 0)
|
||||||
if ( !fullFileName.empty() )
|
|
||||||
{
|
{
|
||||||
filePath = std::string( &fullFileNameCStr[0], partFileNameCStr );
|
fullFileName = std::string(&fullFileNameCStr[0]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fullFileName = "";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,24 +8,12 @@
|
|||||||
class DbgPythonPath
|
class DbgPythonPath
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DbgPythonPath();
|
DbgPythonPath();
|
||||||
|
|
||||||
std::string
|
bool getFullFileName(const std::string &fileName, std::string &fullFileName) const;
|
||||||
getStr() const;
|
|
||||||
|
|
||||||
bool
|
|
||||||
findPath(
|
|
||||||
const std::string &fileName,
|
|
||||||
std::string &fullFileName,
|
|
||||||
std::string &filePath ) const;
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::vector<std::string> m_extactedPathList;
|
||||||
std::vector< std::string > m_pathList;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
@ -99,3 +99,9 @@ python::list toPyList(const std::list< TElem > &stdList)
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
inline
|
||||||
|
bool FileExists(LPCSTR lpFileName)
|
||||||
|
{
|
||||||
|
return ::GetFileAttributesA(lpFileName) != DWORD(-1);
|
||||||
|
}
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user