From 1147249bd8d03de1d0a698cd642d003f06f585f7 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 14 Nov 2021 12:13:25 -0800 Subject: [PATCH] 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 Reviewed-by: James Valleroy --- plinth/app.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/plinth/app.py b/plinth/app.py index 08ed15ade..b93853b1e 100644 --- a/plinth/app.py +++ b/plinth/app.py @@ -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."""