From 80102f9ad885f937e5ee559546c1914d0d67917e Mon Sep 17 00:00:00 2001
From: Vaclav Pavlin <vpavlin@redhat.com>
Date: Thu, 28 May 2015 10:35:34 +0200
Subject: [PATCH] Fix rest API feature

---
 atomicapp/cli/main.py | 12 ++++++++----
 atomicapp/install.py  |  7 +++----
 atomicapp/run.py      |  4 +++-
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/atomicapp/cli/main.py b/atomicapp/cli/main.py
index dcc8f7b..bbccf4c 100755
--- a/atomicapp/cli/main.py
+++ b/atomicapp/cli/main.py
@@ -6,7 +6,9 @@ import os
 from argparse import ArgumentParser
 from argparse import RawDescriptionHelpFormatter
 import logging
-import anymarkup #FIXME
+from atomicapp.rest import Rest
+from atomicapp import context
+import threading
 
 from atomicapp import set_logging
 from atomicapp.constants import ANSWERS_FILE, __ATOMICAPPVERSION__, __NULECULESPECVERSION__
@@ -16,11 +18,12 @@ logger = logging.getLogger(__name__)
 def cli_install(args):
     install = Install(**vars(args))
     install.install()
-    atomicapp.context.globalCtx.addStatus("Install Successful." ,status_type="COMPLETED")
+    context.globalCtx.addStatus("Install Successful." ,status_type="COMPLETED")
 
 def cli_run(args):
     ae = Run(**vars(args))
     ae.run()
+    context.globalCtx.addStatus("Run Successful." ,status_type="COMPLETED")
 
 def cli_stop(args):
     stop = Run(stop = True, **vars(args))
@@ -82,6 +85,7 @@ class CLI():
         except KeyboardInterrupt:
             pass
         except Exception as ex:
+            context.globalCtx.addStatus("Exception raised: %s" % ex ,status_type="ERROR")
             if args.verbose:
                 raise
             else:
@@ -91,7 +95,7 @@ class CLI():
 
 
 def main():
-    atomicapp.context.globalCtx = atomicapp.context.Config(False)
+    context.globalCtx = context.Config(False)
     cli = CLI()
     cargs = cli.get_args()
     if cargs.daemon:
@@ -102,7 +106,7 @@ def main():
         cli.run(cargs)
 
 def start_restapp(debug, port):
-    rest = atomicapp.rest.Rest()
+    rest = Rest()
     rest.run(debug, port)
 
 if __name__ == '__main__':
diff --git a/atomicapp/install.py b/atomicapp/install.py
index c1ef357..0f34e70 100644
--- a/atomicapp/install.py
+++ b/atomicapp/install.py
@@ -15,7 +15,6 @@ logger = logging.getLogger(__name__)
 
 class Install(object):
     dryrun = False
-    params = None
     answers_file = None
 
     def __init__(self, answers, APP, nodeps = False, update = False, target_path = None, dryrun = False, **kwargs):
@@ -86,7 +85,7 @@ class Install(object):
 
     def install(self):
         self.nulecule_base.loadAnswers(self.answers_file)
-        context.globalCtx.addStatus("loading answers.conf", answerContent)
+        context.globalCtx.addStatus("loading answers.conf", self.nulecule_base.answers_data)
 
         if self.nulecule_base.app_path and not self.nulecule_base.target_path == self.nulecule_base.app_path:
             logger.info("Copying content of directory %s to %s", self.nulecule_base.app_path, self.nulecule_base.target_path)
@@ -101,7 +100,7 @@ class Install(object):
             logger.debug("%s path for pulled image: %s", MAIN_FILE, mainfile_path)
             self.nulecule_base.loadMainfile(mainfile_path)
             logger.debug("App ID: %s", self.nulecule_base.app_id)
-            context.globalCtx.setAppId(self.params.app_id)
+            context.globalCtx.setAppId(self.nulecule_base.app_id)
 
             self._populateApp()
         else:
@@ -126,7 +125,7 @@ class Install(object):
         if self.nulecule_base.write_sample_answers:
             self.nulecule_base.writeAnswersSample()
 
-        context.globalCtx.addStatus("answers.conf updated", answerContent)
+        context.globalCtx.addStatus("answers.conf updated", self.nulecule_base.answers_data)
         return values
 
     def _installDependencies(self):
diff --git a/atomicapp/run.py b/atomicapp/run.py
index 6375f55..3a4a2f8 100644
--- a/atomicapp/run.py
+++ b/atomicapp/run.py
@@ -10,6 +10,7 @@ from utils import Utils
 from constants import GLOBAL_CONF, DEFAULT_PROVIDER, MAIN_FILE
 from plugin import Plugin, ProviderFailedException
 from install import Install
+import context
 
 logger = logging.getLogger(__name__)
 
@@ -62,6 +63,7 @@ class Run(object):
                 self.app_path = os.getcwd()
             install = Install(answers, APP, dryrun = dryrun, target_path = self.app_path)
             install.install()
+            context.globalCtx.addStatus("Install Successful." ,status_type="INSTALLED")
 
         self.nulecule_base = Nulecule_Base(target_path=self.app_path)
         if "ask" in kwargs:
@@ -172,7 +174,7 @@ class Run(object):
                 provider.deploy()
         except ProviderFailedException as ex:
             logger.error(ex)
-            sys.exit(1)
+            raise
 
     def run(self):
         self.nulecule_base.loadMainfile(os.path.join(self.nulecule_base.target_path, MAIN_FILE))
-- 
2.1.0

