Skip to content

Commit

Permalink
Add different Python versions support (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
alinbalutoiu authored and c64cosmin committed Dec 18, 2017
1 parent b577b3c commit 8d453e8
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ python/build
python/lib
*.swp
output/

# changes should be made on the templates for those files
/GNUmakefile
/provider/GNUmakefile
/python/client.py
/installbuilder/Base_OMIScriptProvider.data
6 changes: 3 additions & 3 deletions GNUmakefile → GNUmakefile-template
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SCRIPTPROVIDER :

.phony : PYTHONWRAPPER
PYTHONWRAPPER :
cd $(TOP)/scriptprovider/python && python2.7 omi_setup.py build \
cd $(TOP)/scriptprovider/python && __PYTHON_VERSION__ omi_setup.py build \
--build-temp $(OSP_OUTPUTDIR)/python/build


Expand All @@ -33,15 +33,15 @@ TEST :
.phony : clean
clean :
$(MAKE) -C $(TOP)/scriptprovider/provider clean
cd $(TOP)/scriptprovider/python && python2.7 omi_setup.py clean
cd $(TOP)/scriptprovider/python && __PYTHON_VERSION__ omi_setup.py clean
$(MAKE) -C $(TOP)/scriptprovider/omigen_py clean
$(MAKE) -C $(TOP)/scriptprovider/test clean


.phony : install
install :
$(MAKE) -C $(TOP)/scriptprovider/provider install
cd $(TOP)/scriptprovider/python && python2.7 omi_setup.py install
cd $(TOP)/scriptprovider/python && __PYTHON_VERSION__ omi_setup.py install
$(MAKE) -C $(TOP)/scriptprovider/omigen_py install


Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ said, our formal tested matrix of Linux platforms includes the following:
- SUSE Linux Enteprise Server 12 x64
- Ubuntu 12.04 LTS, 14.04 LTS, and 16.04 LTS (x86 and x64)

#### New Python versions beta support

The master branch of omi-script-provider now includes beta support for the
following Python versions:
- Python 2.6
- Python 3.4
- Python 3.5
- Python 3.6

### How to build

#### Dependencies to build OMI Python Script Provider:
Expand Down
68 changes: 68 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ do
outputdirname=$arg
;;

--python-version=*)
pythonversion=$arg
;;


*)
echo "$0: unknown option: $opt"
Expand Down Expand Up @@ -100,11 +104,74 @@ OPTIONS:
--outputdirname The name of the output directory where the binary
files are placed. This name must not contain
slashes.
--python-version The python version for which to compile the
package. The name should contain only the version.
Example: "--python-version 2.7"
EOF
exit 0
fi


##==============================================================================
##
## Check if the given Python version is supported. Defaults to version 2.7
## Update the files with the given python version
##
##==============================================================================

if [ -z "$pythonversion" ]; then
pythonversion=2.7
fi

supported_python_versions="2.6 2.7 3.4 3.5 3.6"
echo "$supported_python_versions" | grep $pythonversion 2>&1 > /dev/null
if [ $? != 0 ]; then
echo "Python version $pythonversion is not supported"
echo "Supported python versions: $supported_python_versions"
exit 1
fi

python_name="python$pythonversion"

command -v $python_name 2>&1 > /dev/null
if [ $? != 0 ]; then
echo "Python version $pythonversion was not found on the system"
exit 1
fi

files_to_update="
$root/provider/GNUmakefile-template
$root/python/client.py-template
$root/installbuilder/Base_OMIScriptProvider.data-template
$root/GNUmakefile-template
"
for file in $files_to_update
do
# Remove "-template" from the filename to get the target file
target_file=`echo -n "$file" | head -c -9`
if [ -f $target_file ]; then
echo "Warning! This will replace the existing file $target_file"
read -r -p "Are you sure? [Y/n]" response
response=`echo $response | tr '[:upper:]' '[:lower:]'`
if echo $response | grep -Eq '(no|n)'; then
echo "configure stopped!"
exit 1
fi
fi
cp $file $target_file
sed -i"*" "s|__PYTHON_VERSION__|$python_name|g" $target_file
if [ "$(basename $target_file)" = "Base_OMIScriptProvider.data" ]; then
# Replace the extension name inside the package data
# Python 3 adds an extra string in the file name (ex: omi.cpython-34m.so)
python_extension_name=`$python_name -c "import sysconfig; print (sysconfig.get_config_var('SO'))"`
python_extension_name="omi$python_extension_name"
sed -i"*" "s|__PYTHON_EXTENSION_NAME__|$python_extension_name|g" $target_file
fi
done

echo "configured for Python $pythonversion"


##==============================================================================
##
## Create output directories.
Expand Down Expand Up @@ -139,6 +206,7 @@ CONFIG_MINOR=$minor
CONFIG_REVISION=$revision
CONFIG_OMI_SCRIPTPROVIDER_VERSION_BUILD=$patch_level
CONFIG_DATE=$date
CONFIG_PYTHON_VERSION=$pythonversion
CONFIG_MAK=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SHLIB_EXT: 'so'
%Files
/opt/omi/lib/libOMIScriptProvider.so; output/bin/libOMIScriptProvider.so; 755; ${{RUN_AS_USER}}; root
/opt/omi/lib/client.py; python/client.py; 755; ${{RUN_AS_USER}}; root
/opt/omi/bin/PythonOMIWrapper.so; output/python/lib/omi.so; 755; ${{RUN_AS_USER}}; root
/opt/omi/bin/PythonOMIWrapper.so; output/python/lib/__PYTHON_EXTENSION_NAME__; 755; ${{RUN_AS_USER}}; root
/opt/omi/bin/omigen_py; output/bin/omigen_py; 755; ${{RUN_AS_USER}}; root


Expand All @@ -29,15 +29,15 @@ SHLIB_EXT: 'so'


%Postinstall_10
SITE_PKG=$(python2.7 -c "import site; print (site.getsitepackages()[0])")
mv /opt/omi/bin/PythonOMIWrapper.so $SITE_PKG/omi.so
SITE_PKG=$(__PYTHON_VERSION__ -c "import site; print (site.getsitepackages()[0])")
mv /opt/omi/bin/PythonOMIWrapper.so $SITE_PKG/__PYTHON_EXTENSION_NAME__

%Postinstall_20
grep -cq 'script=--python:' /etc/opt/omi/conf/omireg.conf || echo 'script=--python:python2.7:client.py' >> /etc/opt/omi/conf/omireg.conf
grep -cq 'script=--python:' /etc/opt/omi/conf/omireg.conf || echo 'script=--python:__PYTHON_VERSION__:client.py' >> /etc/opt/omi/conf/omireg.conf

%Postinstall_30
grep -cq 'script=--Python:' /etc/opt/omi/conf/omireg.conf || echo 'script=--Python:python2.7:client.py' >> /etc/opt/omi/conf/omireg.conf
grep -cq 'script=--Python:' /etc/opt/omi/conf/omireg.conf || echo 'script=--Python:__PYTHON_VERSION__:client.py' >> /etc/opt/omi/conf/omireg.conf

%Postuninstall_10
SITE_PKG=$(python2.7 -c "import site; print (site.getsitepackages()[0])")
rm $SITE_PKG/omi.so
SITE_PKG=$(__PYTHON_VERSION__ -c "import site; print (site.getsitepackages()[0])")
rm $SITE_PKG/__PYTHON_EXTENSION_NAME__
3 changes: 2 additions & 1 deletion installbuilder/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ LONG_NAME=$(CONFIG_FULLPRODUCT)
PF_MAJOR=$(CONFIG_MAJOR)
PF_MINOR=$(CONFIG_MINOR)
OMI_SCRIPTPROVIDER_VERSION_BUILD=$(CONFIG_OMI_SCRIPTPROVIDER_VERSION_BUILD)
PYTHON_VERSION=$(CONFIG_PYTHON_VERSION)
PROVIDES=omiscriptproviderpkg
DESCRIPTION=Enables OMI providers to be written in scripting languages for Linux
RUN_AS_USER=root
PACKAGE_NAME=$(SHORT_NAME)-$(CONFIG_VERSION)-$(OMI_SCRIPTPROVIDER_VERSION_BUILD).$(PF_ARCH)
PACKAGE_NAME=$(SHORT_NAME)-$(CONFIG_VERSION)-$(OMI_SCRIPTPROVIDER_VERSION_BUILD).Python-$(PYTHON_VERSION).$(PF_ARCH)

ifeq ("$(wildcard /usr/bin/dpkg-deb)","")
DPKG_LOCATION=--DPKG_LOCATION="$(IB_DIR)/tools/bin/dpkg-deb-$(PF_ARCH)"
Expand Down
4 changes: 2 additions & 2 deletions provider/GNUmakefile → provider/GNUmakefile-template
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ install : $(BIN_PATH)/$(LIBRARY)
@echo ...installing: $(LIBRARY)
@$(COPY) $(BIN_PATH)/$(LIBRARY) $(CONFIG_LIBDIR)/$(LIBRARY)
@grep -cq '^\W*script=\-\-Python:' $(CONFIG_SYSCONFDIR)/omireg.conf || \
echo 'script=--Python:python2.7:client.py' >> \
echo 'script=--Python:__PYTHON_VERSION__:client.py' >> \
$(CONFIG_SYSCONFDIR)/omireg.conf
@grep -cq '^\W*script=\-\-python:' $(CONFIG_SYSCONFDIR)/omireg.conf || \
echo 'script=--python:python2.7:client.py' >> \
echo 'script=--python:__PYTHON_VERSION__:client.py' >> \
$(CONFIG_SYSCONFDIR)/omireg.conf


Expand Down
2 changes: 1 addition & 1 deletion python/client.py → python/client.py-template
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env __PYTHON_VERSION__
import imp
import os
import sys
Expand Down

1 comment on commit 8d453e8

@EMumau
Copy link
Contributor

@EMumau EMumau commented on 8d453e8 Dec 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like this change. The entire GNUmakefile should not be auto-generated. The way that details like this are normally managed is by creating a rules file (i.e.; config.mak, omi.mak) and defining environmental variables in those files. Generally, all environmental variables (paths, version numbers, interchangeable libraries) are defined in such a rules file. Often, some shell script like configure is called to create the variable values and that rules file.
The GNUmakefile should be reverted. The logic for determining the python version and paths should be moved into the configure script. And the variables should be put into config.mak.

Please sign in to comment.