Skip to content

Commit

Permalink
several improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jbleyel committed Apr 15, 2018
1 parent f934495 commit a6ecad4
Show file tree
Hide file tree
Showing 17 changed files with 208 additions and 240 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Version 1.3.2
## (in development)
* reorg i18n
* move some code to new defaults controller
* optimize web api for UI settings

## Version 1.3.1
* add net api mount manager
Expand Down
17 changes: 11 additions & 6 deletions plugin/controllers/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
from Components.config import config

from models.services import getBouquets, getChannels, getSatellites, getProviders, getEventDesc, getChannelEpg, getSearchEpg, getCurrentFullInfo, getMultiEpg, getEvent
from models.info import getInfo, getPublicPath, getOpenWebifVer, getTranscodingSupport, getLanguage
from models.info import getInfo, getTranscodingSupport, getLanguage
from models.movies import getMovieList
from models.timers import getTimers
from models.config import getConfigs, getConfigsSections, getZapStream, getShowChPicon
from models.config import getConfigs, getConfigsSections
from models.stream import GetSession
from base import BaseController
from time import mktime, localtime
from models.locations import getLocations

from defaults import OPENWEBIFVER, getPublicPath, VIEWS_PATH

# from twisted.web.resource import Resource
import os

Expand Down Expand Up @@ -88,7 +91,7 @@ def P_channels(self, request):
channels = getChannels(idbouquet, stype)
channels['transcoding'] = getTranscodingSupport()
channels['type'] = stype
channels['showchannelpicon'] = getShowChPicon()['showchannelpicon']
channels['showchannelpicon'] = config.OpenWebif.webcache.showchannelpicon.value
return channels

def P_eventdescription(self, request):
Expand All @@ -111,7 +114,7 @@ def P_event(self, request):

def P_about(self, request):
info = {}
info["owiver"] = getOpenWebifVer()
info["owiver"] = OPENWEBIFVER
return {"info": info}

def P_boxinfo(self, request):
Expand Down Expand Up @@ -247,11 +250,13 @@ def P_settings(self, request):
else:
ret['themes'] = []
ret['theme'] = 'original'
ret['zapstream'] = getZapStream()['zapstream']
ret['showchannelpicon'] = getShowChPicon()['showchannelpicon']
ret['zapstream'] = config.OpenWebif.webcache.zapstream.value
ret['showchannelpicon'] = config.OpenWebif.webcache.showchannelpicon.value
ret['allowipkupload'] = config.OpenWebif.allow_upload_ipk.value
loc = getLocations()
ret['locations'] = loc['locations']
if os.path.exists(VIEWS_PATH + "/responsive"):
ret['responsivedesign'] = config.OpenWebif.responsive_enabled.value
return ret

def P_multiepg(self, request):
Expand Down
3 changes: 2 additions & 1 deletion plugin/controllers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
from Components.config import config
from Components.Network import iNetwork

from models.info import getInfo, getPublicPath, getViewsPath
from models.info import getInfo
from models.config import getCollapsedMenus, getConfigsSections
from models.config import getShowName, getCustomName, getBoxName

from defaults import getPublicPath, getViewsPath

def new_getRequestHostname(self):
host = self.getHeader(b'host')
Expand Down
73 changes: 73 additions & 0 deletions plugin/controllers/defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys

from Components.config import config as comp_config

OPENWEBIFVER = "OWIF 1.3.2"

PLUGIN_NAME = 'OpenWebif'
PLUGIN_DESCRIPTION = "OpenWebif Configuration"
PLUGIN_WINDOW_TITLE = PLUGIN_DESCRIPTION

PLUGIN_ROOT_PATH = os.path.dirname(os.path.dirname(__file__))
PUBLIC_PATH = PLUGIN_ROOT_PATH + '/public'
VIEWS_PATH = PLUGIN_ROOT_PATH + '/controllers/views'

sys.path.insert(0, PLUGIN_ROOT_PATH)

GLOBALPICONPATH = None


def getViewsPath(file=""):
if comp_config.OpenWebif.responsive_enabled.value and os.path.exists(VIEWS_PATH + "/responsive") and not (file.startswith('web/') or file.startswith('/web/')):
return VIEWS_PATH + "/responsive/" + file
else:
return VIEWS_PATH + "/" + file


def getPublicPath(file=""):
return PUBLIC_PATH + "/" + file


def getPiconPath():

# Alternative locations need to come first, as the default location always exists and needs to be the last resort
# Sort alternative locations in order of likelyness that they are non-rotational media:
# CF/MMC are always memory cards
# USB can be memory stick or magnetic hdd or SSD, but stick is most likely
# HDD can be magnetic hdd, SSD or even memory stick (if no hdd present) or a NAS
PICON_PREFIXES = [
"/media/cf/",
"/media/mmc/",
"/media/usb/",
"/media/hdd/",
"/usr/share/enigma2/",
"/"
]

#: subfolders containing picons
PICON_FOLDERS = ('owipicon', 'picon')

#: extension of picon files
PICON_EXT = ".png"

for prefix in PICON_PREFIXES:
if os.path.isdir(prefix):
for folder in PICON_FOLDERS:
current = prefix + folder + '/'
if os.path.isdir(current):
print "Current Picon Path : %s" % current
GLOBALPICONPATH = current
return GLOBALPICONPATH
#: TODO discuss
# for item in os.listdir(current):
# if os.path.isfile(current + item) and item.endswith(PICON_EXT):
# PICONPATH = current
# return PICONPATH

return None

#: PICON PATH FIXME: check path again after a few hours to detect new paths
PICON_PATH = getPiconPath()
1 change: 1 addition & 0 deletions plugin/controllers/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ def _(txt):

'packages': _("Packages"),

'newdesign': _('Use new design'),
'no_cancel': _("No, cancel"),
'yes_delete': _("Yes, delete it"),
'cancelled': _("Cancelled"),
Expand Down
26 changes: 0 additions & 26 deletions plugin/controllers/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,6 @@ def getCollapsedMenus():
"collapsed": config.OpenWebif.webcache.collapsedmenus.value.split("|")
}

def setZapStream(value):
config.OpenWebif.webcache.zapstream.value = value
config.OpenWebif.webcache.zapstream.save()
return {
"result": True
}

def getZapStream():
return {
"result": True,
"zapstream": config.OpenWebif.webcache.zapstream.value
}

def setShowChPicon(value):
config.OpenWebif.webcache.showchannelpicon.value = value
config.OpenWebif.webcache.showchannelpicon.save()
return {
"result": True
}

def getShowChPicon():
return {
"result": True,
"showchannelpicon": config.OpenWebif.webcache.showchannelpicon.value
}

def getShowName():
return {
"result": True,
Expand Down
83 changes: 2 additions & 81 deletions plugin/controllers/models/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from enigma import eEPGCache

from ..i18n import _
from ..defaults import OPENWEBIFVER

try:
from boxbranding import getBoxType, getMachineBuild, getMachineBrand, getMachineName, getImageDistro, getImageVersion, getImageBuild, getOEVersion, getDriverDate
Expand All @@ -40,18 +41,8 @@
def getEnigmaVersionString():
return about.getEnigmaVersionString()


OPENWEBIFVER = "OWIF 1.3.2"

STATICBOXINFO = None

PICONPATH = None


def getOpenWebifVer():
return OPENWEBIFVER


def getFriendlyImageDistro():
dist = getImageDistro().replace("openatv", "OpenATV").replace("openhdf", "OpenHDF").replace("openpli", "OpenPLi").replace("openvix", "OpenViX")
return dist
Expand Down Expand Up @@ -187,76 +178,6 @@ def formatIp(ip):
return "%d.%d.%d.%d" % (ip[0], ip[1], ip[2], ip[3])


def getBasePath():
path = os.path.dirname(sys.modules[__name__].__file__)
chunks = path.split("/")
chunks.pop()
chunks.pop()
return "/".join(chunks)


def getPublicPath(file=""):
return getBasePath() + "/public/" + file


def getViewsPath(file=""):
if config.OpenWebif.responsive_enabled.value and os.path.exists(getBasePath() + "/controllers/views/responsive") and not (file.startswith('web/') or file.startswith('/web/')):
return getBasePath() + "/controllers/views/responsive/" + file
else:
return getBasePath() + "/controllers/views/" + file


def getPiconPath():

# FIXME: check path again after a few hours to detect new paths

global PICONPATH

if PICONPATH is not None:
return PICONPATH

# Alternative locations need to come first, as the default location always exists and needs to be the last resort
# Sort alternative locations in order of likelyness that they are non-rotational media:
# CF/MMC are always memory cards
# USB can be memory stick or magnetic hdd or SSD, but stick is most likely
# HDD can be magnetic hdd, SSD or even memory stick (if no hdd present) or a NAS
pathlist = [
"/media/cf/",
"/media/mmc/",
"/media/usb/",
"/media/hdd/",
"/usr/share/enigma2/",
"/"
]

for p in pathlist:
if pathExists(p + "owipicon/"):
PICONPATH = p + "owipicon/"
return PICONPATH
elif pathExists(p + "picon/"):
PICONPATH = p + "picon/"
return PICONPATH

return None


def _getPiconPath():
if pathExists("/media/usb/picon/"):
return "/media/usb/picon/"
elif pathExists("/media/cf/picon/"):
return "/media/cf/picon/"
elif pathExists("/media/mmc/picon/"):
return "/media/mmc/picon/"
elif pathExists("/media/hdd/picon/"):
return "/media/hdd/picon/"
elif pathExists("/usr/share/enigma2/picon/"):
return "/usr/share/enigma2/picon/"
elif pathExists("/picon/"):
return "/picon/"
else:
return ""


def getInfo(session=None, need_fullinfo=False):
# TODO: get webif versione somewhere!
info = {}
Expand Down Expand Up @@ -381,7 +302,7 @@ def getInfo(session=None, need_fullinfo=False):
uptimetext = "?"
info['uptime'] = uptimetext

info["webifver"] = getOpenWebifVer()
info["webifver"] = OPENWEBIFVER
info['imagedistro'] = getImageDistro()
info['friendlyimagedistro'] = getFriendlyImageDistro()
info['oever'] = getOEVersion()
Expand Down
5 changes: 3 additions & 2 deletions plugin/controllers/models/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
from ServiceReference import ServiceReference
from Screens.ChannelSelection import service_types_tv, service_types_radio, FLAG_SERVICE_NEW_FOUND
from enigma import eServiceCenter, eServiceReference, iServiceInformation, eEPGCache
from info import getPiconPath, GetWithAlternative, getOrbitalText
from info import GetWithAlternative, getOrbitalText
from urllib import quote, unquote
from ..utilities import parse_servicereference, SERVICE_TYPE_LOOKUP, NS_LOOKUP
from ..i18n import _, tstrings
from ..defaults import PICON_PATH

try:
from collections import OrderedDict
Expand Down Expand Up @@ -941,7 +942,7 @@ def getTimerEventStatus(event):

def getPicon(sname):

pp = getPiconPath()
pp = PICON_PATH
if pp is not None:
# remove URL part
if ("://" in sname) or ("%3a//" in sname) or ("%3A//" in sname):
Expand Down
9 changes: 4 additions & 5 deletions plugin/controllers/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from twisted.web import static, http, proxy
from Components.config import config

from models.info import getPublicPath, getPiconPath, getBasePath
from models.grab import grabScreenshot
from base import BaseController
from web import WebController, ApiController
Expand All @@ -40,14 +39,14 @@
from wol import WOLSetupController, WOLClientController
from file import FileController

from defaults import PICON_PATH, getPublicPath, VIEWS_PATH

class RootController(BaseController):
"""
Root Web Controller
"""
def __init__(self, session, path=""):
BaseController.__init__(self, path=path, session=session)
piconpath = getPiconPath()

self.putChild("web", WebController(session))
self.putChild("api", ApiController(session))
Expand All @@ -73,8 +72,8 @@ def __init__(self, session, path=""):
self.putChild("transcoding", TranscodingController())
self.putChild("wol", WOLClientController())
self.putChild("wolsetup", WOLSetupController(session))
if piconpath:
self.putChild("picon", static.File(piconpath))
if PICON_PATH:
self.putChild("picon", static.File(PICON_PATH))
try:
from NET import NetController
self.putChild("net", NetController(session))
Expand All @@ -89,7 +88,7 @@ def prePageLoad(self, request):
# the "pages functions" must be called P_pagename
# example http://boxip/index => P_index
def P_index(self, request):
if config.OpenWebif.responsive_enabled.value and os.path.exists(getBasePath() + "/controllers/views/responsive"):
if config.OpenWebif.responsive_enabled.value and os.path.exists(VIEWS_PATH + "/responsive"):
return {}
mode = ''
if "mode" in request.args.keys():
Expand Down
2 changes: 1 addition & 1 deletion plugin/controllers/views/ajax/multiepg.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ fixTableHeight();
if (mode != $mode) {

$.ajax({
url: 'api/setmepgmode?mode=' + mode,
url: 'api/setwebconfig?mepgmode=' + mode,
success: function(data) {
\$("#tvcontent").html(loadspinner).load('ajax/multiepg?bref=${quote($bref)}&day=$day&epgmode='+epgmode+'&week='+$week);
}
Expand Down
Loading

0 comments on commit a6ecad4

Please sign in to comment.