diff --git a/iosfu/plugin/base.py b/iosfu/plugin/base.py index 79fddd3..b07862a 100644 --- a/iosfu/plugin/base.py +++ b/iosfu/plugin/base.py @@ -5,11 +5,18 @@ class BasePlugin(object): """ Base plugin object """ + domain = None # App Domain com.*.* category = 'Base' # Category of the plugin name = 'Base Plugin' # Name of the plugin description = '' # Description - _backup = None # BackupManager instance + _backup = None # Backup instance + + # Backup requeriments for the plugin to work + requires = { + # List of files needed + 'files': [], + } @property def __slug__(self): @@ -20,3 +27,27 @@ class BasePlugin(object): slugify(self.category), slugify(self.name) ) + + def __init__(self, backup=None): + self._backup = backup + + def __unicode__(self): + return u"{0}".format(self.domain) + + def do(self, *args, **kwargs): + """ + Main function called by plugin library. + """ + if self._backup: + return self.__do__(*args, **kwargs) + else: + raise Exception( + 'Plugin {0} need a backup instance to work with'\ + .format(self.__slug__) + ) + + def __do__(self, *args, **kwargs): + """ + Main plugin function. + """ + pass diff --git a/iosfu/plugin/library.py b/iosfu/plugin/library.py index 91782cb..2b547c9 100644 --- a/iosfu/plugin/library.py +++ b/iosfu/plugin/library.py @@ -33,16 +33,4 @@ class Library(object): def discover(self): for path, dirs, files in walk(PATH): if files == ['__init__.py', 'plugin.py']: - # print(path) - # print(dirs) - # print(files) - # print('plugin!') self.load(path) - # for dirname in listdir(PATH): - # plugin_path = join_paths(PATH, dirname) - # plugin_module = join_paths(PATH, dirname, 'plugin.py') - # plugin_init = join_paths(PATH, dirname, '__init__.py') - # if isdir(plugin_path) and isfile(plugin_module) \ - # and isfile(plugin_init): - # self.load(plugin_path, dirname) -