Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find python module #1484

Merged
merged 3 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Cleanup get_report function in gsad [#1263](https://github.com/greenbone/gsa/pull/1263)

### Fixed
- Fix finding python modules
[#1483](https://github.com/greenbone/gsa/pull/1483)
[#1484](https://github.com/greenbone/gsa/pull/1484)
- Fix displaying schedules created during migration [#1479](https://github.com/greenbone/gsa/pull/1478)
- Fix showing Loading indicator at entities pages [#1469](https://github.com/greenbone/gsa/pull/1469)
- Show notes and overrides for results and their icon indicator in results rows [#1446](https://github.com/greenbone/gsa/pull/1446)
Expand Down
87 changes: 64 additions & 23 deletions cmake/FindPythonModule.cmake
Original file line number Diff line number Diff line change
@@ -1,26 +1,67 @@
# From: https://cmake.org/pipermail/cmake/2011-January/041666.html
# - Macro to find a python module
#
# Use it like that: find_python_module(PyQt4 REQUIRED)
# Usage:
# include (FindPythonModule)
# find_python_module (module [VERSION] [REQUIRED])
#
# The following variables are defined:
# MODULE_FOUND - true if found
# MODULE_LOCATION - directory of the module, or it's library file if binary module
# MODULE_VERSION_STRING - module version, if available through __version__
#

macro (find_python_module module)

string (TOUPPER ${module} module_upper)
if (NOT ${module_upper}_FOUND)

# parse arguments
set (${module}_FIND_OPTIONAL TRUE)
if (${ARGC} EQUAL 2)
if (${ARGV1} MATCHES REQUIRED)
set (${module}_FIND_OPTIONAL FALSE)
else ()
set (${module}_FIND_VERSION ${ARGV1})
endif ()
elseif (${ARGC} EQUAL 3)
if (${ARGV2} MATCHES REQUIRED)
set (${module}_FIND_OPTIONAL FALSE)
endif ()
set (${module}_FIND_VERSION ${ARGV1})
endif ()

# A module's location is usually a directory, but for binary modules it's a .so file.
execute_process (COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import re, ${module}; print(re.compile('/__init__.py.*').sub('',${module}.__file__))"
RESULT_VARIABLE _${module}_status
OUTPUT_VARIABLE _${module}_location
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT _${module}_status)
set (${module_upper}_LOCATION ${_${module}_location}
CACHE STRING "Location of Python module ${module}")
# retrieve version
execute_process (COMMAND "${PYTHON_EXECUTABLE}" "-c" "import ${module}; print(${module}.__version__)"
RESULT_VARIABLE _${module}_status
OUTPUT_VARIABLE _${module}_version
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)

set (_${module_upper}_VERSION_MATCH TRUE)
if (NOT _${module}_status)
set (${module_upper}_VERSION_STRING ${_${module}_version})
if (${module}_FIND_VERSION)
if (${module}_FIND_VERSION VERSION_GREATER ${module_upper}_VERSION_STRING)
set (_${module_upper}_VERSION_MATCH FALSE)
endif ()
endif ()
mark_as_advanced (${module_upper}_VERSION_STRING)
endif ()
endif ()

function(find_python_module module)
string(TOUPPER ${module} module_upper)
if(NOT PY_${module_upper})
if(ARGC GREATER 1 AND ARGV1 STREQUAL "REQUIRED")
set(${module}_FIND_REQUIRED TRUE)
endif()
# A module's location is usually a directory, but for binary modules
# it's a .so file.
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import re, ${module}; print re.compile('/__init__.py.*').sub('',${module}.__file__)"
RESULT_VARIABLE _${module}_status
OUTPUT_VARIABLE _${module}_location
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT _${module}_status)
set(PY_${module_upper} ${_${module}_location} CACHE STRING
"Location of Python module ${module}")
endif(NOT _${module}_status)
endif(NOT PY_${module_upper})
find_package_handle_standard_args(PY_${module} DEFAULT_MSG PY_${module_upper})
set(PY_${module_upper}_FOUND ${PY_${module_upper}_FOUND} PARENT_SCOPE)
endfunction(find_python_module)
find_package_handle_standard_args (${module} REQUIRED_VARS ${module_upper}_LOCATION
${module}_FIND_OPTIONAL
_${module_upper}_VERSION_MATCH
VERSION_VAR ${module_upper}_VERSION_STRING
)
mark_as_advanced (${module_upper}_LOCATION)
endif (NOT ${module_upper}_FOUND)
endmacro (find_python_module)
6 changes: 3 additions & 3 deletions gsa/po/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ macro (MAKE_TRANSLATION _LANG)
endmacro ()

if (GETTEXT_FOUND)
if (PY_POLIB_FOUND)
if (POLIB_FOUND)

file (MAKE_DIRECTORY ${GSA_LOCALE_DIR})

Expand Down Expand Up @@ -104,9 +104,9 @@ if (GETTEXT_FOUND)
${GSA_LOCALE_DIR}
DESTINATION ${GSA_DEST_DIR})

else (PY_POLIB_FOUND)
else (POLIB_FOUND)
message (WARNING "Could not build translation files: Python interpreter or polib Python module not found.")
endif (PY_POLIB_FOUND)
endif (POLIB_FOUND)

else (GETTEXT_FOUND)
message (WARNING "Could not build translation files: gettext not found.")
Expand Down