Repository URL to install this package:
|
Version:
5.0-r2 ▾
|
enigma2-plugin-extensions-userscripts
/
usr
/
lib
/
enigma2
/
python
/
Plugins
/
Extensions
/
UserScripts
/
plugin.py
|
|---|
from __future__ import print_function
from __future__ import division
from Components.config import (
config,
configfile,
ConfigSubsection,
ConfigText,
ConfigBoolean,
ConfigInteger,
ConfigSelection,
getConfigListEntry,
)
from Components.ConfigList import ConfigListScreen, ConfigList
from Components.config import KEY_OK, KEY_NUMBERS
from Plugins.Plugin import PluginDescriptor
from Plugins.Extensions.UserScripts.UserScripts import (
UserScriptsPlugin,
UserScriptsStartup,
)
from os import (
path as os_path,
mkdir as os_mkdir,
rmdir as os_rmdir,
environ as os_environ,
remove as os_remove,
listdir as os_listdir,
)
import gettext
import gm
try:
from imp import reload as reload
except:
pass
from shutil import rmtree as rmtree
from Components.Harddisk import HarddiskManager as HarddiskManager
if os_path.exists("/var/lib/dpkg/status"):
from Components.Harddisk import BlockDevice as BlockDevice
userscripts_plugindir = "/usr/lib/enigma2/python/Plugins/Extensions/UserScripts"
os_environ["LANGUAGE"] = "en"
userscripts_language = "en"
REDC = "\033[31m"
ENDC = "\033[m"
boxtype = gm.boxtype()
def cprint(text):
print(REDC + "[USERSCRIPTS] " + text + ENDC)
if os_path.exists("/etc/enigma2/settings"):
f = open("/etc/enigma2/settings")
line = f.readline()
while line:
line = f.readline().replace("\n", "")
sp = line.split("=")
if sp[0] == "config.osd.language":
sp2 = sp[1].split("_")
userscripts_language = sp2[0]
if (
os_path.exists(
"%s/locale/%s" % (userscripts_plugindir, userscripts_language)
)
== True
):
os_environ["LANGUAGE"] = sp[1]
else:
os_environ["LANGUAGE"] = "en"
f.close
_ = gettext.Catalog("userscripts", "%s/locale" % userscripts_plugindir).gettext
yes_no_descriptions = {False: _("no"), True: _("yes")}
config.plugins.userscripts = ConfigSubsection()
userscript_inactivity_options = []
userscript_inactivity_options.append(("standby", _("Standby")))
userscript_inactivity_options.append(("idlemode", _("Idle Mode")))
config.usage.inactivity_action = ConfigSelection(
default="standby", choices=userscript_inactivity_options
)
config.plugins.userscripts.confirm = ConfigBoolean(
default=False, descriptions=yes_no_descriptions
)
config.plugins.userscripts.scriptsave = ConfigBoolean(
default=False, descriptions=yes_no_descriptions
)
userscriptlist_options = []
userscriptlist_options.append(("none", _("none")))
userscriptlist_options.append(("execute", _("Execute")))
userscriptlist_options.append(("install", _("Install")))
userscriptlist_options.append(("both", _("Execute") + " & " + _("Install")))
config.plugins.userscripts.list = ConfigSelection(
default="none", choices=userscriptlist_options
)
userscriptshow_options = []
userscriptshow_options.append(("plugin", _("Pluginlist")))
userscriptshow_options.append(("extension", _("Extension")))
userscriptshow_options.append(("both", _("Pluginlist") + " & " + _("Extension")))
config.plugins.userscripts.show = ConfigSelection(
default="both", choices=userscriptshow_options
)
config.plugins.userscripts.startupdelay = ConfigInteger(default=2, limits=(0, 60))
config.plugins.userscripts.sdcard = ConfigBoolean(
default=True, descriptions=yes_no_descriptions
)
config.plugins.userscripts.leaving = ConfigBoolean(
default=True, descriptions=yes_no_descriptions
)
if os_path.exists("/var/lib/dpkg/status"):
blockDeviceEvenetori = HarddiskManager.blockDeviceEvent
def setit(val):
val.pop()
val.append(0)
def UserScripts_blockDeviceEvent(self, data):
action = data.get("ACTION")
devname = data.get("DEVNAME")
devpath = data.get("DEVPATH")
devtype = data.get("DEVTYPE")
if not (action and devname and devpath and devtype):
return
blkdev = BlockDevice(devname)
# replacement for if __isBlacklisted(data):
major = int(data.get("MAJOR", "0"))
minor = int(data.get("MINOR", "0"))
name = blkdev.name().rstrip("0123456789")
cprint(
"################ name: %s %d,%d ###################" % (devname, major, minor)
)
if config.plugins.userscripts.sdcard.value:
if major == 179:
# mmcblk only blocked if internal Flash
if devname.startswith("/dev/mmcblk1"):
cprint("allowing event for %s (blacklisted)" % devpath)
else:
cprint("ignoring event for %s (blacklisted)" % devpath)
return
else:
# ram, loop, md, mtdblock, mmcblk
if name in ["zram"] or major in (1, 7, 9, 31, 179):
cprint("ignoring event for %s (blacklisted)" % devpath)
return
else: # normal blocking behaviour
# ram, loop, md, mtdblock, mmcblk
if name in ["zram"] or major in (1, 7, 9, 31, 179):
cprint("ignoring event for %s (blacklisted)" % devpath)
return
if action in ("add", "change"):
# enable PVR features when a internal harddisc is detected
device = blkdev.name()
physdev = blkdev.sysfsPath("device", physdev=True)[4:]
description = self.getUserfriendlyDeviceName(device, physdev)
if (
description.startswith(_("SATA"))
and not config.misc.recording_allowed.value
):
config.misc.recording_allowed.value = True
config.misc.recording_allowed.save()
configfile.save()
# dirty Hack to be able to call private Methods from original class
if action == "add":
HarddiskManager._HarddiskManager__addHotplugDevice(self, blkdev, data)
elif action == "change":
HarddiskManager._HarddiskManager__changeHotplugPartition(self, blkdev, data)
elif action == "remove":
HarddiskManager._HarddiskManager__removeHotplugPartition(self, blkdev, data)
if (
boxtype == "dreamone"
or boxtype == "dreamtwo"
or boxtype == "dm900"
or boxtype == "dm920"
):
if os_path.exists("/var/lib/dpkg/status"):
# rename on startup
HarddiskManager.blockDeviceEvent = UserScripts_blockDeviceEvent
def main(session, **kwargs):
if not os_path.exists(
"%s/UserScripts.pyo" % userscripts_plugindir
) and not os_path.exists("%s/UserScripts.pyc" % userscripts_plugindir):
reload(UserScripts)
session.open(UserScriptsPlugin)
def autostart(reason, **kwargs):
if "session" in kwargs and reason == 0:
session = kwargs["session"]
cprint("autostart")
try:
if config.plugins.userscripts.sdcard.value:
if not os_path.exists("/media/sdcard"):
os_mkdir("/media/sdcard")
if not os_path.exists("/media/hdd"):
os_mkdir("/media/hdd")
else:
if os_path.exists("/media/sdcard"):
os_rmdir("/media/sdcard")
except:
pass
if not os_path.exists(
"%s/UserScripts.pyo" % userscripts_plugindir
) and not os_path.exists("%s/UserScripts.pyc" % userscripts_plugindir):
reload(UserScripts)
session.open(UserScriptsStartup)
def Plugins(**kwargs):
if config.plugins.userscripts.show.value == "plugin":
return [
PluginDescriptor(
where=[
PluginDescriptor.WHERE_SESSIONSTART,
PluginDescriptor.WHERE_AUTOSTART,
],
fnc=autostart,
),
PluginDescriptor(
name=_("User Scripts"),
description=_("User Script Plugin"),
where=PluginDescriptor.WHERE_PLUGINMENU,
icon="userscripts.png",
fnc=main,
),
]
elif config.plugins.userscripts.show.value == "extension":
return [
PluginDescriptor(
where=[
PluginDescriptor.WHERE_SESSIONSTART,
PluginDescriptor.WHERE_AUTOSTART,
],
fnc=autostart,
),
PluginDescriptor(
name=_("User Scripts"),
description=_("User Script Plugin"),
where=PluginDescriptor.WHERE_EXTENSIONSMENU,
icon="userscripts.png",
fnc=main,
),
]
elif config.plugins.userscripts.show.value == "both":
return [
PluginDescriptor(
where=[
PluginDescriptor.WHERE_SESSIONSTART,
PluginDescriptor.WHERE_AUTOSTART,
],
fnc=autostart,
),
PluginDescriptor(
name=_("User Scripts"),
description=_("User Script Plugin"),
where=PluginDescriptor.WHERE_PLUGINMENU,
icon="userscripts.png",
fnc=main,
),
PluginDescriptor(
name=_("User Scripts"),
description=_("User Script Plugin"),
where=PluginDescriptor.WHERE_EXTENSIONSMENU,
icon="userscripts.png",
fnc=main,
),
]