Add more documentation.

This commit is contained in:
Bastian Kleineidam 2012-10-11 18:02:29 +02:00
parent 4470e13b1a
commit 194d1e28b1
5 changed files with 19 additions and 4 deletions

1
dosage
View file

@ -82,6 +82,7 @@ def displayHelp(comics, basepath):
return 0
def getComics(options, comics):
"""Retrieve given comics."""
errors = 0
events.installHandler(options.output, options.basepath, options.baseurl)
events.handler.start()

View file

@ -39,4 +39,3 @@ import sys
if not (hasattr(sys, 'version_info') or
sys.version_info < (2, 5, 0, 'final', 0)):
raise SystemExit("This program requires Python 2.5 or later.")

View file

@ -70,6 +70,7 @@ class CONSOLE_SCREEN_BUFFER_INFO(Structure):
("dwMaximumWindowSize", COORD),
]
def __str__(self):
"""Get string representation of console screen buffer info."""
return '(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)' % (
self.dwSize.Y, self.dwSize.X
, self.dwCursorPosition.Y, self.dwCursorPosition.X
@ -79,6 +80,7 @@ class CONSOLE_SCREEN_BUFFER_INFO(Structure):
)
def GetConsoleScreenBufferInfo(stream_id=STDOUT):
"""Get console screen buffer info object."""
handle = handles[stream_id]
csbi = CONSOLE_SCREEN_BUFFER_INFO()
success = windll.kernel32.GetConsoleScreenBufferInfo(
@ -87,6 +89,7 @@ def GetConsoleScreenBufferInfo(stream_id=STDOUT):
def SetConsoleTextAttribute(stream_id, attrs):
"""Set a console text attribute."""
handle = handles[stream_id]
return windll.kernel32.SetConsoleTextAttribute(handle, attrs)
@ -111,6 +114,7 @@ _default_style = None
def init():
"""Initialize foreground and background attributes."""
global _default_foreground, _default_background, _default_style
attrs = GetConsoleScreenBufferInfo(STDOUT).wAttributes
_default_foreground = attrs & 7
@ -119,10 +123,12 @@ def init():
def get_attrs(foreground, background, style):
"""Get foreground and background attributes."""
return foreground + (background << 4) + style
def set_console(stream=STDOUT, foreground=None, background=None, style=None):
"""Set console foreground and background attributes."""
if foreground is None:
foreground = _default_foreground
if background is None:
@ -134,8 +140,10 @@ def set_console(stream=STDOUT, foreground=None, background=None, style=None):
def reset_console(stream=STDOUT):
"""Reset the console."""
set_console(stream=stream)
def get_console_size():
"""Get the console size."""
return GetConsoleScreenBufferInfo(STDOUT).dwSize

View file

@ -31,18 +31,21 @@ class ComicStrip(object):
yield self.getDownloader(normaliseURL(imageUrl))
def getDownloader(self, url):
"""Get an image downloader."""
filename = self.namer(url, self.parentUrl)
if filename is None:
filename = url.rsplit('/', 1)[1]
return ComicImage(self.name, url, self.parentUrl, filename)
class ComicImage(object):
"""A comic image downloader."""
def __init__(self, name, url, referrer, filename):
"""Set URL and filename."""
self.name = name
self.referrer = referrer
self.url = url
if filename is None:
filename = url.rsplit('/', 1)[1]
self.filename, self.ext = os.path.splitext(filename)
self.filename = self.filename.replace(os.sep, '_')
self.ext = self.ext.replace(os.sep, '_')

View file

@ -1,8 +1,12 @@
# -*- coding: iso-8859-1 -*-
# Copyright (C) 2012 Bastian Kleineidam
"""
Functions to load plugin modules.
"""
import os
import sys
def get_modules(folder, importprefix):
"""Find all valid modules in the plugins directory. A valid module
must have a .py extension, and is importable.