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

12
dosage
View file

@ -174,6 +174,7 @@ def displayHelp(options):
def displayComicHelp(scraperobj): def displayComicHelp(scraperobj):
"""Print description and help for a comic.""" """Print description and help for a comic."""
orig_context = out.context
out.context = getScraperName(scraperobj) out.context = getScraperName(scraperobj)
try: try:
out.info(u"URL: " + scraperobj.url) out.info(u"URL: " + scraperobj.url)
@ -191,7 +192,7 @@ def displayComicHelp(scraperobj):
out.exception(msg) out.exception(msg)
return 1 return 1
finally: finally:
out.context = u'' out.context = orig_context
# the comic scraper job queue # the comic scraper job queue
@ -207,6 +208,7 @@ def get_hostname(url):
lock = threading.Lock() lock = threading.Lock()
def get_host_lock(url): def get_host_lock(url):
"""Get lock object for given URL host."""
hostname = get_hostname(url) hostname = get_hostname(url)
return host_locks.setdefault(hostname, threading.Lock()) return host_locks.setdefault(hostname, threading.Lock())
@ -280,6 +282,7 @@ def voteComics(options):
def voteComic(scraperobj): def voteComic(scraperobj):
"""Vote for given comic scraper.""" """Vote for given comic scraper."""
errors = 0 errors = 0
orig_context = out.context
out.context = getScraperName(scraperobj) out.context = getScraperName(scraperobj)
try: try:
name = scraperobj.getName() name = scraperobj.getName()
@ -298,7 +301,7 @@ def voteComic(scraperobj):
out.exception(msg) out.exception(msg)
errors += 1 errors += 1
finally: finally:
out.context = u'' out.context = orig_context
return errors return errors
@ -356,6 +359,9 @@ def run(options):
def doList(columnList=True, verbose=False): def doList(columnList=True, verbose=False):
"""List available comics.""" """List available comics."""
orig_context = out.context
out.context = u''
try:
page = hasattr(sys.stdout, "isatty") and sys.stdout.isatty() page = hasattr(sys.stdout, "isatty") and sys.stdout.isatty()
if page: if page:
fd = StringIO(u'') fd = StringIO(u'')
@ -372,6 +378,8 @@ def doList(columnList=True, verbose=False):
if page: if page:
pydoc.pager(fd.getvalue()) pydoc.pager(fd.getvalue())
return 0 return 0
finally:
out.context = orig_context
def doSingleList(scrapers, verbose=False): def doSingleList(scrapers, verbose=False):

View file

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