Stop getting git data from functest dir
[functest.git] / functest / cli / commands / cli_env.py
index 14ad01b..8094c84 100644 (file)
@@ -10,7 +10,7 @@
 import os
 
 import click
-import git
+import prettytable
 
 from functest.utils.constants import CONST
 import functest.utils.functest_utils as ft_utils
@@ -28,7 +28,7 @@ class CliEnv(object):
                                "it again? [y|n]\n")
             while True:
                 if answer.lower() in ["y", "yes"]:
-                    os.remove(CONST.env_active)
+                    os.remove(CONST.__getattribute__('env_active'))
                     break
                 elif answer.lower() in ["n", "no"]:
                     return
@@ -36,28 +36,20 @@ class CliEnv(object):
                     answer = raw_input("Invalid answer. Please type [y|n]\n")
 
         cmd = ("python %s/functest/ci/prepare_env.py start" %
-               CONST.dir_repo_functest)
+               CONST.__getattribute__('dir_repo_functest'))
         ft_utils.execute_command(cmd)
 
     def show(self):
         def _get_value(attr, default='Unknown'):
             return attr if attr else default
 
-        install_type = _get_value(CONST.INSTALLER_TYPE)
-        installer_ip = _get_value(CONST.INSTALLER_IP)
+        install_type = _get_value(CONST.__getattribute__('INSTALLER_TYPE'))
+        installer_ip = _get_value(CONST.__getattribute__('INSTALLER_IP'))
         installer_info = ("%s, %s" % (install_type, installer_ip))
-        scenario = _get_value(CONST.DEPLOY_SCENARIO)
-        node = _get_value(CONST.NODE_NAME)
-        repo_h = git.Repo(CONST.dir_repo_functest).head
-        if repo_h.is_detached:
-            git_branch = 'detached from FETCH_HEAD'
-            git_hash = repo_h.commit.hexsha
-        else:
-            branch = repo_h.reference
-            git_branch = branch.name
-            git_hash = branch.commit.hexsha
-        is_debug = _get_value(CONST.CI_DEBUG, 'false')
-        build_tag = CONST.BUILD_TAG
+        scenario = _get_value(CONST.__getattribute__('DEPLOY_SCENARIO'))
+        node = _get_value(CONST.__getattribute__('NODE_NAME'))
+        is_debug = _get_value(CONST.__getattribute__('CI_DEBUG'), 'false')
+        build_tag = CONST.__getattribute__('BUILD_TAG')
         if build_tag is not None:
             build_tag = build_tag.lstrip(
                 "jenkins-").lstrip("functest").lstrip("-")
@@ -66,25 +58,21 @@ class CliEnv(object):
         if self.status(verbose=False) == 0:
             STATUS = "ready"
 
-        click.echo("+======================================================+")
-        click.echo("| Functest Environment info                            |")
-        click.echo("+======================================================+")
-        click.echo("|  INSTALLER: %s|" % installer_info.ljust(41))
-        click.echo("|   SCENARIO: %s|" % scenario.ljust(41))
-        click.echo("|        POD: %s|" % node.ljust(41))
-        click.echo("| GIT BRACNH: %s|" % git_branch.ljust(41))
-        click.echo("|   GIT HASH: %s|" % git_hash.ljust(41))
+        msg = prettytable.PrettyTable(
+            header_style='upper', padding_width=5,
+            field_names=['Functest Environment', 'value'])
+        msg.add_row(['INSTALLER', installer_info])
+        msg.add_row(['SCENARIO', scenario])
+        msg.add_row(['POD', node])
         if build_tag:
-            click.echo("|  BUILD TAG: %s|" % build_tag.ljust(41))
-        click.echo("| DEBUG FLAG: %s|" % is_debug.ljust(41))
-        click.echo("+------------------------------------------------------+")
-        click.echo("|     STATUS: %s|" % STATUS.ljust(41))
-        click.echo("+------------------------------------------------------+")
-        click.echo("")
+            msg.add_row(['BUILD TAG', build_tag])
+        msg.add_row(['DEBUG FLAG', is_debug])
+        msg.add_row(['STATUS', STATUS])
+        click.echo(msg.get_string())
 
     def status(self, verbose=True):
         ret_val = 0
-        if not os.path.isfile(CONST.env_active):
+        if not os.path.isfile(CONST.__getattribute__('env_active')):
             if verbose:
                 click.echo("Functest environment is not installed.\n")
             ret_val = 1