#!/usr/bin/python """ wrapper around a userdefined script which can be called in pydar """ # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Copyright 2004 Dries Verachtert import sys from log4py import Logger class CallableScript: def __init__(self, modulePath, functionName): self.__cat = Logger().get_instance(self) self.__modulePath = modulePath self.__functionName = functionName self.reloadMethod() def reloadMethod(self): self.__myMethod = None # immediately try to create the callable object sys.path.append(".") # @todo: add some nice exception catching so we can show decent errormessages myModule = __import__(self.__modulePath) myMethod = getattr(myModule,self.__functionName) if not callable(myMethod): raise Exception("method " + self.__functionName + " in module " + self.__modulePath + " is not callable!") self.__myMethod = myMethod def _getMethod(self): return self.__myMethod