summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-04-30 22:41:46 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-05-08 03:59:38 +0900
commita542c81858d94e0be06216184f3df61600805138 (patch)
treebff29d005308c8db3f39851a1841c503ea3b8c0a
parentc81fb2dabb89a5a443fe5d9bbf8a2c19f45ac276 (diff)
downloadbuildstream-a542c81858d94e0be06216184f3df61600805138.tar.gz
_frontend/app.py: Remove partially_initialized()
There is no more need for this distinction.
-rw-r--r--buildstream/_frontend/app.py109
1 files changed, 42 insertions, 67 deletions
diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py
index 50787b1ec..58a8eab89 100644
--- a/buildstream/_frontend/app.py
+++ b/buildstream/_frontend/app.py
@@ -126,19 +126,33 @@ class App():
# Set soft limit to hard limit
resource.setrlimit(resource.RLIMIT_NOFILE, (limits[1], limits[1]))
- # partially_initialized()
+ # initialized()
+ #
+ # Context manager to initialize the application and optionally run a session
+ # within the context manager.
+ #
+ # This context manager will take care of catching errors from within the
+ # context and report them consistently, so the CLI need not take care of
+ # reporting the errors and exiting with a consistent error status.
#
- # Early stage initialization context manager which only initializes the
- # Context, Project and the logger.
+ # Args:
+ # session_name (str): The name of the session, or None for no session
+ #
+ # Note that the except_ argument may have a subtly different meaning depending
+ # on the activity performed on the Pipeline. In normal circumstances the except_
+ # argument excludes elements from the `elements` list. In a build session, the
+ # except_ elements are excluded from the tracking plan.
#
- # partial initialization is useful for some contexts where we dont
- # want to load the pipeline, such as executing workspace commands.
+ # If a session_name is provided, we treat the block as a session, and print
+ # the session header and summary, and time the main session from startup time.
#
@contextmanager
- def partially_initialized(self):
+ def initialized(self, *, session_name=None):
directory = self._main_options['directory']
config = self._main_options['config']
+ self._session_name = session_name
+
#
# Load the Context
#
@@ -220,77 +234,38 @@ class App():
# we can override the global exception hook.
sys.excepthook = self._global_exception_handler
+ # Mark the beginning of the session
+ if session_name:
+ self._message(MessageType.START, session_name)
+
+ # XXX This is going to change soon !
+ #
+ self.stream._scheduler = self.scheduler
+
# Run the body of the session here, once everything is loaded
try:
yield
except BstError as e:
- self._error_exit(e)
- # initialized()
- #
- # Context manager to initialize the application and optionally run a session
- # within the context manager.
- #
- # This context manager will take care of catching errors from within the
- # context and report them consistently, so the CLI need not take care of
- # reporting the errors and exiting with a consistent error status.
- #
- # Args:
- # session_name (str): The name of the session, or None for no session
- #
- # Note that the except_ argument may have a subtly different meaning depending
- # on the activity performed on the Pipeline. In normal circumstances the except_
- # argument excludes elements from the `elements` list. In a build session, the
- # except_ elements are excluded from the tracking plan.
- #
- # If a session_name is provided, we treat the block as a session, and print
- # the session header and summary, and time the main session from startup time.
- #
- @contextmanager
- def initialized(self, *, session_name=None):
-
- self._session_name = session_name
-
- # Start with the early stage init, this enables logging right away
- with self.partially_initialized():
-
- # Mark the beginning of the session
+ # Print a nice summary if this is a session
if session_name:
- self._message(MessageType.START, session_name)
-
- # XXX This is going to change soon !
- #
- self.stream._scheduler = self.scheduler
-
- # XXX Print the heading
- #
- # WE NEED A STREAM CALLBACK FOR POST LOAD SESSION START
- #
- # if session_name:
- # self._print_heading()
+ elapsed = self.scheduler.elapsed_time()
- # Run the body of the session here, once everything is loaded
- try:
- yield
- except BstError as e:
+ if isinstance(e, StreamError) and e.terminated: # pylint: disable=no-member
+ self._message(MessageType.WARN, session_name + ' Terminated', elapsed=elapsed)
+ else:
+ self._message(MessageType.FAIL, session_name, elapsed=elapsed)
- if session_name:
- elapsed = self.scheduler.elapsed_time()
+ self._print_summary()
- if isinstance(e, StreamError) and e.terminated: # pylint: disable=no-member
- self._message(MessageType.WARN, session_name + ' Terminated', elapsed=elapsed)
- else:
- self._message(MessageType.FAIL, session_name, elapsed=elapsed)
-
- self._print_summary()
+ # Exit with the error
+ self._error_exit(e)
- # Let the outer context manager print the error and exit
- raise
- else:
- # No exceptions occurred, print session time and summary
- if session_name:
- self._message(MessageType.SUCCESS, session_name, elapsed=self.scheduler.elapsed_time())
- self._print_summary()
+ else:
+ # No exceptions occurred, print session time and summary
+ if session_name:
+ self._message(MessageType.SUCCESS, session_name, elapsed=self.scheduler.elapsed_time())
+ self._print_summary()
# init_project()
#