From cf36a9d385bf36168d6ac6506e1def0ca30cdcd7 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sat, 20 Nov 2021 16:23:29 -0800 Subject: [PATCH] *: Drop use of module level is_essential flag Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- doc/dev/reference/app_module.rst | 8 -------- plinth/__main__.py | 6 +++--- plinth/middleware.py | 2 +- plinth/module_loader.py | 7 +------ plinth/modules/apache/__init__.py | 5 +---- plinth/modules/avahi/__init__.py | 6 ++---- plinth/modules/backups/__init__.py | 8 +++----- plinth/modules/cockpit/__init__.py | 4 +--- plinth/modules/config/__init__.py | 4 +--- plinth/modules/datetime/__init__.py | 7 ++----- plinth/modules/diagnostics/__init__.py | 7 ++----- plinth/modules/dynamicdns/__init__.py | 4 +--- plinth/modules/firewall/__init__.py | 4 +--- plinth/modules/first_boot/__init__.py | 8 ++++++-- plinth/modules/help/__init__.py | 3 +-- plinth/modules/letsencrypt/__init__.py | 4 +--- plinth/modules/names/__init__.py | 7 ++----- plinth/modules/networks/__init__.py | 4 +--- plinth/modules/power/__init__.py | 4 +--- plinth/modules/privoxy/__init__.py | 2 -- plinth/modules/security/__init__.py | 4 +--- plinth/modules/snapshot/__init__.py | 6 ++---- plinth/modules/ssh/__init__.py | 4 +--- plinth/modules/sso/__init__.py | 4 +--- plinth/modules/storage/__init__.py | 4 +--- plinth/modules/upgrades/__init__.py | 4 +--- plinth/modules/users/__init__.py | 8 +++----- plinth/setup.py | 13 ++++--------- plinth/tests/test_middleware.py | 1 - 29 files changed, 45 insertions(+), 107 deletions(-) diff --git a/doc/dev/reference/app_module.rst b/doc/dev/reference/app_module.rst index 67600e2ee..b1c3b4d26 100644 --- a/doc/dev/reference/app_module.rst +++ b/doc/dev/reference/app_module.rst @@ -16,14 +16,6 @@ are part of the :class:`~plinth.app.Info` component. Need for this attribute at the module level will be removed in the future. -.is_essential -^^^^^^^^^^^^^^^^^^^^^^^^^ - -Optional. If an app must be installed and configured by FreedomBox without user -intervention, this attribute must be set to True. This attribute is part of the -:class:`~plinth.app.Info` component. Need for this attribute at the module level -will be removed in the future. - .version ^^^^^^^^^^^^^^^^^^^^ diff --git a/plinth/__main__.py b/plinth/__main__.py index 500250a59..5c1568d11 100644 --- a/plinth/__main__.py +++ b/plinth/__main__.py @@ -72,10 +72,10 @@ def list_dependencies(module_list): def list_modules(modules_type): """List all/essential/optional modules and exit.""" for module_name, module in module_loader.loaded_modules.items(): - module_is_essential = getattr(module, 'is_essential', False) - if 'essential' in modules_type and not module_is_essential: + is_essential = module.app.info.is_essential + if 'essential' in modules_type and not is_essential: continue - elif 'optional' in modules_type and module_is_essential: + elif 'optional' in modules_type and is_essential: continue print('{module_name}'.format(module_name=module_name)) sys.exit() diff --git a/plinth/middleware.py b/plinth/middleware.py index 9e610160f..fad795eda 100644 --- a/plinth/middleware.py +++ b/plinth/middleware.py @@ -33,7 +33,7 @@ def _collect_setup_result(request, module): exception = module.setup_helper.collect_result() if not exception: - if not setup._is_module_essential(module): + if not module.setup_helper.app.info.is_essential: messages.success(request, _('Application installed.')) else: if isinstance(exception, PackageException): diff --git a/plinth/module_loader.py b/plinth/module_loader.py index 9bbe8cf98..b90dc9388 100644 --- a/plinth/module_loader.py +++ b/plinth/module_loader.py @@ -28,11 +28,6 @@ def include_urls(): _include_module_urls(module_import_path, module_name) -def _is_module_essential(module): - """Return if a module is an essential module.""" - return getattr(module, 'is_essential', False) - - def load_modules(): """ Read names of enabled modules in modules/enabled directory and @@ -54,7 +49,7 @@ def load_modules(): remaining_modules = dict(modules) # Make a copy # Place all essential modules ahead of others in module load order sorted_modules = sorted( - modules, key=lambda module: not _is_module_essential(modules[module])) + modules, key=lambda module: not modules[module].app.info.is_essential) for module_name in sorted_modules: if module_name not in remaining_modules: continue diff --git a/plinth/modules/apache/__init__.py b/plinth/modules/apache/__init__.py index ba49356d7..2057a3699 100644 --- a/plinth/modules/apache/__init__.py +++ b/plinth/modules/apache/__init__.py @@ -17,8 +17,6 @@ from plinth.utils import format_lazy, is_valid_user_name version = 9 -is_essential = True - app = None @@ -32,8 +30,7 @@ class ApacheApp(app_module.App): super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential, - name=_('Apache HTTP Server')) + is_essential=True, name=_('Apache HTTP Server')) self.add(info) packages = Packages('packages-apache', [ diff --git a/plinth/modules/avahi/__init__.py b/plinth/modules/avahi/__init__.py index 32e3e4313..1c91b257e 100644 --- a/plinth/modules/avahi/__init__.py +++ b/plinth/modules/avahi/__init__.py @@ -23,8 +23,6 @@ from . import manifest version = 1 -is_essential = True - depends = ['names'] _description = [ @@ -51,8 +49,8 @@ class AvahiApp(app_module.App): super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - name=_('Service Discovery'), icon='fa-compass', - description=_description, + is_essential=True, name=_('Service Discovery'), + icon='fa-compass', description=_description, manual_page='ServiceDiscovery') self.add(info) diff --git a/plinth/modules/backups/__init__.py b/plinth/modules/backups/__init__.py index 5df5dd14f..00fed229a 100644 --- a/plinth/modules/backups/__init__.py +++ b/plinth/modules/backups/__init__.py @@ -25,8 +25,6 @@ logger = logging.getLogger(__name__) version = 3 -is_essential = True - depends = ['storage'] _description = [ @@ -50,9 +48,9 @@ class BackupsApp(app_module.App): super().__init__() info = app_module.Info( - app_id=self.app_id, version=version, depends=depends, - name=_('Backups'), icon='fa-files-o', description=_description, - manual_page='Backups', + app_id=self.app_id, version=version, is_essential=True, + depends=depends, name=_('Backups'), icon='fa-files-o', + description=_description, manual_page='Backups', donation_url='https://www.borgbackup.org/support/fund.html') self.add(info) diff --git a/plinth/modules/cockpit/__init__.py b/plinth/modules/cockpit/__init__.py index a3f0d160a..4fa128ab3 100644 --- a/plinth/modules/cockpit/__init__.py +++ b/plinth/modules/cockpit/__init__.py @@ -22,8 +22,6 @@ from . import manifest, utils version = 1 -is_essential = True - _description = [ format_lazy( _('Cockpit is a server manager that makes it easy to administer ' @@ -61,7 +59,7 @@ class CockpitApp(app_module.App): super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential, name=_('Cockpit'), + is_essential=True, name=_('Cockpit'), icon='fa-wrench', icon_filename='cockpit', short_description=_('Server Administration'), description=_description, manual_page='Cockpit', diff --git a/plinth/modules/config/__init__.py b/plinth/modules/config/__init__.py index c1c200114..04d4271ce 100644 --- a/plinth/modules/config/__init__.py +++ b/plinth/modules/config/__init__.py @@ -21,8 +21,6 @@ from plinth.signals import domain_added version = 3 -is_essential = True - _description = [ _('Here you can set some general configuration options ' 'like hostname, domain name, webserver home page etc.') @@ -52,7 +50,7 @@ class ConfigApp(app_module.App): """Create components for the app.""" super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential, depends=depends, + is_essential=True, depends=depends, name=_('General Configuration'), icon='fa-cog', description=_description, manual_page='Configure') diff --git a/plinth/modules/datetime/__init__.py b/plinth/modules/datetime/__init__.py index aefdec394..e1e5697d6 100644 --- a/plinth/modules/datetime/__init__.py +++ b/plinth/modules/datetime/__init__.py @@ -16,8 +16,6 @@ from . import manifest version = 2 -is_essential = True - _description = [ _('Network time server is a program that maintains the system time ' 'in synchronization with servers on the Internet.') @@ -63,9 +61,8 @@ class DateTimeApp(app_module.App): super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential, - name=_('Date & Time'), icon='fa-clock-o', - description=_description, + is_essential=True, name=_('Date & Time'), + icon='fa-clock-o', description=_description, manual_page='DateTime') self.add(info) diff --git a/plinth/modules/diagnostics/__init__.py b/plinth/modules/diagnostics/__init__.py index f11476ce2..5db9ec46d 100644 --- a/plinth/modules/diagnostics/__init__.py +++ b/plinth/modules/diagnostics/__init__.py @@ -21,8 +21,6 @@ from . import manifest version = 1 -is_essential = True - _description = [ _('The system diagnostic test will run a number of checks on your ' 'system to confirm that applications and services are working as ' @@ -49,9 +47,8 @@ class DiagnosticsApp(app_module.App): """Create components for the app.""" super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential, - name=_('Diagnostics'), icon='fa-heartbeat', - description=_description, + is_essential=True, name=_('Diagnostics'), + icon='fa-heartbeat', description=_description, manual_page='Diagnostics') self.add(info) diff --git a/plinth/modules/dynamicdns/__init__.py b/plinth/modules/dynamicdns/__init__.py index cf0db265f..8f0e0e1e9 100644 --- a/plinth/modules/dynamicdns/__init__.py +++ b/plinth/modules/dynamicdns/__init__.py @@ -19,8 +19,6 @@ from . import manifest version = 1 -is_essential = True - depends = ['names'] _description = [ @@ -52,7 +50,7 @@ class DynamicDNSApp(app_module.App): super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential, depends=depends, + is_essential=True, depends=depends, name=_('Dynamic DNS Client'), icon='fa-refresh', description=_description, manual_page='DynamicDNS') diff --git a/plinth/modules/firewall/__init__.py b/plinth/modules/firewall/__init__.py index 343f19be5..591615d85 100644 --- a/plinth/modules/firewall/__init__.py +++ b/plinth/modules/firewall/__init__.py @@ -23,8 +23,6 @@ glib = import_from_gi('GLib', '2.0') version = 2 -is_essential = True - _description = [ format_lazy( _('Firewall is a security system that controls the incoming and ' @@ -61,7 +59,7 @@ class FirewallApp(app_module.App): super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential, name=_('Firewall'), + is_essential=True, name=_('Firewall'), icon='fa-shield', description=_description, manual_page='Firewall') self.add(info) diff --git a/plinth/modules/first_boot/__init__.py b/plinth/modules/first_boot/__init__.py index c0b49f751..9bf921766 100644 --- a/plinth/modules/first_boot/__init__.py +++ b/plinth/modules/first_boot/__init__.py @@ -13,8 +13,6 @@ from plinth.signals import post_setup version = 1 -is_essential = True - first_boot_steps = [ { 'id': 'firstboot_welcome', @@ -42,6 +40,12 @@ class FirstBootApp(app.App): def __init__(self): """Create components for the app.""" super().__init__() + + info = app.Info(app_id=self.app_id, version=version, is_essential=True) + self.add(info) + + def post_init(self): + """Perform post initialization operations.""" post_setup.connect(_clear_first_boot_steps) diff --git a/plinth/modules/help/__init__.py b/plinth/modules/help/__init__.py index fa0360537..70ad6fadf 100644 --- a/plinth/modules/help/__init__.py +++ b/plinth/modules/help/__init__.py @@ -13,7 +13,6 @@ from plinth import cfg, menu, web_server version = 1 -is_essential = True app = None @@ -27,7 +26,7 @@ class HelpApp(app_module.App): super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential) + is_essential=True) self.add(info) menu_item = menu.Menu('menu-help', _('Documentation'), None, 'fa-book', diff --git a/plinth/modules/letsencrypt/__init__.py b/plinth/modules/letsencrypt/__init__.py index 8c1cacd51..feaa5d3e6 100644 --- a/plinth/modules/letsencrypt/__init__.py +++ b/plinth/modules/letsencrypt/__init__.py @@ -25,8 +25,6 @@ from . import components, manifest version = 3 -is_essential = True - depends = ['names'] _description = [ @@ -61,7 +59,7 @@ class LetsEncryptApp(app_module.App): super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential, depends=depends, + is_essential=True, depends=depends, name=_('Let\'s Encrypt'), icon='fa-lock', short_description=_('Certificates'), description=_description, diff --git a/plinth/modules/names/__init__.py b/plinth/modules/names/__init__.py index 7ca071ceb..8b4093fcb 100644 --- a/plinth/modules/names/__init__.py +++ b/plinth/modules/names/__init__.py @@ -17,8 +17,6 @@ from . import components, manifest version = 1 -is_essential = True - logger = logging.getLogger(__name__) _description = [ @@ -42,9 +40,8 @@ class NamesApp(app_module.App): """Create components for the app.""" super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential, - name=_('Name Services'), icon='fa-tags', - description=_description, + is_essential=True, name=_('Name Services'), + icon='fa-tags', description=_description, manual_page='NameServices') self.add(info) diff --git a/plinth/modules/networks/__init__.py b/plinth/modules/networks/__init__.py index 6f9be36db..0e04889b1 100644 --- a/plinth/modules/networks/__init__.py +++ b/plinth/modules/networks/__init__.py @@ -16,8 +16,6 @@ from plinth.package import Packages version = 1 -is_essential = True - first_boot_steps = [ { 'id': 'network_topology_wizard', @@ -58,7 +56,7 @@ class NetworksApp(app_module.App): super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential, name=_('Networks'), + is_essential=True, name=_('Networks'), icon='fa-signal', description=_description, manual_page='Networks') self.add(info) diff --git a/plinth/modules/power/__init__.py b/plinth/modules/power/__init__.py index 006ba71ea..d1faadd43 100644 --- a/plinth/modules/power/__init__.py +++ b/plinth/modules/power/__init__.py @@ -12,8 +12,6 @@ from . import manifest version = 1 -is_essential = True - _description = [_('Restart or shut down the system.')] app = None @@ -29,7 +27,7 @@ class PowerApp(app_module.App): super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential, name=_('Power'), + is_essential=True, name=_('Power'), description=_description, manual_page='Power') self.add(info) diff --git a/plinth/modules/privoxy/__init__.py b/plinth/modules/privoxy/__init__.py index ee256a55e..8dd1d5c08 100644 --- a/plinth/modules/privoxy/__init__.py +++ b/plinth/modules/privoxy/__init__.py @@ -21,8 +21,6 @@ from . import manifest version = 1 -is_essential = False - _description = [ _('Privoxy is a non-caching web proxy with advanced filtering ' 'capabilities for enhancing privacy, modifying web page data and ' diff --git a/plinth/modules/security/__init__.py b/plinth/modules/security/__init__.py index b98f7e3cc..13f884879 100644 --- a/plinth/modules/security/__init__.py +++ b/plinth/modules/security/__init__.py @@ -20,8 +20,6 @@ from . import manifest version = 7 -is_essential = True - ACCESS_CONF_FILE = '/etc/security/access.d/50freedombox.conf' ACCESS_CONF_FILE_OLD = '/etc/security/access.conf' ACCESS_CONF_SNIPPET = '-:ALL EXCEPT root fbx plinth (admin) (sudo):ALL' @@ -41,7 +39,7 @@ class SecurityApp(app_module.App): super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential, name=_('Security'), + is_essential=True, name=_('Security'), icon='fa-lock', manual_page='Security') self.add(info) diff --git a/plinth/modules/snapshot/__init__.py b/plinth/modules/snapshot/__init__.py index 9a48f2f9f..144759124 100644 --- a/plinth/modules/snapshot/__init__.py +++ b/plinth/modules/snapshot/__init__.py @@ -20,8 +20,6 @@ from . import manifest version = 4 -is_essential = True - _description = [ _('Snapshots allows creating and managing btrfs file system snapshots. ' 'These can be used to roll back the system to a previously known ' @@ -53,8 +51,8 @@ class SnapshotApp(app_module.App): super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - name=_('Storage Snapshots'), icon='fa-film', - description=_description, + is_essential=True, name=_('Storage Snapshots'), + icon='fa-film', description=_description, manual_page='Snapshots') self.add(info) diff --git a/plinth/modules/ssh/__init__.py b/plinth/modules/ssh/__init__.py index 7b6bcd272..d199c08b0 100644 --- a/plinth/modules/ssh/__init__.py +++ b/plinth/modules/ssh/__init__.py @@ -21,8 +21,6 @@ from . import manifest version = 1 -is_essential = True - _description = [ _('A Secure Shell server uses the secure shell protocol to accept ' 'connections from remote computers. An authorized remote computer ' @@ -43,7 +41,7 @@ class SSHApp(app_module.App): super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential, + is_essential=True, name=_('Secure Shell (SSH) Server'), icon='fa-terminal', description=_description) self.add(info) diff --git a/plinth/modules/sso/__init__.py b/plinth/modules/sso/__init__.py index 049e92a88..6dd5ebf2b 100644 --- a/plinth/modules/sso/__init__.py +++ b/plinth/modules/sso/__init__.py @@ -11,8 +11,6 @@ from plinth.package import Packages version = 1 -is_essential = True - depends = ['security', 'apache'] app = None @@ -27,7 +25,7 @@ class SSOApp(app_module.App): super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential, depends=depends, + is_essential=True, depends=depends, name=_('Single Sign On')) self.add(info) diff --git a/plinth/modules/storage/__init__.py b/plinth/modules/storage/__init__.py index 062ed5b03..855f868e4 100644 --- a/plinth/modules/storage/__init__.py +++ b/plinth/modules/storage/__init__.py @@ -33,8 +33,6 @@ _description = [ logger = logging.getLogger(__name__) -is_essential = True - app = None @@ -50,7 +48,7 @@ class StorageApp(app_module.App): super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential, name=_('Storage'), + is_essential=True, name=_('Storage'), icon='fa-hdd-o', description=_description, manual_page='Storage') self.add(info) diff --git a/plinth/modules/upgrades/__init__.py b/plinth/modules/upgrades/__init__.py index 34c879297..6e92bf25f 100644 --- a/plinth/modules/upgrades/__init__.py +++ b/plinth/modules/upgrades/__init__.py @@ -24,8 +24,6 @@ from . import manifest version = 9 -is_essential = True - first_boot_steps = [ { 'id': 'backports_wizard', @@ -73,7 +71,7 @@ class UpgradesApp(app_module.App): super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential, name=_('Update'), + is_essential=True, name=_('Update'), icon='fa-refresh', description=_description, manual_page='Upgrades') self.add(info) diff --git a/plinth/modules/users/__init__.py b/plinth/modules/users/__init__.py index 908cae761..7abb6e719 100644 --- a/plinth/modules/users/__init__.py +++ b/plinth/modules/users/__init__.py @@ -19,8 +19,6 @@ from .components import UsersAndGroups version = 3 -is_essential = True - first_boot_steps = [ { 'id': 'users_firstboot', @@ -56,9 +54,9 @@ class UsersApp(app_module.App): super().__init__() info = app_module.Info(app_id=self.app_id, version=version, - is_essential=is_essential, - name=_('Users and Groups'), icon='fa-users', - description=_description, manual_page='Users') + is_essential=True, name=_('Users and Groups'), + icon='fa-users', description=_description, + manual_page='Users') self.add(info) menu_item = menu.Menu('menu-users', info.name, None, info.icon, diff --git a/plinth/setup.py b/plinth/setup.py index cd5647925..4f24ae4e7 100644 --- a/plinth/setup.py +++ b/plinth/setup.py @@ -145,7 +145,7 @@ def setup_modules(module_list=None, essential=False, allow_install=True): 'Running setup for modules, essential - %s, ' 'selected modules - %s', essential, module_list) for module_name, module in plinth.module_loader.loaded_modules.items(): - if essential and not _is_module_essential(module): + if essential and not module.app.info.is_essential: continue if module_list and module_name not in module_list: @@ -159,7 +159,7 @@ def list_dependencies(module_list=None, essential=False): for module_import_path in plinth.module_loader.get_modules_to_load(): module_name = module_import_path.split('.')[-1] module = importlib.import_module(module_import_path) - if essential and not _is_module_essential(module): + if essential and not module.app.info.is_essential: continue if module_list and module_name not in module_list and \ @@ -227,7 +227,7 @@ def _get_modules_for_regular_setup(): 1. essential modules that are not up-to-date 2. non-essential modules that are installed and need updates """ - if (_is_module_essential(module) and module.app.get_setup_state() != + if (module.app.info.is_essential and module.app.get_setup_state() != app_module.App.SetupState.UP_TO_DATE): return True @@ -240,18 +240,13 @@ def _get_modules_for_regular_setup(): return [name for name, module in all_modules if is_setup_required(module)] -def _is_module_essential(module): - """Return if a module is an essential module.""" - return getattr(module, 'is_essential', False) - - def _set_is_first_setup(): """Set whether all essential modules have been setup at least once.""" global _is_first_setup modules = plinth.module_loader.loaded_modules.values() _is_first_setup = any( (module for module in modules - if _is_module_essential(module) and module.app.needs_setup())) + if module.app.info.is_essential and module.app.needs_setup())) def run_setup_on_modules(module_list, allow_install=True): diff --git a/plinth/tests/test_middleware.py b/plinth/tests/test_middleware.py index 29a0bbe74..ff1e80fb8 100644 --- a/plinth/tests/test_middleware.py +++ b/plinth/tests/test_middleware.py @@ -129,7 +129,6 @@ class TestSetupMiddleware: """Test that module installation result is collected properly.""" resolve.return_value.namespaces = ['mockapp'] module = Mock() - module.is_essential = False module.setup_helper.is_finished = True module.setup_helper.collect_result.return_value = None module.app.get_setup_state.return_value = \