Skip to content

Commit

Permalink
AutoTimer: Use python logging instead of shell prints (betonme)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima73 committed Dec 2, 2015
1 parent e0196ff commit 6b79838
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 151 deletions.
18 changes: 18 additions & 0 deletions autotimer/po/ru.po
Expand Up @@ -1295,3 +1295,21 @@ msgstr "только из режима глубокого ожидания"

msgid "never"
msgstr "никогда"

msgid "Create debug log file"
msgstr "Создавать лог файл отладки"

msgid "Path debug log"
msgstr "Расположение лога отладки"

msgid "Print shell log"
msgstr "Вывод shell лога"

msgid "If this enabled, debug log print in console mode start enigma2."
msgstr "Если это включено, то лог отладки будет выводится в режиме запуска enigma2 через консоль."

msgid "Specify the name and location for the log."
msgstr "Укажите имя и расположение для лога."

msgid "If this enabled, debug Autotimer write in log file."
msgstr "Если это включено, то лог отладки Автотаймера будет записан в файл."
5 changes: 2 additions & 3 deletions autotimer/src/AutoPoller.py
Expand Up @@ -24,6 +24,8 @@

from twisted.internet import reactor

from Logger import doLog

class AutoPollerThread(Thread):
"""Background thread where the EPG is parsed (unless initiated by the user)."""
def __init__(self):
Expand Down Expand Up @@ -106,14 +108,12 @@ def run(self):
try:
import NavigationInstance
if NavigationInstance.instance.RecordTimer.isRecording():
print("[AutoTimer]: Skip check during running records")
reactor.callFromThread(timer.startLongTimer, config.plugins.autotimer.interval.value*3600)
continue
except:
pass
try:
if config.plugins.autotimer.onlyinstandby.value and Standby.inStandby is None:
print("[AutoTimer]: Skip check during live tv")
reactor.callFromThread(timer.startLongTimer, config.plugins.autotimer.interval.value*3600)
continue
except:
Expand All @@ -122,7 +122,6 @@ def run(self):
try:
from Plugins.Extensions.EPGRefresh.EPGRefresh import epgrefresh
if epgrefresh.isrunning:
print("[AutoTimer]: Skip check during EPGRefresh")
reactor.callFromThread(timer.startLongTimer, config.plugins.autotimer.interval.value*3600)
continue
except:
Expand Down
124 changes: 77 additions & 47 deletions autotimer/src/AutoTimer.py

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions autotimer/src/AutoTimerConfiguration.py
Expand Up @@ -11,6 +11,8 @@

from enigma import eServiceReference

from Logger import doLog

"""
Configuration Version.
To be bumped for any modification of the config format.
Expand Down Expand Up @@ -42,7 +44,7 @@ def parseConfig(configuration, list, version = None, uniqueTimerId = 0, defaultT
try:
intVersion = int(version)
except ValueError:
print('[AutoTimer] Config version "%s" is not a valid integer, assuming old version' % version)
doLog('[AutoTimer] Config version "%s" is not a valid integer, assuming old version' % version)
intVersion = -1

if intVersion < 5:
Expand Down Expand Up @@ -71,13 +73,13 @@ def parseEntry(element, baseTimer, defaults = False):
# Read out match
baseTimer.match = element.get("match", "").encode("UTF-8")
if not baseTimer.match:
print('[AutoTimer] Erroneous config is missing attribute "match", skipping entry')
doLog('[AutoTimer] Erroneous config is missing attribute "match", skipping entry')
return False

# Read out name
baseTimer.name = element.get("name", "").encode("UTF-8")
if not baseTimer.name:
print('[AutoTimer] Timer is missing attribute "name", defaulting to match')
doLog('[AutoTimer] Timer is missing attribute "name", defaulting to match')
baseTimer.name = baseTimer.match

# Read out enabled
Expand All @@ -87,7 +89,7 @@ def parseEntry(element, baseTimer, defaults = False):
elif enabled == "yes":
baseTimer.enabled = True
else:
print('[AutoTimer] Erroneous config contains invalid value for "enabled":', enabled,', disabling')
doLog('[AutoTimer] Erroneous config contains invalid value for "enabled":', enabled,', disabling')
baseTimer.enabled = False

# Read timeframe
Expand Down Expand Up @@ -220,7 +222,7 @@ def parseEntry(element, baseTimer, defaults = False):
if value in idx:
value = idx[value]
else:
print('[AutoTimer] Erroneous config contains invalid value for "afterevent":', afterevent,', ignoring definition')
doLog('[AutoTimer] Erroneous config contains invalid value for "afterevent":', afterevent,', ignoring definition')
continue

start = afterevent.get("from")
Expand Down Expand Up @@ -277,7 +279,7 @@ def parseEntry(element, baseTimer, defaults = False):
return True

def parseConfigOld(configuration, list, uniqueTimerId = 0):
print("[AutoTimer] Trying to parse old config")
doLog("[AutoTimer] Trying to parse old config")

# Iterate Timers
for timer in configuration.findall("timer"):
Expand All @@ -294,7 +296,7 @@ def parseConfigOld(configuration, list, uniqueTimerId = 0):
name = getValue(timer.findall("name"), "").encode("UTF-8")

if not name:
print('[AutoTimer] Erroneous config is missing attribute "name", skipping entry')
doLog('[AutoTimer] Erroneous config is missing attribute "name", skipping entry')
continue

# Read out match (V3+)
Expand All @@ -303,7 +305,7 @@ def parseConfigOld(configuration, list, uniqueTimerId = 0):
# Read out match
match = match.encode("UTF-8")
if not match:
print('[AutoTimer] Erroneous config contains empty attribute "match", skipping entry')
doLog('[AutoTimer] Erroneous config contains empty attribute "match", skipping entry')
continue
# V2-
else:
Expand All @@ -319,7 +321,7 @@ def parseConfigOld(configuration, list, uniqueTimerId = 0):
elif enabled == "yes":
enabled = True
else:
print('[AutoTimer] Erroneous config contains invalid value for "enabled":', enabled,', skipping entry')
doLog('[AutoTimer] Erroneous config contains invalid value for "enabled":', enabled,', skipping entry')
enabled = False
# V1
else:
Expand Down Expand Up @@ -352,7 +354,7 @@ def parseConfigOld(configuration, list, uniqueTimerId = 0):
end = [int(x) for x in end.split(':')]
timetuple = (start, end)
else:
print('[AutoTimer] Erroneous config contains invalid definition of "timespan", ignoring definition')
doLog('[AutoTimer] Erroneous config contains invalid definition of "timespan", ignoring definition')
timetuple = None
else:
timetuple = None
Expand Down Expand Up @@ -441,7 +443,7 @@ def parseConfigOld(configuration, list, uniqueTimerId = 0):
if value in idx:
value = idx[value]
else:
print('[AutoTimer] Erroneous config contains invalid value for "afterevent":', afterevent,', ignoring definition')
doLog('[AutoTimer] Erroneous config contains invalid value for "afterevent":', afterevent,', ignoring definition')
continue

start = element.get("from")
Expand Down
158 changes: 75 additions & 83 deletions autotimer/src/AutoTimerResource.py
Expand Up @@ -15,7 +15,7 @@
from . import _, config, iteritems, plugin
from plugin import autotimer

API_VERSION = "1.4"
API_VERSION = "1.5"

class AutoTimerBaseResource(resource.Resource):
def returnResult(self, req, state, statetext):
Expand Down Expand Up @@ -130,11 +130,11 @@ def finishRequest():
if self._stillAlive:
reactor.callFromThread(finishRequest)

def intermediateWrite(self, new, conflicting, similar):
def intermediateWrite(self, timers, conflicting, similar, skipped):
returnlist = []
extend = returnlist.extend

for (name, begin, end, serviceref, autotimername) in new:
for (name, begin, end, serviceref, autotimername, message) in timers:
ref = ServiceReference(str(serviceref))
extend((
'<e2simulatedtimer>\n'
Expand All @@ -150,6 +150,72 @@ def intermediateWrite(self, new, conflicting, similar):
if self._stillAlive:
reactor.callFromThread(lambda: self._req.write(''.join(returnlist)))

class AutoTimerTestBackgroundThread(AutoTimerBackgroundThread):
def run(self):
req = self._req
if self._stillAlive:
req.setResponseCode(http.OK)
req.setHeader('Content-type', 'application/xhtml+xml')
req.setHeader('charset', 'UTF-8')
reactor.callFromThread(lambda: req.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<e2autotimersimulate api_version=\"" + str(API_VERSION) + "\">\n"))

def finishRequest():
req.write('</e2autotimersimulate>')
req.finish()

id = req.args.get("id")
if id:
self.id = int(id[0])
else:
self.id = None

try: autotimer.parseEPG(simulateOnly=True, uniqueId=self.id, callback=self.intermediateWrite)
except Exception as e:
def finishRequest():
req.write('<exception>'+str(e)+'</exception><|PURPOSEFULLYBROKENXML<')
req.finish()

if self._stillAlive:
reactor.callFromThread(finishRequest)

def intermediateWrite(self, timers, conflicting, similar, skipped):
returnlist = []
extend = returnlist.extend

for (name, begin, end, serviceref, autotimername, message) in timers:
ref = ServiceReference(str(serviceref))
extend((
'<e2simulatedtimer>\n'
' <e2servicereference>', stringToXML(serviceref), '</e2servicereference>\n',
' <e2servicename>', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n',
' <e2name>', stringToXML(name), '</e2name>\n',
' <e2timebegin>', str(begin), '</e2timebegin>\n',
' <e2timeend>', str(end), '</e2timeend>\n',
' <e2autotimername>', stringToXML(autotimername), '</e2autotimername>\n',
' <e2state>OK</e2state>\n'
' <e2message>', stringToXML(message), '</e2message>\n'
'</e2simulatedtimer>\n'
))

if self.id:
for (name, begin, end, serviceref, autotimername, message) in skipped:
ref = ServiceReference(str(serviceref))
extend((
'<e2simulatedtimer>\n'
' <e2servicereference>', stringToXML(serviceref), '</e2servicereference>\n',
' <e2servicename>', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n',
' <e2name>', stringToXML(name), '</e2name>\n',
' <e2timebegin>', str(begin), '</e2timebegin>\n',
' <e2timeend>', str(end), '</e2timeend>\n',
' <e2autotimername>', stringToXML(autotimername), '</e2autotimername>\n',
' <e2state>Skip</e2state>\n'
' <e2message>', stringToXML(message), '</e2message>\n'
'</e2simulatedtimer>\n'
))

if self._stillAlive:
reactor.callFromThread(lambda: self._req.write(''.join(returnlist)))

class AutoTimerSimulateResource(AutoTimerBaseResource):
def render(self, req):
AutoTimerSimulateBackgroundThread(req, None)
Expand All @@ -169,6 +235,11 @@ def render(self, req):
req.setHeader('charset', 'UTF-8')
return ''.join(autotimer.getXml())

class AutoTimerTestResource(AutoTimerBaseResource):
def render(self, req):
AutoTimerTestBackgroundThread(req, None)
return server.NOT_DONE_YET

class AutoTimerRemoveAutoTimerResource(AutoTimerBaseResource):
def render(self, req):
id = req.args.get("id")
Expand Down Expand Up @@ -512,86 +583,7 @@ def render(self, req):
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>config.plugins.autotimer.try_guessing</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>config.plugins.autotimer.editor</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>config.plugins.autotimer.disabled_on_conflict</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>config.plugins.autotimer.addsimilar_on_conflict</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>config.plugins.autotimer.show_in_extensionsmenu</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>config.plugins.autotimer.fastscan</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>config.plugins.autotimer.notifconflict</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>config.plugins.autotimer.notifsimilar</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>config.plugins.autotimer.maxdaysinfuture</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>config.plugins.autotimer.add_autotimer_to_tags</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>config.plugins.autotimer.add_name_to_tags</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>config.plugins.autotimer.timeout</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>config.plugins.autotimer.delay</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>config.plugins.autotimer.editdelay</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>config.plugins.autotimer.skip_during_records</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>config.plugins.autotimer.skip_during_epgrefresh</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>hasVps</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>hasSeriesPlugin</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>version</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
<e2setting>
<e2settingname>api_version</e2settingname>
<e2settingvalue>%s</e2settingvalue>
</e2setting>
</e2settings>""" % (
<e2settingname>config.plugins.autotimer.try_guesings>""" % (
config.plugins.autotimer.autopoll.value,
config.plugins.autotimer.interval.value,
config.plugins.autotimer.refresh.value,
Expand Down
3 changes: 3 additions & 0 deletions autotimer/src/AutoTimerSettings.py
Expand Up @@ -78,6 +78,9 @@ def __init__(self, session):
getConfigListEntry(_("Skip poll during epg refresh"), config.plugins.autotimer.skip_during_epgrefresh, _("If enabled, the polling will be skipped if EPGRefresh is currently running.")),
getConfigListEntry(_("Popup timeout in seconds"), config.plugins.autotimer.popup_timeout, _("If 0, the popup will remain open.")),
getConfigListEntry(_("Remove not existing events"), config.plugins.autotimer.check_eit_and_remove, _("Check the event id (eit) and remove the timer if there is no corresponding EPG event. Due to compatibility issues with SerienRecorder and IPRec, only timer created by AutoTimer are affected.")),
getConfigListEntry(_("Create debug log file"), config.plugins.autotimer.log_write, _("If this enabled, debug Autotimer write in log file.")),
getConfigListEntry(_("Path debug log"), config.plugins.autotimer.log_file, _("Specify the name and location for the log.")),
getConfigListEntry(_("Print shell log"), config.plugins.autotimer.log_shell, _("If this enabled, debug log print in console mode start enigma2.")),
],
session = session,
on_change = self.changed
Expand Down
3 changes: 2 additions & 1 deletion autotimer/src/AutoTimerWizard.py
Expand Up @@ -19,6 +19,8 @@
# Wizard XML Path
from Tools import Directories

from Logger import doLog

class AutoTimerWizard(WizardLanguage, AutoTimerEditorBase, Rc):
STEP_ID_BASIC = 2
STEP_ID_TIMESPAN = 5
Expand Down Expand Up @@ -176,7 +178,6 @@ def yellow(self):
def maybeRemoveWhitespaces(self):
# XXX: Hack alert
if self["list"].current[1] == "removeTrailingWhitespaces":
print("Next step would be to remove trailing whitespaces, removing them and redirecting to 'conf2'")
self.timer.match = self.timer.match.rstrip()
self.match.value = self.match.value.rstrip()
self.currStep = self.getStepWithID("conf2")
Expand Down

0 comments on commit 6b79838

Please sign in to comment.