From 78916326b9f04341e5d0c8145f6ead4be7aec035 Mon Sep 17 00:00:00 2001 From: cktricky Date: Thu, 12 Apr 2018 23:58:20 -0400 Subject: [PATCH] so now we can load modules dynamically. Also, the tutorials for python seem insane. Why was this simple answer not the first to pop. Ugh. --- libs/__init__.py | 11 ----------- libs/utils/common.py | 2 +- modules/__init__.py | 5 +---- weirdAAL.py | 6 ++++++ 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/libs/__init__.py b/libs/__init__.py index 7ad8262..e69de29 100644 --- a/libs/__init__.py +++ b/libs/__init__.py @@ -1,11 +0,0 @@ -import os -from libs.utils.common import * - - -# Get the application's path (wherever weirdAAL.py is located will be the dirpath ) -dirpath = os.getcwd() -# The actual location of this file on the filesystem is the "foldername" -foldername = os.path.dirname(os.path.realpath(__file__)) - -all_files = list_all_files(foldername) -__all__ = all_files diff --git a/libs/utils/common.py b/libs/utils/common.py index 4ac82b4..e7136e6 100644 --- a/libs/utils/common.py +++ b/libs/utils/common.py @@ -7,6 +7,6 @@ def list_all_files(directory): for file in list_of_files: filename_and_ext = os.path.splitext(file) - if filename_and_ext[1] == ".py": + if (filename_and_ext[1] == ".py") and not (filename_and_ext[0].startswith("__")): array.append(filename_and_ext[0]) return array diff --git a/modules/__init__.py b/modules/__init__.py index 4f3d876..8eaa350 100644 --- a/modules/__init__.py +++ b/modules/__init__.py @@ -1,12 +1,9 @@ import os from libs.utils.common import * - # Get the application's path (wherever weirdAAL.py is located will be the dirpath ) dirpath = os.getcwd() # The actual location of this file on the filesystem is the "foldername" foldername = os.path.dirname(os.path.realpath(__file__)) -all_files = list_all_files(foldername) - -__all__ = all_files +all_modules = list_all_files(foldername) diff --git a/weirdAAL.py b/weirdAAL.py index 0887c52..1d43717 100755 --- a/weirdAAL.py +++ b/weirdAAL.py @@ -12,6 +12,12 @@ import os from config import AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY from botocore.exceptions import ClientError from modules import * +import sys + +sys.path.append("modules") +for module in all_modules: + exec("from %s import *"%module) + parser = argparse.ArgumentParser() parser.add_argument("-s", "--step", help="list the step you would like to run",