app: Add unique ID to each app class

Also maintain a global list of apps

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2019-05-31 11:44:14 -07:00 committed by James Valleroy
parent e55a85bdd1
commit 46f162d093
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
53 changed files with 141 additions and 5 deletions

View File

@ -31,10 +31,24 @@ class App:
"""
app_id = None
_all_apps = collections.OrderedDict()
def __init__(self):
"""Initialize the app object."""
if not self.app_id:
raise ValueError('Invalid app ID configured')
self.components = collections.OrderedDict()
# Add self to global list of apps
self._all_apps[self.app_id] = self
@classmethod
def get(cls, app_id):
"""Return an app with given ID."""
return cls._all_apps[app_id]
def add(self, component):
"""Add a component to an app."""
self.components[component.component_id] = component

View File

@ -38,6 +38,8 @@ app = None
class ApacheApp(app_module.App):
"""FreedomBox app for Apache web server."""
app_id = 'apache'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -63,6 +63,8 @@ app = None
class AvahiApp(app_module.App):
"""FreedomBox app for Avahi."""
app_id = 'avahi'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -59,6 +59,8 @@ app = None
class BackupsApp(app_module.App):
"""FreedomBox app for backup and restore."""
app_id = 'backups'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -90,6 +90,8 @@ app = None
class BindApp(app_module.App):
"""FreedomBox app for Bind."""
app_id = 'bind'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -68,6 +68,8 @@ app = None
class CockpitApp(app_module.App):
"""FreedomBox app for Cockpit."""
app_id = 'cockpit'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -53,6 +53,8 @@ app = None
class ConfigApp(app_module.App):
"""FreedomBox app for basic system configuration."""
app_id = 'config'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -61,6 +61,8 @@ app = None
class CoquelicotApp(app_module.App):
"""FreedomBox app for Coquelicot."""
app_id = 'coquelicot'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -53,6 +53,8 @@ app = None
class DateTimeApp(app_module.App):
"""FreedomBox app for date and time."""
app_id = 'datetime'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -64,6 +64,8 @@ app = None
class DelugeApp(app_module.App):
"""FreedomBox app for Deluge."""
app_id = 'deluge'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -46,6 +46,8 @@ app = None
class DiagnosticsApp(app_module.App):
"""FreedomBox app for diagnostics."""
app_id = 'diagnostics'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -81,6 +81,8 @@ app = None
class DiasporaApp(app_module.App):
"""FreedomBox app for Diaspora."""
app_id = 'diaspora'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -64,6 +64,8 @@ app = None
class DynamicDNSApp(app_module.App):
"""FreedomBox app for Dynamic DNS."""
app_id = 'dynamicdns'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -81,6 +81,8 @@ app = None
class EjabberdApp(app_module.App):
"""FreedomBox app for ejabberd."""
app_id = 'ejabberd'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -53,6 +53,8 @@ app = None
class FirewallApp(app_module.App):
"""FreedomBox app for Firewall."""
app_id = 'firewall'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -38,6 +38,8 @@ app = None
class HelpApp(app_module.App):
"""FreedomBox app for showing help."""
app_id = 'help'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -80,6 +80,8 @@ app = None
class I2PApp(app_module.App):
"""FreedomBox app for I2P."""
app_id = 'i2p'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -72,6 +72,8 @@ app = None
class IkiwikiApp(app_module.App):
"""FreedomBox app for Ikiwiki."""
app_id = 'ikiwiki'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -62,6 +62,8 @@ app = None
class InfinotedApp(app_module.App):
"""FreedomBox app for infinoted."""
app_id = 'infinoted'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -55,6 +55,8 @@ app = None
class JSXCApp(app_module.App):
"""FreedomBox app for JSXC."""
app_id = 'jsxc'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -74,6 +74,8 @@ app = None
class LetsEncryptApp(app_module.App):
"""FreedomBox app for Let's Encrypt."""
app_id = 'letsencrypt'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -77,6 +77,8 @@ app = None
class MatrixSynapseApp(app_module.App):
"""FreedomBox app for Matrix Synapse."""
app_id = 'matrixsynapse'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -64,6 +64,8 @@ app = None
class MediaWikiApp(app_module.App):
"""FreedomBox app for MediaWiki."""
app_id = 'mediawiki'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -81,6 +81,8 @@ app = None
class MinetestApp(app_module.App):
"""FreedomBox app for Minetest."""
app_id = 'minetest'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -70,6 +70,8 @@ app = None
class MLDonkeyApp(app_module.App):
"""FreedomBox app for MLDonkey."""
app_id = 'mldonkey'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -60,6 +60,8 @@ app = None
class MonkeysphereApp(app_module.App):
"""FreedomBox app for Monkeysphere."""
app_id = 'monkeysphere'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -67,6 +67,8 @@ app = None
class MumbleApp(app_module.App):
"""FreedomBox app for Mumble."""
app_id = 'mumble'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -63,6 +63,8 @@ app = None
class NamesApp(app_module.App):
"""FreedomBox app for names."""
app_id = 'names'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -45,6 +45,8 @@ app = None
class NetworksApp(app_module.App):
"""FreedomBox app for Networks."""
app_id = 'networks'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -63,6 +63,8 @@ app = None
class OpenVPNApp(app_module.App):
"""FreedomBox app for OpenVPN."""
app_id = 'openvpn'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -82,6 +82,8 @@ app = None
class PagekiteApp(app_module.App):
"""FreedomBox app for Pagekite."""
app_id = 'pagekite'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -70,6 +70,8 @@ app = None
class PrivoxyApp(app_module.App):
"""FreedomBox app for Privoxy."""
app_id = 'privoxy'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -73,6 +73,8 @@ app = None
class QuasselApp(app_module.App):
"""FreedomBox app for Quassel."""
app_id = 'quassel'
def __init__(self):
"""Create components for the app."""
super().__init__()
@ -88,8 +90,8 @@ class QuasselApp(app_module.App):
login_required=True)
self.add(shortcut)
firewall = Firewall('firewall-quassel', name,
ports=['quassel-plinth'], is_external=True)
firewall = Firewall('firewall-quassel', name, ports=['quassel-plinth'],
is_external=True)
self.add(firewall)

View File

@ -78,6 +78,8 @@ app = None
class RadicaleApp(app_module.App):
"""FreedomBox app for Radicale."""
app_id = 'radicale'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -76,6 +76,8 @@ app = None
class ReproApp(app_module.App):
"""FreedomBox app for Repro."""
app_id = 'repro'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -62,6 +62,8 @@ app = None
class RestoreApp(app_module.App):
"""FreedomBox app for Restore."""
app_id = 'restore'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -69,6 +69,8 @@ app = None
class RoundcubeApp(app_module.App):
"""FreedomBox app for Roundcube."""
app_id = 'roundcube'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -63,6 +63,8 @@ app = None
class SearxApp(app_module.App):
"""FreedomBox app for Searx."""
app_id = 'searx'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -50,6 +50,8 @@ app = None
class SecurityApp(app_module.App):
"""FreedomBox app for security."""
app_id = 'security'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -56,6 +56,8 @@ app = None
class ShaarliApp(app_module.App):
"""FreedomBox app for Shaarli."""
app_id = 'shaarli'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -64,6 +64,8 @@ app = None
class ShadowsocksApp(app_module.App):
"""FreedomBox app for Shadowsocks."""
app_id = 'shadowsocks'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -46,6 +46,8 @@ app = None
class SharingApp(app_module.App):
"""FreedomBox app for sharing files."""
app_id = 'sharing'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -64,6 +64,8 @@ app = None
class SnapshotApp(app_module.App):
"""FreedomBox app for snapshots."""
app_id = 'snapshot'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -56,6 +56,8 @@ app = None
class SSHApp(app_module.App):
"""FreedomBox app for SSH."""
app_id = 'ssh'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -61,6 +61,8 @@ app = None
class StorageApp(app_module.App):
"""FreedomBox app for storage."""
app_id = 'storage'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -73,6 +73,8 @@ app = None
class SyncthingApp(app_module.App):
"""FreedomBox app for Syncthing."""
app_id = 'syncthing'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -66,6 +66,8 @@ app = None
class TahoeApp(app_module.App):
"""FreedomBox app for Tahoe LAFS."""
app_id = 'tahoe'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -69,6 +69,8 @@ app = None
class TorApp(app_module.App):
"""FreedomBox app for Tor."""
app_id = 'tor'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -65,6 +65,8 @@ app = None
class TransmissionApp(app_module.App):
"""FreedomBox app for Transmission."""
app_id = 'transmission'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -72,6 +72,8 @@ app = None
class TTRSSApp(app_module.App):
"""FreedomBox app for TT-RSS."""
app_id = 'ttrss'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -49,6 +49,8 @@ app = None
class UpgradesApp(app_module.App):
"""FreedomBox app for software upgrades."""
app_id = 'upgrades'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -54,6 +54,8 @@ app = None
class UsersApp(app_module.App):
"""FreedomBox app for users and groups management."""
app_id = 'users'
def __init__(self):
"""Create components for the app."""
super().__init__()

View File

@ -25,6 +25,11 @@ import pytest
from plinth.app import App, Component, FollowerComponent, LeaderComponent
class TestApp(App):
"""Sample App for testing."""
app_id = 'test-app'
class LeaderTest(FollowerComponent):
"""Test class for using LeaderComponent in tests."""
is_leader = True
@ -33,7 +38,7 @@ class LeaderTest(FollowerComponent):
@pytest.fixture(name='app_with_components')
def fixture_app_with_components():
"""Setup an app with some components."""
app = App()
app = TestApp()
app.add(FollowerComponent('test-follower-1'))
app.add(FollowerComponent('test-follower-2'))
app.add(LeaderTest('test-leader-1'))
@ -41,16 +46,31 @@ def fixture_app_with_components():
return app
@pytest.fixture(name='empty_apps', autouse=True)
def fixture_empty_apps():
"""Remove all apps from global list before starting a test."""
App._all_apps = collections.OrderedDict()
def test_app_instantiation():
"""Test that App is instantiated properly."""
app = App()
app = TestApp()
assert isinstance(app.components, collections.OrderedDict)
assert not app.components
assert app.app_id == 'test-app'
assert app._all_apps['test-app'] == app
assert len(app._all_apps) == 1
def test_get():
"""Test that an app can be correctly retrieved."""
app = TestApp()
assert App.get(app.app_id) == app
def test_app_add():
"""Test adding a components to an App."""
app = App()
app = TestApp()
component = Component('test-component')
return_value = app.add(component)
assert len(app.components) == 1