Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modular module system #380

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 7 additions & 24 deletions Maraschino.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,13 @@ def get_rundir():


def import_modules():
for mod in maraschino.MODULES:
module = 'modules.{0}'.format(mod)
try:
__import__(module)
except ImportError:
pass
"""All modules that are available in Maraschino are at this point imported."""
import modules.applications
import modules.controls
import modules.couchpotato
import modules.currently_playing
import modules.diskspace
import modules.headphones
import modules.index
import modules.ipcamera
import modules.library
import modules.log
import modules.nzbget
import modules.recently_added
import modules.remote
import modules.sabnzbd
import modules.script_launcher
import modules.search
import modules.sickbeard
import modules.trakt
import modules.traktplus
import modules.transmission
import modules.updater
import modules.utorrent
import modules.weather
import modules.xbmc_notify
import mobile
import xbmcmm

Expand All @@ -80,6 +62,7 @@ def shutdown_session(exception=None):

import maraschino


def main():
"""Main function that is called at the startup of Maraschino."""
from optparse import OptionParser
Expand Down
32 changes: 30 additions & 2 deletions maraschino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import subprocess
import threading
import wsgiserver
import imp
import copy
from Maraschino import app
from Logger import maraschinoLogger
from apscheduler.scheduler import Scheduler
Expand Down Expand Up @@ -44,6 +46,8 @@
COMMITS_BEHIND = 0
COMMITS_COMPARE_URL = ''
FIRST_RUN = 0
MODULES = []
MODULES_CONF = ''


def initialize():
Expand All @@ -52,7 +56,7 @@ def initialize():

global __INITIALIZED__, app, FULL_PATH, RUNDIR, ARGS, DAEMON, PIDFILE, VERBOSE, LOG_FILE, LOG_DIR, logger, PORT, SERVER, DATABASE, AUTH, \
UPDATER, CURRENT_COMMIT, LATEST_COMMIT, COMMITS_BEHIND, COMMITS_COMPARE_URL, USE_GIT, WEBROOT, HOST, KIOSK, DATA_DIR, SCRIPT_DIR, \
THREADS, FIRST_RUN
THREADS, FIRST_RUN, MODULES, MODULES_CONF

if __INITIALIZED__:
return False
Expand Down Expand Up @@ -137,6 +141,31 @@ def initialize():
'password': password
}

#Modular modules
module_dir = os.path.join(DATA_DIR, 'modules')
for path, dirs, files in os.walk(module_dir):
for name in files:
if name.endswith('.ini'):
MODULES.append(name.replace('.ini', ''))

for mod in MODULES:
ini_path = os.path.join(module_dir, "{0}.ini".format(mod))
if os.path.getsize(ini_path) <= 0:
pass
else:
conf_imp = imp.load_source(mod, ini_path)
if isinstance(conf_imp.mod_conf, list):
try:
data
except NameError:
data = copy.deepcopy(conf_imp.mod_conf)
else:
data = copy.deepcopy(data) + copy.deepcopy(conf_imp.mod_conf)
else:
pass
conf_imp = ''
MODULES_CONF = data

# Set up web server
if '--webroot' not in str(ARGS):
WEBROOT = get_setting_value('maraschino_webroot')
Expand Down Expand Up @@ -206,7 +235,6 @@ def start():
logger.log(' ##### IMPORTANT : WEBROOT DOES NOT WORK UNDER THE DEV SERVER #######', 'INFO')
app.run(debug=True, port=PORT, host=HOST)


def stop():
"""Shutdown Maraschino"""
logger.log('Shutting down Maraschino...', 'INFO')
Expand Down
Loading