From 87be76e6c8b3024c05fe76a97a5a922486a64bb9 Mon Sep 17 00:00:00 2001 From: shangxdy Date: Thu, 31 Aug 2017 10:22:48 +0800 Subject: Package for funectest Modify the install script JIRA: PARSER-125 Change-Id: Ia43687286fb8ac3b18b816aa5e4928ce9a12beec Signed-off-by: shangxdy --- setup.py | 44 ++++++++++++++++++++++++++++++++++++ tests/parser_install.sh | 41 --------------------------------- tools/parser_install.sh | 41 +++++++++++++++++++++++++++++++++ tosca2heat/tosca-parser/setup.py | 49 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 41 deletions(-) delete mode 100755 tests/parser_install.sh create mode 100755 tools/parser_install.sh diff --git a/setup.py b/setup.py index c53ce4f..0546aa8 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,54 @@ +import os import setuptools +from distutils.command.install_data import install_data +from setuptools.command.build_py import build_py +from setuptools.command.install import install + try: import multiprocessing # noqa except ImportError: pass + +class Parser_build_py(build_py): + """Override build_py to call customized build.""" + + def run(self): + print(" === Before nfv parser build === ") + # self.run_command('xxx') + super(Parser_build_py, self).run() + print(" === After nfv parser build === ") + + +class Parser_install(install): + """Override install to call customized install.""" + + def run(self): + print(" === Before nfv parser install === ") + super(Parser_install, self).run(self) + # Custom stuff here + # distutils.command.install actually has some nice helper methods + # and interfaces. I strongly suggest reading the docstrings. + print(" === After nfv parser install === ") + + +class Parser_post_install(install_data): + """Override install_data to call customized install_data.""" + + def run(self): + print(" === Before nfv parser post install data === ") + # Call parent + super(Parser_post_install, self).run(self) + # Execute commands + print(" === After nfv parser post install data ===") + + setuptools.setup( setup_requires=['pbr>=2.0.0'], + cmdclass={ + "build_py": Parser_build_py, + "install_data": Parser_install, + "post_install": Parser_post_install, + }, pbr=True) diff --git a/tests/parser_install.sh b/tests/parser_install.sh deleted file mode 100755 index 40b61d4..0000000 --- a/tests/parser_install.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash -e -############################################################################## -# Copyright (c) 2016 ZTE Corporation. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -set +e -BASE_WORK_DIR=$(cd $(dirname $0) && pwd) - -OPNFV_REPO_DIR=${1:-""} - -# start syslog for loghander -service rsyslog restart && echo "syslog start successfully" - -# install requirements for parser -if [ -n "${OPNFV_REPO_DIR}" ]; then - echo " OPNFV repository directory is ${OPNFV_REPO_DIR}" - pip install -r ${OPNFV_REPO_DIR}/parser/tosca2heat/tosca-parser/requirements.txt - pip install -r ${OPNFV_REPO_DIR}/parser/tosca2heat/heat-translator/requirements.txt -else - echo "No input for OPNFV repository directory, will use local directory" - pip install -r ${BASE_WORK_DIR}/../tosca2heat/tosca-parser/requirements.txt - pip install -r ${BASE_WORK_DIR}/../tosca2heat/heat-translator/requirements.txt -fi - -# uninstall other tosca-parser and heat-translator for parser -pip uninstall -y tosca-parser -pip uninstall -y heat-translator - -# install parser -if [ -n "${OPNFV_REPO_DIR}" ]; then - cd ${OPNFV_REPO_DIR}/parser/tosca2heat/tosca-parser && python setup.py install - cd ${OPNFV_REPO_DIR}/parser/tosca2heat/heat-translator && python setup.py install -else - cd ${BASE_WORK_DIR}/../tosca2heat/tosca-parser && python setup.py install - cd ${BASE_WORK_DIR}/../tosca2heat/heat-translator && python setup.py install -fi \ No newline at end of file diff --git a/tools/parser_install.sh b/tools/parser_install.sh new file mode 100755 index 0000000..d03bbb8 --- /dev/null +++ b/tools/parser_install.sh @@ -0,0 +1,41 @@ +#!/bin/bash -e +############################################################################## +# Copyright (c) 2016 ZTE Corporation. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +set +e +BASE_WORK_DIR=$(cd $(dirname $0) && pwd) + +OPNFV_REPO_DIR=${1:-""} + +# start syslog for loghander +service rsyslog restart && echo "syslog start successfully" + +# install requirements for parser +if [ -n "${OPNFV_REPO_DIR}" ]; then + echo " OPNFV repository directory is ${OPNFV_REPO_DIR}" + pip install -r ${OPNFV_REPO_DIR}/parser/tosca2heat/tosca-parser/requirements.txt + pip install -r ${OPNFV_REPO_DIR}/parser/tosca2heat/heat-translator/requirements.txt +else + echo "No input for OPNFV repository directory, will use local directory" + pip install -r ${BASE_WORK_DIR}/../tosca2heat/tosca-parser/requirements.txt + pip install -r ${BASE_WORK_DIR}/../tosca2heat/heat-translator/requirements.txt +fi + +# uninstall other tosca-parser and heat-translator for parser +pip uninstall -y tosca-parser +pip uninstall -y heat-translator + +# install parser +if [ -n "${OPNFV_REPO_DIR}" ]; then + cd ${OPNFV_REPO_DIR}/parser/tosca2heat/heat-translator && python setup.py install + cd ${OPNFV_REPO_DIR}/parser/tosca2heat/tosca-parser && python setup.py install +else + cd ${BASE_WORK_DIR}/../tosca2heat/heat-translator && python setup.py install + cd ${BASE_WORK_DIR}/../tosca2heat/tosca-parser && python setup.py install +fi \ No newline at end of file diff --git a/tosca2heat/tosca-parser/setup.py b/tosca2heat/tosca-parser/setup.py index 566d844..3d70b81 100644 --- a/tosca2heat/tosca-parser/setup.py +++ b/tosca2heat/tosca-parser/setup.py @@ -14,16 +14,65 @@ # limitations under the License. # THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT +import os import setuptools +from distutils.command.install_data import install_data +from setuptools.command.build_py import build_py +from setuptools.command.install import install + # In python < 2.7.4, a lazy loading of package `pbr` will break # setuptools if some other modules registered functions in `atexit`. # solution from: http://bugs.python.org/issue15881#msg170215 + + try: import multiprocessing # noqa except ImportError: pass + +class Toscaparser_build_py(build_py): + """Override build_py to call customized build.""" + + def run(self): + print(" === Before nfv toscaparser build === ") + # self.run_command('xxx') + super(Toscaparser_build_py, self).run() + print(" === After nfv toscaparser build === ") + + +class Toscaparser_install(install): + """Override install to call customized install.""" + + def run(self): + print(" === Before nfv toscaparser install === ") + # Make sure uninstall toscaparser from openstack + os.system("pip uninstall -y tosca-parser") + + super(Toscaparser_install, self).run(self) + # Custom stuff here + # distutils.command.install actually has some nice helper methods + # and interfaces. I strongly suggest reading the docstrings. + print(" === After nfv toscaparser install === ") + + +class Toscaparser_post_install(install_data): + """Override install_data to call customized install_data.""" + + def run(self): + print(" === Before nfv toscaparser post install data === ") + # Call parent + super(Toscaparser_post_install, self).run(self) + # Execute commands + print(" === After nfv toscaparser post install data ===") + + setuptools.setup( setup_requires=['pbr>=2.0.0'], + cmdclass={ + "build_py": Toscaparser_build_py, + "install_data": Toscaparser_install, + "post_install": Toscaparser_post_install, + }, pbr=True) -- cgit 1.2.3-korg