Refactor heat-translator setup.py 61/41261/1
authorshangxdy <shang.xiaodong@zte.com.cn>
Thu, 7 Sep 2017 02:54:36 +0000 (10:54 +0800)
committershangxdy <shang.xiaodong@zte.com.cn>
Thu, 7 Sep 2017 03:00:56 +0000 (11:00 +0800)
Overwrite setup.py in heat-translator project to uninstall openstack
heat-translator before build/install nfv-heattranslator.

JIRA: PARSER-151

Change-Id: I65da014439e3c07b866b3baf8643e569d813165c
Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
tosca2heat/heat-translator/setup.cfg
tosca2heat/heat-translator/setup.py

index 863b97d..2a10811 100644 (file)
@@ -1,5 +1,5 @@
 [metadata]
-name = heat-translator
+name = nfv-heattranslator
 version =
 url = https://wiki.opnfv.org/display/parser
 summary = Tool to translate non-heat templates to Heat Orchestration Template in nfv.
index 566d844..bf9aa00 100644 (file)
 # 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
@@ -24,6 +29,48 @@ try:
 except ImportError:
     pass
 
+
+class HeatTranslator_build_py(build_py):
+    """Override build_py to call customized build."""
+
+    def run(self):
+        print(" ===  Before nfv heat translator build === ")
+        # self.run_command('xxx')
+        super(HeatTranslator_build_py, self).run()
+        print(" ===  After nfv heat heat translator build === ")
+
+
+class HeatTranslator_install(install):
+    """Override install to call customized install."""
+
+    def run(self):
+        print(" ===  Before nfv heat translator install === ")
+        # Make sure uninstall toscaparser from openstack
+        os.system("pip uninstall -y heat-translator")
+
+        super(HeatTranslator_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 heat translator install === ")
+
+
+class HeatTranslator_post_install(install_data):
+    """Override install_data to call customized install_data."""
+
+    def run(self):
+        print(" === Before nfv heat translator post install data === ")
+        # Call parent
+        super(HeatTranslator_post_install, self).run(self)
+        # Execute commands
+        print(" === After nfv heat translator post install data ===")
+
+
 setuptools.setup(
     setup_requires=['pbr>=2.0.0'],
+    cmdclass={
+        "build_py": HeatTranslator_build_py,
+        "install_data": HeatTranslator_install,
+        "post_install": HeatTranslator_post_install,
+    },
     pbr=True)