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