From 574cea3fc8121d72af808c9e1e1fff4116fe9dfc Mon Sep 17 00:00:00 2001 From: David Lynch Date: Fri, 23 Sep 2016 12:51:03 -0500 Subject: [PATCH] Make the sites system not require editing __init__.py --- sites/__init__.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sites/__init__.py b/sites/__init__.py index f73e03f..104cc19 100644 --- a/sites/__init__.py +++ b/sites/__init__.py @@ -1,4 +1,6 @@ +import glob +import os import argparse from bs4 import BeautifulSoup @@ -101,5 +103,12 @@ def get(url): if site_class.matches(url): return site_class -# And now, the things that will use this: -from . import xenforo, fanfictionnet, deviantart, stash, ao3 # noqa + +# And now, a particularly hacky take on a plugin system: +# Make an __all__ out of all the python files in this directory that don't start +# with __. Then import * them. + +modules = glob.glob(os.path.join(os.path.dirname(__file__), "*.py")) +__all__ = [os.path.basename(f)[:-3] for f in modules if not f.startswith("__")] + +from . import * # noqa