Make app names as module identifiers

- The last part of the module import path is the module name.  This also
  becomes the Django app name.  Apps names have to be unique.  Hence,
  there is no scope for two different modules with same name but
  different load path to exist in the project.

- Most uses of list of loaded modules are dealing with app names instead
  of full module load path.  This is due to the fact that Django deals
  with app names and not module paths.

- It is also somewhat clumsy to access a loaded module as we are
  re-importing every time to get access module.

- Simplify all of the above by using app names are module identifiers
  and maintaing an ordered dictionary of app names to loadded modules.

- Remove unused imports.

- Minor styling fixes.
This commit is contained in:
Sunil Mohan Adapa committed 2016-02-13 13:49:23 +05:30
1 parent 3e2c84dba2
commit 7f4c5f7410
32 files changed
+61 -91

No files matched your search

+1 -3
View File
@@ -20,16 +20,14 @@ Plinth module for service discovery.
"""
from django.utils.translation import ugettext_lazy as _
import subprocess
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
# pylint: disable=C0103
depends = ['plinth.modules.system']
depends = ['system']
service = None
+1 -3
View File
@@ -24,6 +24,4 @@ from .config import init
__all__ = ['config', 'init']
depends = ['plinth.modules.system',
'plinth.modules.firewall',
'plinth.modules.names']
depends = ['system', 'firewall', 'names']
+1 -1
View File
@@ -19,7 +19,7 @@
URLs for the Configuration module
"""
from django.conf.urls import patterns, url
from django.conf.urls import url
from . import config as views
+1 -2
View File
@@ -22,13 +22,12 @@ Plinth module to configure system date and time
from django.utils.translation import ugettext_lazy as _
import subprocess
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
depends = ['plinth.modules.system']
depends = ['system']
service = None
+1 -2
View File
@@ -21,13 +21,12 @@ Plinth module to configure a Deluge web client.
from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
depends = ['plinth.modules.apps']
depends = ['apps']
service = None
+1 -1
View File
@@ -25,7 +25,7 @@ from plinth import action_utils
__all__ = ['diagnostics', 'init']
depends = ['plinth.modules.system']
depends = ['system']
def diagnose():
+10 -17
View File
@@ -60,19 +60,14 @@ def index(request):
@require_POST
def module(request, module_name):
"""Return diagnostics for a particular module."""
found = False
for module_import_path in module_loader.loaded_modules:
if module_name == module_import_path.split('.')[-1]:
found = True
break
if not found:
try:
module = module_loader.loaded_modules[module_name]
except KeyError:
raise Http404('Module does not exist or not loaded')
loaded_module = importlib.import_module(module_import_path)
results = []
if hasattr(loaded_module, 'diagnose'):
results = loaded_module.diagnose()
if hasattr(module, 'diagnose'):
results = module.diagnose()
return TemplateResponse(request, 'diagnostics_module.html',
{'title': _('Diagnostic Test'),
@@ -110,17 +105,15 @@ def run_on_all_modules():
'progress_percentage': 0}
modules = []
for module_import_path in module_loader.loaded_modules:
loaded_module = importlib.import_module(module_import_path)
if not hasattr(loaded_module, 'diagnose'):
for module_name, module in module_loader.loaded_modules.items():
if not hasattr(module, 'diagnose'):
continue
module_name = module_import_path.split('.')[-1]
modules.append((module_name, loaded_module))
modules.append((module_name, module))
current_results['results'][module_name] = None
current_results['modules'] = modules
for current_index, (module_name, loaded_module) in enumerate(modules):
current_results['results'][module_name] = loaded_module.diagnose()
for current_index, (module_name, module) in enumerate(modules):
current_results['results'][module_name] = module.diagnose()
current_results['progress_percentage'] = \
int((current_index + 1) * 100 / len(modules))
+1 -1
View File
@@ -24,4 +24,4 @@ from .dynamicdns import init
__all__ = ['dynamicdns', 'init']
depends = ['plinth.modules.apps']
depends = ['apps']
+1 -1
View File
@@ -24,4 +24,4 @@ from .firewall import init
__all__ = ['firewall', 'init']
depends = ['plinth.modules.system']
depends = ['system']
+1 -2
View File
@@ -21,13 +21,12 @@ Plinth module to configure ikiwiki
from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
depends = ['plinth.modules.apps']
depends = ['apps']
service = None
+1 -7
View File
@@ -20,19 +20,13 @@ Plinth module for using Let's Encrypt.
"""
from django.utils.translation import ugettext_lazy as _
import json
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
from plinth.modules import names
depends = [
'plinth.modules.apps',
'plinth.modules.names'
]
depends = ['apps', 'names']
service = None
+1 -1
View File
@@ -23,7 +23,7 @@ from django.utils.translation import ugettext_lazy as _
from plinth import cfg
depends = ['plinth.modules.system']
depends = ['system']
def init():
+1 -2
View File
@@ -21,13 +21,12 @@ Plinth module to configure Mumble server
from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
depends = ['plinth.modules.apps']
depends = ['apps']
service = None
+1 -1
View File
@@ -31,7 +31,7 @@ SERVICES = (
('ssh', _('SSH'), 22),
)
depends = ['plinth.modules.system']
depends = ['system']
domain_types = {}
domains = {}
+1 -1
View File
@@ -31,7 +31,7 @@ from plinth import network
__all__ = ['networks', 'init']
depends = ['plinth.modules.system']
depends = ['system']
logger = Logger(__name__)
+1 -1
View File
@@ -27,7 +27,7 @@ from plinth import cfg
from plinth import service as service_module
depends = ['plinth.modules.apps']
depends = ['apps']
service = None
+1 -1
View File
@@ -26,7 +26,7 @@ from plinth import action_utils
__all__ = ['owncloud', 'init']
depends = ['plinth.modules.apps']
depends = ['apps']
def diagnose():
+1 -1
View File
@@ -26,7 +26,7 @@ from . import utils
__all__ = ['init']
depends = ['plinth.modules.apps', 'plinth.modules.names']
depends = ['apps', 'names']
def init():
+1 -1
View File
@@ -23,7 +23,7 @@ from django.utils.translation import ugettext_lazy as _
from plinth import cfg
depends = ['plinth.modules.system']
depends = ['system']
def init():
+2 -5
View File
@@ -20,7 +20,6 @@ Plinth module to configure Privoxy.
"""
from django.utils.translation import ugettext_lazy as _
import json
from plinth import actions
from plinth import action_utils
@@ -28,7 +27,7 @@ from plinth import cfg
from plinth import service as service_module
depends = ['plinth.modules.apps']
depends = ['apps']
service = None
@@ -84,9 +83,7 @@ def diagnose_url_with_proxy():
result = action_utils.diagnose_url(url, kind=address['kind'], env=env)
result[0] = _('Access {url} with proxy {proxy} on tcp{kind}') \
.format(url=url, proxy=proxy, kind=address['kind'])
.format(url=url, proxy=proxy, kind=address['kind'])
results.append(result)
return results
+1 -1
View File
@@ -25,7 +25,7 @@ from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
depends = ['plinth.modules.apps']
depends = ['apps']
service = None
+1 -1
View File
@@ -25,7 +25,7 @@ from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
depends = ['plinth.modules.apps']
depends = ['apps']
service = None
+1 -1
View File
@@ -27,7 +27,7 @@ service = None
__all__ = ['init']
depends = ['plinth.modules.apps']
depends = ['apps']
def init():
+1 -3
View File
@@ -21,13 +21,11 @@ Plinth module to configure Roundcube.
from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
depends = ['plinth.modules.apps']
depends = ['apps']
def init():
+1 -1
View File
@@ -26,7 +26,7 @@ from plinth import cfg
from plinth import service as service_module
depends = ['plinth.modules.apps']
depends = ['apps']
service = None
+1 -1
View File
@@ -32,7 +32,7 @@ from plinth.modules.names import SERVICES
from plinth.signals import domain_added
depends = ['plinth.modules.apps', 'plinth.modules.names']
depends = ['apps', 'names']
socks_service = None
bridge_service = None
+1 -2
View File
@@ -21,13 +21,12 @@ Plinth module to configure Transmission server
from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
depends = ['plinth.modules.apps']
depends = ['apps']
service = None
+1 -1
View File
@@ -24,7 +24,7 @@ from django.utils.translation import ugettext_lazy as _
from plinth import cfg
depends = ['plinth.modules.system']
depends = ['system']
def init():
+1 -3
View File
@@ -20,14 +20,12 @@ Plinth module to manage users
"""
from django.utils.translation import ugettext_lazy as _
import json
import subprocess
from plinth import cfg
from plinth import actions
from plinth import action_utils
depends = ['plinth.modules.system']
depends = ['system']
def init():
+1 -2
View File
@@ -20,7 +20,6 @@ Plinth module to configure XMPP server
"""
from django.utils.translation import ugettext_lazy as _
import json
from plinth import actions
from plinth import action_utils
@@ -30,7 +29,7 @@ from plinth.signals import pre_hostname_change, post_hostname_change
from plinth.signals import domainname_change
depends = ['plinth.modules.apps']
depends = ['apps']
service = None