"""Plugins for backup.py Plugins should expose 3 functions: init(cfg, *args) pre() post() init() will set up any variables that it needs. pre() runs before the backup run() runs the actual backup post() runs after the backup """ # this is kinda hacky; anything better? import sys, os, glob sys.path.insert(0, os.path.dirname(__file__)) import traceback import subprocess, time class PluginNotFoundError(Exception): pass def run(cfg, plugin, *args, **kwargs): """This runs a plugin. @param plugin: a string value for a file that is importable. @type plugin: string""" try: module = __import__(plugin) except: #traceback.print_exc() raise PluginNotFoundError("Plugin %s not found." % plugin) try: module.init(cfg, *args, **kwargs) module.pre() module.run() module.post() del(module) except: traceback.print_exc() print plugin """Common utilities for plugins.""" class PluginError(Exception): pass def normalize_path(path, cwd=True): path = os.path.expandvars(path) path = os.path.expanduser(path) path = path.replace("/", os.path.sep) if cwd: path = unicode(os.path.abspath(path)) else: path = unicode(path) path = glob.glob(path) return path def print_exec(command): "Execute `command` as a subprocess and print its output." cmd = subprocess.Popen(command, shell=True) cmd.wait() return cmd.returncode def prune(path): "Remove empty directories, depth first." pass