diff --git a/tools/make_man.py b/tools/make_man.py index 589313c83b081920dd6637bc386a367950d1471c..5b45c5232475abdf306c97bcf3edecac07e3d26c 100755 --- a/tools/make_man.py +++ b/tools/make_man.py @@ -106,39 +106,26 @@ def format_option_strings(self, option): def main(): - scripts_path = os.path.join(BASE_PATH, "scripts") + scripts_path = os.path.join(BASE_PATH, 'weboob', 'applications') files = os.listdir(scripts_path) completions = dict() - # Create a fake "scripts" modules to import the scripts into - sys.modules["scripts"] = imp.new_module("scripts") - for fname in files: fpath = os.path.join(scripts_path, fname) - if os.path.isfile(fpath) and os.access(fpath, os.X_OK): - with open(fpath) as f: - # Python will likely want create a compiled file, we provide a place - tmpdir = os.path.join(tempfile.gettempdir(), "weboob", "make_man") - if not os.path.isdir(tmpdir): - os.makedirs(tmpdir) - tmpfile = os.path.join(tmpdir, fname) - - desc = ("", "U", imp.PY_SOURCE) - try: - script = imp.load_module("scripts.%s" % fname, f, tmpfile, desc) - except ImportError as e: - print("Unable to load the %s script (%s)" - % (fname, e), file=sys.stderr) - else: - print("Loaded %s" % fname) - # Find the applications we can handle - for klass in script.__dict__.values(): - if inspect.isclass(klass) and issubclass(klass, Application) and klass.VERSION: - completions[fname] = analyze_application(klass, fname) - finally: - # Cleanup compiled files if needed - if (os.path.isfile(tmpfile + "c")): - os.unlink(tmpfile + "c") + if os.path.isdir(fpath) and not fname.startswith('_'): + try: + fp, pathname, description = imp.find_module(fname, [scripts_path]) + module = imp.load_module(fname, fp, pathname, description) + except OSError as e: + print("Unable to load the %s application (%s)" + % (fname, e), file=sys.stderr) + else: + print("Loaded %s" % fname) + # Find the applications we can handle + for klass in module.__dict__.values(): + if inspect.isclass(klass) and issubclass(klass, Application) and klass.VERSION: + completions[klass.APPNAME] = analyze_application(klass, klass.APPNAME) + write_completions(completions)