Plugin library code cleanup

BasePlugin: Added some base methods and future use variables:
This commit is contained in:
Felipe Martin 2013-11-20 23:38:54 +01:00
parent 57e0a20da7
commit 4a575e5ed8
2 changed files with 32 additions and 13 deletions

View File

@ -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

View File

@ -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)