Improved documentation.

This commit is contained in:
Bastian Kleineidam 2013-03-25 19:47:29 +01:00
parent 4338afc1a7
commit 9d1f286424
2 changed files with 10 additions and 5 deletions

View file

@ -198,6 +198,7 @@ class JSONEventHandler(EventHandler):
return fn return fn
def getComicData(self, comic): def getComicData(self, comic):
"""Return dictionary with comic info."""
if comic not in self.data: if comic not in self.data:
if os.path.exists(self.jsonFn(comic)): if os.path.exists(self.jsonFn(comic)):
with codecs.open(self.jsonFn(comic), 'r', 'utf-8') as f: with codecs.open(self.jsonFn(comic), 'r', 'utf-8') as f:
@ -207,6 +208,7 @@ class JSONEventHandler(EventHandler):
return self.data[comic] return self.data[comic]
def getPageInfo(self, comic, url): def getPageInfo(self, comic, url):
"""Return dictionary with comic page info."""
comicData = self.getComicData(comic) comicData = self.getComicData(comic)
if url not in comicData['pages']: if url not in comicData['pages']:
comicData['pages'][url] = {'images':{}} comicData['pages'][url] = {'images':{}}
@ -260,12 +262,12 @@ class MultiHandler(object):
"""Encapsulate a list of handlers.""" """Encapsulate a list of handlers."""
def start(self): def start(self):
"""Emit a start event. Should be overridden in subclass.""" """Emit start events for handlers."""
for handler in _handlers: for handler in _handlers:
handler.start() handler.start()
def comicDownloaded(self, comic, filename): def comicDownloaded(self, comic, filename):
"""Emit a comic downloaded event. Should be overridden in subclass.""" """Emit comic downloaded events for handlers."""
for handler in _handlers: for handler in _handlers:
handler.comicDownloaded(comic, filename) handler.comicDownloaded(comic, filename)
@ -275,7 +277,7 @@ class MultiHandler(object):
handler.comicPageLink(comic, url, prevUrl) handler.comicPageLink(comic, url, prevUrl)
def end(self): def end(self):
"""Emit an end event. Should be overridden in subclass.""" """Emit end events for handlers."""
for handler in _handlers: for handler in _handlers:
handler.end() handler.end()

View file

@ -12,14 +12,16 @@ import codecs
import json import json
def jsonFn(d): def jsonFn(d):
"""Get JSON filename."""
return os.path.join(d, 'dosage.json') return os.path.join(d, 'dosage.json')
def loadJson(d): def loadJson(d):
"""Return JSON data."""
with codecs.open(jsonFn(d), 'r', 'utf-8') as f: with codecs.open(jsonFn(d), 'r', 'utf-8') as f:
data = json.load(f) return json.load(f)
return data
def prepare_output(d): def prepare_output(d):
"""Clean pre-existing links in output directory."""
outDir = os.path.join(d, 'inorder') outDir = os.path.join(d, 'inorder')
if not os.path.exists(outDir): if not os.path.exists(outDir):
os.mkdir(outDir) os.mkdir(outDir)
@ -30,6 +32,7 @@ def prepare_output(d):
return outDir return outDir
def create_symlinks(d): def create_symlinks(d):
"""Create new symbolic links in output directory."""
data = loadJson(d) data = loadJson(d)
outDir = prepare_output(d) outDir = prepare_output(d)