diff --git a/tivomirror b/tivomirror index 8f83304..7d5a051 100755 --- a/tivomirror +++ b/tivomirror @@ -323,13 +323,6 @@ def getAvail(dir): return s.f_bsize * s.f_bavail -def quit_process(pid): - try: - os.kill(pid, signal.SIGQUIT) - except OSError: - pass - - class FdLogger(threading.Thread): def __init__(self, logger, lvl, fd): self.logger = logger @@ -349,58 +342,8 @@ class FdLogger(threading.Thread): self.logger.exception("") -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") - - @timeout(43200) -def download_curl(item, mak, target): - global cookies - url = item.url - logger.info("--- downloading \"%s\"" % (url)) - p_curl = subprocess.Popen(["curl", "--anyauth", "--fail", \ - "--insecure", "--cookie", cookies, \ - "--silent", "--show-error", \ - "--user", "tivo:%s" % mak, "--url", url ], \ - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - p_decode = subprocess.Popen([tivodecode, "--mak", mak, \ - "--no-verify", "--out", target, "-"], stdin=p_curl.stdout, - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - FdLogger(logger, logging.INFO, p_curl.stderr) - FdLogger(logger, logging.INFO, p_decode.stdout) - FdLogger(logger, logging.INFO, p_decode.stderr) - try: - waitForProcs([p_curl.pid, p_decode.pid]) - except Exception, e: - try: - os.remove(target) - except OSError: - pass - raise e - if os.path.getsize(target) < 1024: - print "error transcoding file: too small" - os.remove(target) - raise TivoException("downloaded file is too small") - - -@timeout(43200) -def download_py(item, mak, target): +def download_item(item, mak, target): global session, proxies, headers count = 0 start = time.time() @@ -483,7 +426,7 @@ def download_decode(item, mak): except OSError: pass try: - download_curl(item, mak, target) + download_item(item, mak, target) except Exception, e: exc_info = sys.exc_info() try: