Verbesserte Fehlerbehandlung
This commit is contained in:
parent
d1ebd921e1
commit
fe5a731dfd
1 changed files with 41 additions and 30 deletions
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
# $Schlepperbande: src/tivomirror/tivomirror,v 1.34 2010/08/07 13:40:31 stb Exp $
|
# $Schlepperbande: src/tivomirror/tivomirror,v 1.35 2010/08/07 13:42:24 stb Exp $
|
||||||
#
|
#
|
||||||
# Stefans Script, um die Sendungen vom Tivo runterzuladen und in MPEG4
|
# Stefans Script, um die Sendungen vom Tivo runterzuladen und in MPEG4
|
||||||
# zu transkodieren.
|
# zu transkodieren.
|
||||||
|
@ -99,6 +99,34 @@ def getAvail(dir):
|
||||||
s = os.statvfs(dir)
|
s = os.statvfs(dir)
|
||||||
return s.f_bsize * s.f_bavail
|
return s.f_bsize * s.f_bavail
|
||||||
|
|
||||||
|
|
||||||
|
def quit_process(pid):
|
||||||
|
try:
|
||||||
|
os.kill(pid, signal.SIGQUIT)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def waitForProcs(pids):
|
||||||
|
success = True
|
||||||
|
while len(pids) > 0:
|
||||||
|
(spid, sse) = os.wait()
|
||||||
|
pids.remove(spid)
|
||||||
|
if os.WIFSIGNALED(sse) \
|
||||||
|
or (os.WIFEXITED(sse) and os.WEXITSTATUS(sse) != 0):
|
||||||
|
if os.WIFSIGNALED(sse):
|
||||||
|
print "--- process %d was terminated by signal %d" % (spid, os.WTERMSIG(sse))
|
||||||
|
elif os.WIFEXITED(sse):
|
||||||
|
print "--- process %d exited with code %d" % (spid, os.WEXITSTATUS(sse))
|
||||||
|
else:
|
||||||
|
print "--- process %d terminated unsuccessfully" % spid
|
||||||
|
success = False
|
||||||
|
for pid in pids:
|
||||||
|
quit_process(pid)
|
||||||
|
if not success:
|
||||||
|
raise TivoException("error executing processes")
|
||||||
|
|
||||||
|
|
||||||
def transcode(file, src, passno, ar):
|
def transcode(file, src, passno, ar):
|
||||||
print "--- transcoding pass %d" % passno
|
print "--- transcoding pass %d" % passno
|
||||||
try:
|
try:
|
||||||
|
@ -144,30 +172,6 @@ def transcode(file, src, passno, ar):
|
||||||
subprocess.check_call(transcode_opts)
|
subprocess.check_call(transcode_opts)
|
||||||
|
|
||||||
|
|
||||||
def checkProcessError(curl, decode):
|
|
||||||
(spid, sse) = os.wait()
|
|
||||||
if not os.WIFSIGNALED(sse) \
|
|
||||||
and os.WIFEXITED(sse) and os.WEXITSTATUS(sse) == 0:
|
|
||||||
return False
|
|
||||||
if spid == curl.pid:
|
|
||||||
proc = "curl"
|
|
||||||
elif spid == decode.pid:
|
|
||||||
proc = "tivodecode"
|
|
||||||
if os.WIFSIGNALED(sse):
|
|
||||||
cause = "exited with signal %d" % os.WTERMSIG(sse)
|
|
||||||
else:
|
|
||||||
cause = "exited with code %d" % os.WEXITSTATUS(sse)
|
|
||||||
proc = "another"
|
|
||||||
print "--- %s %s" % (proc, cause)
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def quit_process(pid):
|
|
||||||
try:
|
|
||||||
os.kill(pid, signal.SIGQUIT)
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def download(file, url, mak, target):
|
def download(file, url, mak, target):
|
||||||
print "--- dowloading \"%s\"" % (url)
|
print "--- dowloading \"%s\"" % (url)
|
||||||
p_curl = subprocess.Popen(["curl", "--anyauth", "--fail", \
|
p_curl = subprocess.Popen(["curl", "--anyauth", "--fail", \
|
||||||
|
@ -177,16 +181,20 @@ def download(file, url, mak, target):
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE)
|
||||||
p_decode = subprocess.Popen(["tivodecode", "--mak", mak, \
|
p_decode = subprocess.Popen(["tivodecode", "--mak", mak, \
|
||||||
"--out", target, "-"], stdin=p_curl.stdout)
|
"--out", target, "-"], stdin=p_curl.stdout)
|
||||||
if checkProcessError(p_curl, p_decode) or checkProcessError(p_curl, p_decode):
|
try:
|
||||||
quit_process(p_curl.pid)
|
waitForProcs([p_curl.pid, p_decode.pid])
|
||||||
quit_process(p_decode.pid.pid)
|
except Exception, e:
|
||||||
os.remove(target)
|
try:
|
||||||
raise TivoException("error downloading/decoding file")
|
os.remove(target)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
raise e
|
||||||
if os.path.getsize(target) < 1024:
|
if os.path.getsize(target) < 1024:
|
||||||
print "error transcoding file: too small"
|
print "error transcoding file: too small"
|
||||||
os.remove(target)
|
os.remove(target)
|
||||||
raise TivoException("downloaded file is too small")
|
raise TivoException("downloaded file is too small")
|
||||||
|
|
||||||
|
|
||||||
def download_decode(file, url, mak, ar):
|
def download_decode(file, url, mak, ar):
|
||||||
#target = tmpmp2
|
#target = tmpmp2
|
||||||
target = "%s.mpg" % file
|
target = "%s.mpg" % file
|
||||||
|
@ -206,11 +214,13 @@ def download_decode(file, url, mak, ar):
|
||||||
os.remove(tmpmp2)
|
os.remove(tmpmp2)
|
||||||
os.remove(tmpmp4)
|
os.remove(tmpmp4)
|
||||||
|
|
||||||
|
|
||||||
def savetoc(toc):
|
def savetoc(toc):
|
||||||
fd=open("toc.xml", "w")
|
fd=open("toc.xml", "w")
|
||||||
fd.write(toc)
|
fd.write(toc)
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
|
|
||||||
curdir = os.getcwd()
|
curdir = os.getcwd()
|
||||||
os.chdir(tmp)
|
os.chdir(tmp)
|
||||||
avail = getAvail(targetdir)
|
avail = getAvail(targetdir)
|
||||||
|
@ -218,6 +228,7 @@ if avail < minfree:
|
||||||
print "%s: %.1fG available, at least %.1fG needed, stopping" % \
|
print "%s: %.1fG available, at least %.1fG needed, stopping" % \
|
||||||
(targetdir, avail / gig, minfree / gig)
|
(targetdir, avail / gig, minfree / gig)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
downloaddb = anydbm.open(curdir + "/tivo/.downloads", "c")
|
downloaddb = anydbm.open(curdir + "/tivo/.downloads", "c")
|
||||||
print "*** Getting listing"
|
print "*** Getting listing"
|
||||||
toc = gettoc()
|
toc = gettoc()
|
||||||
|
|
Loading…
Reference in a new issue