adding no downsize option

This commit is contained in:
Damjan Košir 2015-05-20 22:38:29 +12:00
parent 77a9cce00d
commit 4529fdee3b
3 changed files with 12 additions and 6 deletions

1
dosage
View file

@ -75,6 +75,7 @@ def setupOptions():
parser.add_argument('-m', '--modulehelp', action='store_true', help='display help for comic modules') parser.add_argument('-m', '--modulehelp', action='store_true', help='display help for comic modules')
parser.add_argument('-t', '--timestamps', action='store_true', help='print timestamps for all output at any info level') parser.add_argument('-t', '--timestamps', action='store_true', help='print timestamps for all output at any info level')
parser.add_argument('-o', '--output', action='append', dest='handler', choices=events.getHandlerNames(), help='sets output handlers for downloaded comics') parser.add_argument('-o', '--output', action='append', dest='handler', choices=events.getHandlerNames(), help='sets output handlers for downloaded comics')
parser.add_argument('--no-downscale', action='store_false', dest='allowdownscale', help='prevent downscaling when using html or rss handler')
parser.add_argument('-p', '--parallel', action='store', type=int, default=1, help='fetch comics in parallel. Specify the number of connections') parser.add_argument('-p', '--parallel', action='store', type=int, default=1, help='fetch comics in parallel. Specify the number of connections')
parser.add_argument('--adult', action='store_true', help='confirms that you are old enough to view adult content') parser.add_argument('--adult', action='store_true', help='confirms that you are old enough to view adult content')
# used for development testing prev/next matching # used for development testing prev/next matching

View file

@ -154,7 +154,7 @@ def getComics(options):
"""Retrieve comics.""" """Retrieve comics."""
if options.handler: if options.handler:
for name in set(options.handler): for name in set(options.handler):
events.addHandler(name, options.basepath, options.baseurl) events.addHandler(name, options.basepath, options.baseurl, options.allowdownscale)
events.getHandler().start() events.getHandler().start()
errors = 0 errors = 0
try: try:

View file

@ -20,10 +20,11 @@ class EventHandler(object):
"""Base class for writing events to files. The currently defined events are """Base class for writing events to files. The currently defined events are
start(), comicDownloaded() and end().""" start(), comicDownloaded() and end()."""
def __init__(self, basepath, baseurl): def __init__(self, basepath, baseurl, allowdownscale):
"""Initialize base path and url.""" """Initialize base path and url."""
self.basepath = basepath self.basepath = basepath
self.baseurl = baseurl or self.getBaseUrl() self.baseurl = baseurl or self.getBaseUrl()
self.allowdownscale = allowdownscale
def getBaseUrl(self): def getBaseUrl(self):
'''Return a file: URL that probably points to the basedir. '''Return a file: URL that probably points to the basedir.
@ -87,7 +88,9 @@ class RSSEventHandler(EventHandler):
def comicDownloaded(self, comic, filename, text=None): def comicDownloaded(self, comic, filename, text=None):
"""Write RSS entry for downloaded comic.""" """Write RSS entry for downloaded comic."""
imageUrl = self.getUrlFromFilename(filename) imageUrl = self.getUrlFromFilename(filename)
size = getDimensionForImage(filename, MaxImageSize) size = None
if self.allowdownscale:
size = getDimensionForImage(filename, MaxImageSize)
title = '%s - %s' % (comic.name, os.path.basename(filename)) title = '%s - %s' % (comic.name, os.path.basename(filename))
pageUrl = comic.referrer pageUrl = comic.referrer
description = '<img src="%s"' % imageUrl description = '<img src="%s"' % imageUrl
@ -198,7 +201,9 @@ class HtmlEventHandler(EventHandler):
"""Write HTML entry for downloaded comic.""" """Write HTML entry for downloaded comic."""
if self.lastComic != comic.name: if self.lastComic != comic.name:
self.newComic(comic) self.newComic(comic)
size = getDimensionForImage(filename, MaxImageSize) size = None
if self.allowdownscale:
size = getDimensionForImage(filename, MaxImageSize)
imageUrl = self.getUrlFromFilename(filename) imageUrl = self.getUrlFromFilename(filename)
pageUrl = comic.referrer pageUrl = comic.referrer
if pageUrl != self.lastUrl: if pageUrl != self.lastUrl:
@ -302,11 +307,11 @@ def getHandlerNames():
_handlers = [] _handlers = []
def addHandler(name, basepath=None, baseurl=None): def addHandler(name, basepath=None, baseurl=None, allowDownscale=False):
"""Add an event handler with given name.""" """Add an event handler with given name."""
if basepath is None: if basepath is None:
basepath = '.' basepath = '.'
_handlers.append(_handler_classes[name](basepath, baseurl)) _handlers.append(_handler_classes[name](basepath, baseurl, allowDownscale))
class MultiHandler(object): class MultiHandler(object):