コード例 #1
0
ファイル: plugin.py プロジェクト: ssato/python-myrepo
    def test_20_load_plugin_modules__w_plugdir(self):
        srcs = glob.glob(
            os.path.join(TC.selfdir(), MP.PLUGINS_FILENAME_PATTERN)
        )
        dst = os.path.join(self.workdir, MP.PLUGINS_SUBDIR)

        if not os.path.exists(dst):
            os.makedirs(dst)

        for f in srcs:
            shutil.copy(f, dst)

        modnames = sorted(
            os.path.basename(os.path.splitext(f)[0]) for f in srcs
        )

        ms = MP.load_plugin_modules(dst, MP.PLUGINS_FILENAME_PATTERN)

        for n, m in itertools.izip(modnames, ms):
            self.assertEquals(n, m.__name__)
コード例 #2
0
ファイル: hooks.py プロジェクト: ssato/python-myrepo
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
import myrepo.plugin as MP
import logging
import sys

from functools import partial as curry


PRE_HOOKS_PREFIX = "pre_"
POST_HOOKS_PREFIX = "post_"

HOOK_MODULES = MP.load_plugin_modules()


def noop(*args, **kwargs):
    return False


def find_hook(f, prefix, module):
    """
    @param f: function to run commands (see also myrepo.commands)
    @param prefix: prefix of callbacks to run before/after f
    @param module: Plugin module to find hooks
    """
    return getattr(module, prefix + f.func_name, noop)