app: Introduce separate method for post initialization operations

During __init__, only component building must be done. All other operations go
in to post_init(). This allows for cleaner initialization from various
scenarios which simply have to query the app instead of fully initializing it.

Tests:

- None.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2021-11-14 12:13:25 -08:00 committed by James Valleroy
parent bdb239c72e
commit 1147249bd8
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -41,7 +41,15 @@ class App:
_all_apps = collections.OrderedDict()
def __init__(self):
"""Initialize the app object."""
"""Build the app by adding components.
App may be built just for the purpose for querying. For example, when
querying the list of package dependencies of essential apps, an app is
minimally constructed under a read-only environment for querying from a
specific component. So, this operation should have no side-effects such
connecting to signals, running configuration corrections and scheduling
operations.
"""
if not self.app_id:
raise ValueError('Invalid app ID configured')
@ -50,6 +58,14 @@ class App:
# Add self to global list of apps
self._all_apps[self.app_id] = self
def post_init(self):
"""Perform post initialization operations.
Additional initialization operations such as connecting to signals,
running configuration corrections and scheduling operations should be
done in this method rather than in __init__().
"""
@classmethod
def get(cls, app_id):
"""Return an app with given ID."""