Fix exit code on errors.

This commit is contained in:
Bastian Kleineidam 2013-03-11 20:05:06 +01:00
parent 7eaf12caf6
commit dc2e3c807f
2 changed files with 11 additions and 7 deletions

17
dosage
View file

@ -127,8 +127,12 @@ def saveComicStrip(strip, basepath):
def displayHelp(comics): def displayHelp(comics):
"""Print help for comic strips.""" """Print help for comic strips."""
for scraperobj in getScrapers(comics): try:
displayComicHelp(scraperobj) for scraperobj in getScrapers(comics):
displayComicHelp(scraperobj)
except ValueError as msg:
out.error(msg)
return 1
return 0 return 0
@ -157,6 +161,9 @@ def getComics(options):
try: try:
for scraperobj in getScrapers(options.comic, options.basepath, options.adult, options.multimatch): for scraperobj in getScrapers(options.comic, options.basepath, options.adult, options.multimatch):
errors += getStrips(scraperobj, options) errors += getStrips(scraperobj, options)
except ValueError as msg:
out.error(msg)
errors += 1
finally: finally:
events.getHandler().end() events.getHandler().end()
return errors return errors
@ -293,11 +300,7 @@ def getScrapers(comics, basepath=None, adult=True, multiple_allowed=False):
else: else:
name = comic name = comic
indexes = None indexes = None
try: scraperclasses = scraper.find_scraperclasses(name, multiple_allowed=multiple_allowed)
scraperclasses = scraper.find_scraperclasses(name, multiple_allowed=multiple_allowed)
except ValueError as msg:
out.error(msg)
continue
for scraperclass in scraperclasses: for scraperclass in scraperclasses:
if not adult and scraperclass.adult: if not adult and scraperclass.adult:
warn_adult(scraperclass) warn_adult(scraperclass)

View file

@ -51,6 +51,7 @@ class TestDosage (unittest.TestCase):
def test_error(self): def test_error(self):
self.assertRaises(OSError, run_with_options, []) self.assertRaises(OSError, run_with_options, [])
self.assertRaises(OSError, run_with_options, ['--imadoofus']) self.assertRaises(OSError, run_with_options, ['--imadoofus'])
self.assertRaises(OSError, run_with_options, ['Garfield'])
def test_fetch_html(self): def test_fetch_html(self):
run_with_options(["-n", "2", "-b", self.tmpdir, "-o", "html", "-o", "rss", "calvinandhobbes"]) run_with_options(["-n", "2", "-b", self.tmpdir, "-o", "html", "-o", "rss", "calvinandhobbes"])