Fix comic list output.

This commit is contained in:
Bastian Kleineidam 2014-01-05 17:37:13 +01:00
parent cc4f94e9cf
commit ef17268ace
2 changed files with 28 additions and 20 deletions

44
dosage
View file

@ -174,6 +174,7 @@ def displayHelp(options):
def displayComicHelp(scraperobj):
"""Print description and help for a comic."""
orig_context = out.context
out.context = getScraperName(scraperobj)
try:
out.info(u"URL: " + scraperobj.url)
@ -191,7 +192,7 @@ def displayComicHelp(scraperobj):
out.exception(msg)
return 1
finally:
out.context = u''
out.context = orig_context
# the comic scraper job queue
@ -207,6 +208,7 @@ def get_hostname(url):
lock = threading.Lock()
def get_host_lock(url):
"""Get lock object for given URL host."""
hostname = get_hostname(url)
return host_locks.setdefault(hostname, threading.Lock())
@ -280,6 +282,7 @@ def voteComics(options):
def voteComic(scraperobj):
"""Vote for given comic scraper."""
errors = 0
orig_context = out.context
out.context = getScraperName(scraperobj)
try:
name = scraperobj.getName()
@ -298,7 +301,7 @@ def voteComic(scraperobj):
out.exception(msg)
errors += 1
finally:
out.context = u''
out.context = orig_context
return errors
@ -356,22 +359,27 @@ def run(options):
def doList(columnList=True, verbose=False):
"""List available comics."""
page = hasattr(sys.stdout, "isatty") and sys.stdout.isatty()
if page:
fd = StringIO(u'')
out.setStream(fd)
out.info(u'Available comic scrapers:')
out.info(u'Comics tagged with [%s] require age confirmation with the --adult option.' % TAG_ADULT)
out.info(u'Non-english comics are tagged with [%s].' % TAG_LANG)
scrapers = sorted(getScrapers(['@@']), key=lambda s: s.getName())
if columnList:
num = doColumnList(scrapers)
else:
num = doSingleList(scrapers, verbose=verbose)
out.info(u'%d supported comics.' % num)
if page:
pydoc.pager(fd.getvalue())
return 0
orig_context = out.context
out.context = u''
try:
page = hasattr(sys.stdout, "isatty") and sys.stdout.isatty()
if page:
fd = StringIO(u'')
out.setStream(fd)
out.info(u'Available comic scrapers:')
out.info(u'Comics tagged with [%s] require age confirmation with the --adult option.' % TAG_ADULT)
out.info(u'Non-english comics are tagged with [%s].' % TAG_LANG)
scrapers = sorted(getScrapers(['@@']), key=lambda s: s.getName())
if columnList:
num = doColumnList(scrapers)
else:
num = doSingleList(scrapers, verbose=verbose)
out.info(u'%d supported comics.' % num)
if page:
pydoc.pager(fd.getvalue())
return 0
finally:
out.context = orig_context
def doSingleList(scrapers, verbose=False):

View file

@ -21,7 +21,7 @@ class Output(object):
def __init__(self, stream=None):
"""Initialize context and indentation."""
self.context = u''
self.context = None
self.level = 0
self.timestamps = False
if stream is None:
@ -77,7 +77,7 @@ class Output(object):
with lock:
if self.context:
self.stream.write(u'%s%s> ' % (timestamp, self.context))
else:
elif self.context is None:
self.stream.write(u'%s%s> ' % (timestamp, get_threadname()))
self.stream.write(u'%s' % s, color=color)
try: