From 69da8abdc91d1bf7716900b9088189c75a140330 Mon Sep 17 00:00:00 2001 From: "SND\\air_max_cp" Date: Fri, 16 Dec 2011 16:03:39 +0000 Subject: [PATCH] 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 --- _boost_pykd_build.cmd | 26 ++++++++ pykd/dbgext.cpp | 3 +- pykd/dbgpath.cpp | 152 +++++++++++------------------------------- pykd/dbgpath.h | 21 ++---- pykd/utils.h | 9 +++ 5 files changed, 78 insertions(+), 133 deletions(-) create mode 100644 _boost_pykd_build.cmd create mode 100644 pykd/utils.h diff --git a/_boost_pykd_build.cmd b/_boost_pykd_build.cmd new file mode 100644 index 0000000..283ea23 --- /dev/null +++ b/_boost_pykd_build.cmd @@ -0,0 +1,26 @@ +:: +:: Copy to boost root dir +:: + +call :ExecBjam 32 +call :ExecBjam 64 +pause +goto :EOF + + +:ExecBjam +set arch=%1 +set stagedir=stage +if "%arch%"=="64" set stagedir=stage64 + +bjam.exe ^ + -j 4 ^ + --toolset=msvc-9.0 ^ + release debug ^ + threading=multi link=static runtime-link=shared ^ + address-model=%arch% ^ + --with-python --with-date_time --with-regex --with-thread ^ + python=2.6 ^ + --stagedir=%stagedir% ^ + stage +goto :EOF diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index e75d0bf..d1ed286 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -844,11 +844,10 @@ py( PDEBUG_CLIENT4 client, PCSTR args) // найти путь к файлу std::string fullFileName; - std::string filePath; DbgPythonPath dbgPythonPath; - if ( dbgPythonPath.findPath( argsList[0], fullFileName, filePath ) ) + if ( dbgPythonPath.getFullFileName( argsList[0], fullFileName ) ) { try { diff --git a/pykd/dbgpath.cpp b/pykd/dbgpath.cpp index 10be731..f2094b7 100644 --- a/pykd/dbgpath.cpp +++ b/pykd/dbgpath.cpp @@ -1,147 +1,71 @@ #include "stdafx.h" #include "dbgpath.h" +#include "utils.h" #include /////////////////////////////////////////////////////////////////////////////// - - DbgPythonPath::DbgPythonPath() { - DWORD enviromentSize = 0; - - enviromentSize = GetEnvironmentVariableA( "PYTHONPATH", NULL, enviromentSize ); + boost::python::object sys = boost::python::import("sys"); - std::vector enviromentBuffer(enviromentSize); + boost::python::list pathList(sys.attr("path")); - if (!enviromentBuffer.empty()) - { - GetEnvironmentVariableA( "PYTHONPATH", &enviromentBuffer[0], enviromentSize ); - - typedef boost::escaped_list_separator 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::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::list pathList( sys.attr("path") ); - boost::python::ssize_t n = boost::python::len(pathList); - for(boost::python::ssize_t i=0;i( pathList[i] ) ); - bool pyExt = fileName.rfind( ".py" ) == fileName.length() - 3; + for (boost::python::ssize_t i = 0; i < n ; i++) + m_extactedPathList.push_back(boost::python::extract(pathList[i])); +} - // 1. Ищем в рабочей директории - DWORD bufSize = - SearchPathA( - NULL, - fileName.c_str(), - pyExt ? NULL : ".py", - 0, - NULL, - NULL ); - - if ( bufSize > 0 ) - { - bufSize += 1; - std::vector fullFileNameCStr(bufSize); - char *partFileNameCStr = NULL; +/////////////////////////////////////////////////////////////////////////////// + +bool DbgPythonPath::getFullFileName(const std::string &fileName, std::string &fullFileName) const +{ + bool fileHasPyExt = fileName.rfind(".py") == fileName.length() - 3; + fullFileName = fileName; - SearchPathA( - NULL, - fileName.c_str(), - pyExt ? NULL : ".py", - bufSize, - &fullFileNameCStr[0], - &partFileNameCStr ); - - fullFileName = std::string( &fullFileNameCStr[0] ); - if ( !fullFileName.empty() ) - { - filePath = std::string( &fullFileNameCStr[0], partFileNameCStr ); - return true; - } - } - - // 2. Ищем во всех директориях, указанных в m_pathList + if (!fileHasPyExt) + fullFileName += ".py"; - std::vector::const_iterator it = extPathList.begin(); - - for ( ; it != extPathList.end(); ++it ) + if (FileExists(fullFileName.c_str())) + return true; + + std::vector::const_iterator it = m_extactedPathList.begin(); + for ( ; it != m_extactedPathList.end(); ++it) { - DWORD bufSize = - SearchPathA( - (*it).c_str(), - fileName.c_str(), - pyExt ? NULL : ".py", - 0, - NULL, - NULL ); + DWORD bufSize = SearchPathA( + (*it).c_str(), + fullFileName.c_str(), + NULL, + 0, + NULL, + NULL); - if ( bufSize > 0 ) + if (bufSize > 0) { bufSize += 1; std::vector fullFileNameCStr(bufSize); - char *partFileNameCStr = NULL; + char *partFileNameCStr = NULL; bufSize = SearchPathA( (*it).c_str(), - fileName.c_str(), - pyExt ? NULL : ".py", + fullFileName.c_str(), + NULL, bufSize, &fullFileNameCStr[0], - &partFileNameCStr ); - - fullFileName = std::string( &fullFileNameCStr[0] ); - if ( !fullFileName.empty() ) - { - filePath = std::string( &fullFileNameCStr[0], partFileNameCStr ); + &partFileNameCStr); + + if (bufSize > 0) + { + fullFileName = std::string(&fullFileNameCStr[0]); return true; - } + } } } - + + fullFileName = ""; return false; } diff --git a/pykd/dbgpath.h b/pykd/dbgpath.h index 3f790f1..56e4cbe 100644 --- a/pykd/dbgpath.h +++ b/pykd/dbgpath.h @@ -1,32 +1,19 @@ #pragma once #include +#include /////////////////////////////////////////////////////////////////////////////// class DbgPythonPath { public: - DbgPythonPath(); - std::string - getStr() const; - - bool - findPath( - const std::string &fileName, - std::string &fullFileName, - std::string &filePath ) const; - - + bool getFullFileName(const std::string &fileName, std::string &fullFileName) const; + private: - - std::vector< std::string > m_pathList; - + std::vector m_extactedPathList; }; -//extern DbgPythonPath& dbgPythonPath; - - /////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/utils.h b/pykd/utils.h new file mode 100644 index 0000000..77bc24a --- /dev/null +++ b/pykd/utils.h @@ -0,0 +1,9 @@ +#pragma once + +//////////////////////////////////////////////////////////////////////////////// +inline +bool FileExists(LPCSTR lpFileName) +{ + return ::GetFileAttributesA(lpFileName) != DWORD(-1); +} +////////////////////////////////////////////////////////////////////////////////