From a040bc7a0263aed473ab1b5ce2f294aeaad81d2b Mon Sep 17 00:00:00 2001 From: "Jip J. Dekker" Date: Sun, 1 Jun 2014 20:01:19 +0200 Subject: [PATCH] Added documentation for the sourceloader --- sourceloader.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sourceloader.py b/sourceloader.py index 9957a70..2ed50a8 100644 --- a/sourceloader.py +++ b/sourceloader.py @@ -1,6 +1,7 @@ import inspect import os import re + from FourmiCrawler.sources.source import Source @@ -8,6 +9,10 @@ class SourceLoader: sources = [] def __init__(self, rel_dir="FourmiCrawler/sources"): + """ + The initiation of a SourceLoader, selects and indexes a directory for usable sources. + :param rel_dir: A relative path to a directory. + """ path = os.path.dirname(os.path.abspath(__file__)) path += "/" + rel_dir known_parser = set() @@ -21,18 +26,30 @@ class SourceLoader: known_parser.add(cls) def include(self, source_names): + """ + This function excludes all sources that don't match the given regular expressions. + :param source_names: A list of regular expression (strings) + """ new = set() for name in source_names: new.update([src for src in self.sources if re.match(name, src.__class__.__name__)]) self.sources = list(new) def exclude(self, source_names): + """ + This function excludes all sources that match the given regular expressions. + :param source_names: A list of regular expression (strings) + """ exclude = [] for name in source_names: exclude.extend([src for src in self.sources if re.match(name, src.__class__.__name__)]) self.sources = [src for src in self.sources if src not in exclude] def __str__(self): + """ + This function returns a string with all sources currently available in the SourceLoader. + :return: a string with all available sources. + """ string = "" for src in self.sources: string += "Source: " + src.__class__.__name__