Fix column listing.

This commit is contained in:
Bastian Kleineidam 2012-10-12 21:57:06 +02:00
parent 7bf54255f0
commit aff905e0bd

14
dosage
View file

@ -132,27 +132,31 @@ def doList(columnList):
out.write('Available comic scrapers:') out.write('Available comic scrapers:')
scrapers = getScrapers(['@@']) scrapers = getScrapers(['@@'])
if columnList: if columnList:
doColumnList(scrapers) num = doColumnList(scrapers)
else: else:
doSingleList(scrapers) num = doSingleList(scrapers)
out.write('%d supported comics.' % len(scrapers)) out.write('%d supported comics.' % num)
return 0 return 0
def doSingleList(scrapers): def doSingleList(scrapers):
"""Get list of scraper names, one per line.""" """Get list of scraper names, one per line."""
print '\n'.join(scraperobj.get_name() for scraperobj in scrapers) for num, scraperobj in enumerate(scrapers):
print scraperobj.get_name()
return num
def doColumnList(scrapers): def doColumnList(scrapers):
"""Get list of scraper names with multiple names per line.""" """Get list of scraper names with multiple names per line."""
screenWidth = get_columns() screenWidth = get_columns(sys.stdout)
names = [scraperobj.get_name() for scraperobj in scrapers] names = [scraperobj.get_name() for scraperobj in scrapers]
num = len(names)
maxlen = max([len(name) for name in names]) maxlen = max([len(name) for name in names])
namesPerLine = int(screenWidth / (maxlen + 1)) namesPerLine = int(screenWidth / (maxlen + 1))
while names: while names:
print ''.join([name.ljust(maxlen) for name in names[:namesPerLine]]) print ''.join([name.ljust(maxlen) for name in names[:namesPerLine]])
del names[:namesPerLine] del names[:namesPerLine]
return num
def getScrapers(comics, basepath=None): def getScrapers(comics, basepath=None):