Skip to content

Commit

Permalink
Check for the LastUpdate.log file on server hosting the data file.
Browse files Browse the repository at this point in the history
If the last successful update is older than 2 days reject the server and switch to another one.
This should fix the problem when server still hold and return obsolete files but are no longer accessible to update them.
  • Loading branch information
Pr2 authored and Pr2 committed Sep 11, 2018
1 parent e47c147 commit 5d0ca05
Showing 1 changed file with 65 additions and 3 deletions.
68 changes: 65 additions & 3 deletions src/EPGImport/EPGImport.py
Expand Up @@ -16,6 +16,16 @@
from twisted.web.client import downloadPage
import twisted.python.runtime

import urllib2, httplib
from datetime import datetime

# Used to check server validity
date_format = "%Y-%m-%d"
now = datetime.now()
alloweddelta = 2
CheckFile = "LastUpdate.log"
ServerStatusList = {}

PARSERS = {
'xmltv': 'gen_xmltv',
'genxmltv': 'gen_xmltv',
Expand All @@ -37,7 +47,7 @@ def getParser(name):
def getTimeFromHourAndMinutes(hour, minute):
now = time.localtime()
begin = int(time.mktime((now.tm_year, now.tm_mon, now.tm_mday,
hour, minute, 0, now.tm_wday, now.tm_yday, now.tm_isdst)))
hour, minute, 0, now.tm_wday, now.tm_yday, now.tm_isdst)))
return begin

def bigStorage(minFree, default, *candidates):
Expand Down Expand Up @@ -94,6 +104,55 @@ def __init__(self, epgcache, channelFilter):
self.epgcache = epgcache
self.channelFilter = channelFilter

def checkValidServer(self, serverurl):
dirname, filename = os.path.split(serverurl)
FullString = dirname + "/" + CheckFile
req = urllib2.build_opener()
req.addheaders = [('User-Agent', 'Twisted Client')]
dlderror=0
if ServerStatusList.has_key(dirname):
# If server is know return its status immediately
return ServerStatusList[dirname]
else:
# Server not in the list so checking it
try:
response = req.open(FullString)
except urllib2.HTTPError, e:
print ('[EPGImport] HTTPError in checkValidServer= ' + str(e.code))
dlderror=1
except urllib2.URLError, e:
print ('[EPGImport] URLError in checkValidServer= ' + str(e.reason))
dlderror=1
except httplib.HTTPException, e:
print ('[EPGImport] HTTPException in checkValidServer')
dlderror=1
except Exception:
print ('[EPGImport] Generic exception in checkValidServer')
dlderror=1

if not dlderror:
LastTime = response.read().strip('\n')
try:
FileDate = datetime.strptime(LastTime, date_format)
except ValueError:
print>>log, "[EPGImport] checkValidServer wrong date format in file rejecting server %s" % dirname
ServerStatusList[dirname]=0
return ServerStatusList[dirname]
delta = (now - FileDate).days
if delta <= alloweddelta:
# OK the delta is in the foreseen windows
ServerStatusList[dirname]=1
else:
# Sorry the delta is higher removing this site
print>>log, "[EPGImport] checkValidServer rejected server delta days too high: %s" % dirname
ServerStatusList[dirname]=0

else:
# We need to exclude this server
print>>log, "[EPGImport] checkValidServer rejected server download error for: %s" % dirname
ServerStatusList[dirname]=0
return ServerStatusList[dirname]

def beginImport(self, longDescUntil = None):
'Starts importing using Enigma reactor. Set self.sources before calling this.'
if hasattr(self.epgcache, 'importEvents'):
Expand Down Expand Up @@ -357,5 +416,8 @@ def do_download(self, sourcefile, afterDownload, downloadFail):
filename += ext
sourcefile = sourcefile.encode('utf-8')
print>>log, "[EPGImport] Downloading: " + sourcefile + " to local path: " + filename
downloadPage(sourcefile, filename).addCallbacks(afterDownload, downloadFail, callbackArgs=(filename,True))
return filename
if self.checkValidServer(sourcefile) == 1:
downloadPage(sourcefile, filename).addCallbacks(afterDownload, downloadFail, callbackArgs=(filename,True))
return filename
else:
self.downloadFail("checkValidServer reject the server")

This comment has been minimized.

Copy link
@davegudge

davegudge Sep 12, 2018

I'm hitting this line when attempting to import from a new source for the first time i.e. first import after flashing the box.

img_4058

3 comments on commit 5d0ca05

@kiddac
Copy link

@kiddac kiddac commented on 5d0ca05 Sep 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everybody is now trying to fix the total mess you have caused.

@pr2git
Copy link
Contributor

@pr2git pr2git commented on 5d0ca05 Sep 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rytecepg.dyndns.tv is the OpenViX mirror, from this server the downloading of the LastUpdate.log is not possible.
So ask OpenVix to fix the problem!

If OpenViX has some mechanism to only allow download from this server from OpenViX image then this sources must be excluded from the Rytec sources files and OpenViX need to create there own source file with there own mirror.

@pr2git
Copy link
Contributor

@pr2git pr2git commented on 5d0ca05 Sep 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rytecepg.wanwizard.eu I asked Doglover to properly define the LastUpdate.log on it.

Please sign in to comment.