Fix download command

Also implement proper usage on error or -h
This commit is contained in:
Stefan Bethke 2017-11-02 00:25:12 +01:00
parent b77ae6c9a8
commit 4b67699a39

View file

@ -538,9 +538,14 @@ def mirror(toc, downloaddb, one=False):
def download_episode(toc, downloaddb, episode):
items = toc.getItems()
options = {}
for item in items:
if item.title == episode or item.name == episode or item.episode == episode:
download_one(item, downloaddb)
for i in (item.title, item.episode, item.name):
if IncludeShow.includes.has_key(i):
options = IncludeShow.includes[i]
download_one(item, downloaddb, options)
return
def printtoc(toc, downloaddb):
@ -561,6 +566,12 @@ def printtoc(toc, downloaddb):
print "*** {} shows listed".format(len(items))
def usage():
print >>sys.stderr, 'usage: tivomirror -dvuT [-c config] cmd'
print >>sys.stderr, ' cmd is one of download, list, mirror, mirrorone'
sys.exit(64)
def main():
global config, logger
curdir = os.getcwd()
@ -576,8 +587,8 @@ def main():
conffile = None
try:
options, remainder = getopt.getopt(sys.argv[1:], 'c:dvuT',
['config', 'ignoreepisodetitle', 'debug', 'verbose', 'update'])
options, remainder = getopt.getopt(sys.argv[1:], 'c:dhvuT?',
['config', 'ignoreepisodetitle', 'debug', 'verbose', 'update', help])
for opt, arg in options:
if opt in ('-c', '--config'):
@ -591,6 +602,8 @@ def main():
updateToc = True
if opt in ('-T', '--ignoreepisodetitle'):
config.ignoreepisodetitle = True
if opt in ('-h', '-?', '--help'):
usage()
config = Config(conffile)
@ -614,9 +627,12 @@ def main():
else:
logger.error("invalid command {}".format(cmd))
print >>sys.stderr, "invalid command {}".format(cmd)
sys.exit(64)
usage()
downloaddb.close()
except getopt.GetoptError as e:
print >>sys.stderr, 'Error parsing options: {}'.format(e)
usage()
except Exception:
logger.exception("")
logger.info("*** Completed")