fix package description generation script to be compatible with python 2 and 3

This commit is contained in:
Sébastien Loriot 2020-07-21 10:28:54 +02:00 committed by Mael Rouxel-Labbé
parent a8d29742e7
commit 65ecf06f5d
3 changed files with 11 additions and 23 deletions

View File

@ -1,9 +1,3 @@
#!/bin/sh
if which python2 2>/dev/null >/dev/null; then
exec python2 ${CMAKE_BINARY_DIR}/pkglist_filter.py "$1"
elif which python2.7 2>/dev/null >/dev/null; then
exec python2.7 ${CMAKE_BINARY_DIR}/pkglist_filter.py "$1"
elif which python2.6 2>/dev/null >/dev/null; then
exec python2.6 ${CMAKE_BINARY_DIR}/pkglist_filter.py "$1"
fi
exec ${PYTHON_EXECUTABLE} ${CMAKE_BINARY_DIR}/pkglist_filter.py "$1"

View File

@ -1,18 +1,6 @@
@echo off
@where /q python
if not errorlevel 1 ( set python=python )
@where /q python2
if not errorlevel 1 ( set python=python2 )
@where /q python2.6
if not errorlevel 1 ( set python=python2.6 )
@where /q python2.7
if not errorlevel 1 ( set python=python2.7 )
:go
%python% ${CMAKE_BINARY_DIR}/pkglist_filter.py %1
${PYTHON_EXECUTABLE} ${CMAKE_BINARY_DIR}/pkglist_filter.py %1
@echo on

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
import codecs
import re
@ -28,10 +28,16 @@ def main(argv):
for l in pkgdesc:
do_print = do_print or re.match(".*cgalPkgDescriptionBegin.*", l)
if(do_print):
sys.stdout.write(l.encode('utf-8'))
if hasattr(sys.stdout, 'buffer'):
sys.stdout.buffer.write(l.encode('utf-8')) #python3
else:
sys.stdout.write(l.encode('utf-8')) #python2
do_print = do_print and (not re.match(".*cgalPkgDescriptionEnd.*", l))
else:
sys.stdout.write(line.encode('utf-8'))
if hasattr(sys.stdout, 'buffer'):
sys.stdout.buffer.write(line.encode('utf-8')) #python3
else:
sys.stdout.write(line.encode('utf-8')) #python2
if __name__ == "__main__":
main(sys.argv)