Module is a directory instead of file

- Move enabled module symlinks to 'modules/enabled' directory.
- Make all modules properly importable
- Import modules instead of their symlinks
This commit is contained in:
Sunil Mohan Adapa 2014-06-06 12:01:08 +05:30
parent 8d5e976b84
commit 912c5022ca
63 changed files with 452 additions and 56 deletions

View File

@ -1 +0,0 @@
installed/apps/apps.py

View File

@ -1 +0,0 @@
installed/lib/auth.py

View File

@ -1 +0,0 @@
installed/lib/auth_page.py

View File

@ -1 +0,0 @@
installed/config/config.py

View File

@ -1 +0,0 @@
installed/diagnostics/diagnostics.py

1
modules/enabled/apps Symbolic link
View File

@ -0,0 +1 @@
../installed/apps/

1
modules/enabled/config Symbolic link
View File

@ -0,0 +1 @@
../installed/config/

1
modules/enabled/diagnostics Symbolic link
View File

@ -0,0 +1 @@
../installed/diagnostics/

1
modules/enabled/expert_mode Symbolic link
View File

@ -0,0 +1 @@
../installed/expert_mode/

1
modules/enabled/firewall Symbolic link
View File

@ -0,0 +1 @@
../installed/firewall/

1
modules/enabled/first_boot Symbolic link
View File

@ -0,0 +1 @@
../installed/first_boot/

1
modules/enabled/help Symbolic link
View File

@ -0,0 +1 @@
../installed/help/

1
modules/enabled/lib Symbolic link
View File

@ -0,0 +1 @@
../installed/lib/

1
modules/enabled/owncloud Symbolic link
View File

@ -0,0 +1 @@
../installed/owncloud/

1
modules/enabled/packages Symbolic link
View File

@ -0,0 +1 @@
../installed/packages/

1
modules/enabled/pagekite Symbolic link
View File

@ -0,0 +1 @@
../installed/pagekite/

1
modules/enabled/system Symbolic link
View File

@ -0,0 +1 @@
../installed/system/

1
modules/enabled/tor Symbolic link
View File

@ -0,0 +1 @@
../installed/tor/

1
modules/enabled/users Symbolic link
View File

@ -0,0 +1 @@
../installed/users/

1
modules/enabled/xmpp Symbolic link
View File

@ -0,0 +1 @@
../installed/xmpp/

View File

@ -1 +0,0 @@
installed/expert_mode/expert_mode.py

View File

@ -1 +0,0 @@
installed/firewall/firewall.py

View File

@ -1 +0,0 @@
installed/first_boot/first_boot.py

View File

@ -1 +0,0 @@
installed/help/help.py

View File

View File

@ -0,0 +1,25 @@
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Plinth module for apps section page
"""
from . import apps
__all__ = ['apps']

View File

@ -1,6 +1,5 @@
import cherrypy
from gettext import gettext as _
from modules.auth import require
from plugin_mount import PagePlugin
import cfg
import util

View File

@ -0,0 +1,25 @@
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Plinth module for basic system configuration
"""
from . import config
__all__ = ['config']

View File

@ -28,7 +28,7 @@ import socket
import actions
import cfg
from modules.auth import require
from ..lib.auth import require
from plugin_mount import PagePlugin
import util

View File

@ -0,0 +1,25 @@
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Plinth module to system diagnostics
"""
from . import diagnostics
__all__ = ['diagnostics']

View File

@ -21,7 +21,7 @@ Plinth module for running diagnostics
import cherrypy
from gettext import gettext as _
from auth import require
from ..lib.auth import require
from plugin_mount import PagePlugin
import actions
import cfg

View File

@ -0,0 +1,25 @@
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Plinth module for expert mode configuration
"""
from . import expert_mode
__all__ = ['expert_mode']

View File

@ -1,7 +1,7 @@
import cherrypy
from django import forms
from gettext import gettext as _
from modules.auth import require
from ..lib.auth import require
from plugin_mount import PagePlugin
import cfg
import util

View File

@ -0,0 +1,25 @@
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Plinth module to configure a firewall
"""
from . import firewall
__all__ = ['firewall']

View File

@ -24,7 +24,7 @@ from gettext import gettext as _
import actions
import cfg
from modules.auth import require
from ..lib.auth import require
from plugin_mount import PagePlugin
import service as service_module
import util

View File

@ -0,0 +1,25 @@
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Plinth module for first boot wizard
"""
from . import first_boot
__all__ = ['first_boot']

View File

@ -23,10 +23,10 @@ from django import forms
from django.core import validators
from gettext import gettext as _
from plugin_mount import PagePlugin
from modules.auth import add_user
from ..lib.auth import add_user
from ..config import config
from withsqlite.withsqlite import sqlite_db
import cfg
import config
import util

View File

@ -0,0 +1,25 @@
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Plinth module for help pages
"""
from . import help # pylint: disable-msg=W0622
__all__ = ['help']

View File

@ -0,0 +1,29 @@
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Plinth library modules
"""
from . import auth
from . import auth_page
from . import user_store
__all__ = ['auth',
'auth_page',
'user_store']

View File

@ -0,0 +1,25 @@
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Plinth module to configure ownCloud
"""
from . import owncloud
__all__ = ['owncloud']

View File

@ -1,7 +1,7 @@
import cherrypy
from django import forms
from gettext import gettext as _
from modules.auth import require
from ..lib.auth import require
from plugin_mount import PagePlugin
import actions
import cfg

View File

@ -0,0 +1,25 @@
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Plinth module to manage packages
"""
from . import packages
__all__ = ['packages']

View File

@ -1,7 +1,7 @@
import cherrypy
from django import forms
from gettext import gettext as _
from auth import require
from ..lib.auth import require
from plugin_mount import PagePlugin
import actions
import cfg

View File

@ -0,0 +1,25 @@
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Plinth module to configure PageKite
"""
from . import pagekite
__all__ = ['pagekite']

View File

@ -26,7 +26,7 @@ from gettext import gettext as _
import actions
import cfg
from modules.auth import require
from ..lib.auth import require
from plugin_mount import PagePlugin
import util

View File

@ -0,0 +1,25 @@
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Plinth module to configure santiago port
"""
from . import santiago
__all__ = ['santiago']

View File

@ -0,0 +1,25 @@
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Plinth module for system section page
"""
from . import system
__all__ = ['system']

View File

@ -0,0 +1,25 @@
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Plinth module to configure Tor
"""
from . import tor
__all__ = ['tor']

View File

@ -22,7 +22,7 @@ Plinth module for configuring Tor
import cherrypy
from gettext import gettext as _
from plugin_mount import PagePlugin
from modules.auth import require
from ..lib.auth import require
import actions
import cfg
import util

View File

@ -0,0 +1,25 @@
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Plinth module to manage users
"""
from . import users
__all__ = ['users']

View File

@ -2,8 +2,7 @@ import cherrypy
from django import forms
from django.core import validators
from gettext import gettext as _
import auth
from auth import require
from ..lib.auth import require, add_user
from plugin_mount import PagePlugin
import cfg
from model import User
@ -86,8 +85,8 @@ class UserAdd(PagePlugin):
username=data['username'])))
return
auth.add_user(data['username'], data['password'], data['full_name'],
data['email'], False)
add_user(data['username'], data['password'], data['full_name'],
data['email'], False)
messages.append(
('success', _('User "{username}" added').format(
username=data['username'])))

View File

@ -0,0 +1,25 @@
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Plinth module to configure XMPP server
"""
from . import xmpp
__all__ = ['xmpp']

View File

@ -1,7 +1,7 @@
import cherrypy
from django import forms
from gettext import gettext as _
from modules.auth import require
from ..lib.auth import require
from plugin_mount import PagePlugin
import cfg
import actions

View File

@ -1 +0,0 @@
installed/owncloud/owncloud.py

View File

@ -1 +0,0 @@
installed/packages/packages.py

View File

@ -1 +0,0 @@
installed/pagekite/pagekite.py

View File

@ -1 +0,0 @@
installed/system/system.py

View File

@ -1 +0,0 @@
installed/tor/tor.py

View File

@ -1 +0,0 @@
installed/lib/user_store.py

View File

@ -1 +0,0 @@
installed/users/users.py

View File

@ -1 +0,0 @@
installed/xmpp/xmpp.py

View File

@ -4,8 +4,10 @@ import os, stat, sys, argparse
from gettext import gettext as _
import cfg
import django.conf
import importlib
if not os.path.join(cfg.file_root, "vendor") in sys.path:
sys.path.append(os.path.join(cfg.file_root, "vendor"))
import re
import cherrypy
from cherrypy import _cpserver
@ -74,20 +76,21 @@ class Root(plugin_mount.PagePlugin):
else:
raise cherrypy.InternalRedirect('help/about')
def load_modules():
"""Import all the symlinked .py files in the modules directory and
all the .py files in directories linked in the modules directory
(but don't dive deeper than that). Also, ignore the installed
directory."""
for name in os.listdir("modules"):
if name.endswith(".py") and not name.startswith('.'):
cfg.log.info("importing modules/%s" % name)
try:
__import__("modules.%s" % (name[:-3]))
except ImportError, e:
cfg.log.error(_("Couldn't import modules/%s: %s") % (name, e))
else:
cfg.log("skipping %s" % name)
"""
Read names of enabled modules in modules/enabled directory and
import them from modules/installed directory.
"""
for name in os.listdir('modules/enabled'):
cfg.log.info('Importing modules/installed/%s' % name)
try:
importlib.import_module(
'modules.installed.{module}'.format(module=name))
except ImportError as exception:
cfg.log.error(
'Could not import modules/installed/{module}: {exception}'
.format(module=name, exception=exception))
def get_template_directories():
@ -96,13 +99,9 @@ def get_template_directories():
core_directory = os.path.join(directory, 'templates')
directories = set((core_directory,))
for name in os.listdir('modules'):
if not name.endswith(".py") or name.startswith('.'):
continue
real_name = os.path.realpath(os.path.join('modules', name))
directory = os.path.dirname(real_name)
directories.add(os.path.join(directory, 'templates'))
for name in os.listdir('modules/enabled'):
directories.add(os.path.join('modules', 'installed', name,
'templates'))
cfg.log.info('Template directories - %s' % directories)

View File

@ -1,7 +1,4 @@
import cherrypy
from modules.auth import require
import cfg
import util
class PluginMount(type):