Code cleanup and simplification.
This commit is contained in:
parent
62411a4970
commit
4dec964cb7
1 changed files with 10 additions and 14 deletions
24
dosage
24
dosage
|
@ -51,7 +51,8 @@ def setupOptions():
|
||||||
|
|
||||||
class Dosage(object):
|
class Dosage(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, settings):
|
||||||
|
self.settings = settings
|
||||||
self.errors = 0
|
self.errors = 0
|
||||||
|
|
||||||
def setOutputInfo(self):
|
def setOutputInfo(self):
|
||||||
|
@ -119,10 +120,11 @@ class Dosage(object):
|
||||||
def doList(self, columnList):
|
def doList(self, columnList):
|
||||||
out.write('Available comic scrapers:')
|
out.write('Available comic scrapers:')
|
||||||
scrapers = self.getScrapers()
|
scrapers = self.getScrapers()
|
||||||
if columnList:
|
if len(scrapers) > 0:
|
||||||
self.doColumnList(scrapers)
|
if columnList:
|
||||||
else:
|
self.doColumnList(scrapers)
|
||||||
self.doSingleList(scrapers)
|
else:
|
||||||
|
self.doSingleList(scrapers)
|
||||||
out.write('%d supported comics.' % len(scrapers))
|
out.write('%d supported comics.' % len(scrapers))
|
||||||
|
|
||||||
def doSingleList(self, scrapers):
|
def doSingleList(self, scrapers):
|
||||||
|
@ -133,14 +135,9 @@ class Dosage(object):
|
||||||
screenWidth = getWindowSize()
|
screenWidth = getWindowSize()
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
screenWidth = 80
|
screenWidth = 80
|
||||||
|
|
||||||
if len(scrapers) == 0:
|
|
||||||
return
|
|
||||||
|
|
||||||
names = [scraper.get_name() for scraper in scrapers]
|
names = [scraper.get_name() for scraper in scrapers]
|
||||||
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]
|
||||||
|
@ -193,8 +190,7 @@ class Dosage(object):
|
||||||
print Copyright
|
print Copyright
|
||||||
print Freeware
|
print Freeware
|
||||||
|
|
||||||
def run(self, settings, comics):
|
def run(self, comics):
|
||||||
self.settings = settings
|
|
||||||
self.setOutputInfo()
|
self.setOutputInfo()
|
||||||
self.comics = comics
|
self.comics = comics
|
||||||
|
|
||||||
|
@ -221,8 +217,8 @@ def main():
|
||||||
try:
|
try:
|
||||||
parser = setupOptions()
|
parser = setupOptions()
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
d = Dosage()
|
d = Dosage(options.__dict__)
|
||||||
d.run(options.__dict__, args)
|
d.run(args)
|
||||||
if d.errors:
|
if d.errors:
|
||||||
res = 1
|
res = 1
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue