def package_plugins(source_dir, basename=None): plugin_files = [] if not os.path.isdir(source_dir): return False source_dir = os.path.abspath(source_dir) if not basename: for x in _PLUGIN_FILE_EXTENSIONS: l = glob.glob(os.path.join(source_dir, '*' + x)) for x in l: plugin_files.append(os.path.basename(x)) else: for x in _PLUGIN_FILE_EXTENSIONS: filename = basename + x if os.path.exists(os.path.join(source_dir, filename)): plugin_files.append(filename) break try: for x in plugin_files: mod = load_plugin_module(os.path.join(source_dir, x)) plugin = mod.Plugin() files = [x] if plugin.scripts: for f in plugin.scripts: if os.path.exists(os.path.join(source_dir, f)): files.append(f) else: raise IOError("file not found: %s" % f) if plugin.graphics: for f in plugin.graphics: if os.path.exists(os.path.join(source_dir, f)): files.append(f) else: raise IOError("file not found: %s" % f) if plugin.resources: for f in plugin.resources: if os.path.exists(os.path.join(source_dir, f)): files.append(f) else: raise IOError("file not found: %s" % f) unique_suffix = unique_str() archive_name = '%s.%s.wwpz' % (plugin.basename, unique_suffix) with zipfile.ZipFile(archive_name, mode='w') as z: for f in files: z.write(os.path.join(source_dir, f), os.path.basename(f)) return len(plugin_files) except IOError: return 0 except zipfile.BadZipfile: return 0
def store_association(cond_plugin, *task_plugins): if len(task_plugins) < 1: raise ValueError("expected at least one task plugin") l = [] if not isinstance(cond_plugin, BaseConditionPlugin): raise TypeError("expected a ConditionPlugin") else: l.append(cond_plugin.unique_id) for p in task_plugins: if not isinstance(p, TaskPlugin): raise TypeError("expected a TaskPlugin") else: l.append(p.unique_id) association_id = _PLUGIN_ASSOCIATION_ID_MAGIC + unique_str() datastore.put(association_id, json.dumps(l)) return association_id
def __init__(self, basename, name, description, author, copyright, icon=None, help_string=None, version=None): if self.__class__.__name__ == 'BasePlugin': raise TypeError("cannot instantiate abstract class") self.version = version self.basename = basename self.unique_id = _PLUGIN_UNIQUE_ID_MAGIC + '%s_%s' % ( self.basename, unique_str()) self.module_basename = basename self.name = name self.description = description self.author = author self.copyright = copyright if icon is None: icon = 'puzzle' if help_string is None: help_string = description self.summary_description = self.description self.icon = icon self.help_string = ' '.join(help_string.split('\n')) self.category = None self.plugin_type = None self.stock = False self.scripts = [] self.graphics = [] self.resources = [] self.enabled = True self.forward_allowed = True self._forward_button = None
def __init__(self, basename, name, description, author, copyright, icon=None, help_string=None, version=None): if self.__class__.__name__ == 'BasePlugin': raise TypeError("cannot instantiate abstract class") self.version = version self.basename = basename self.unique_id = _PLUGIN_UNIQUE_ID_MAGIC + '%s_%s' % (self.basename, unique_str()) self.module_basename = basename self.name = name self.description = description self.author = author self.copyright = copyright if icon is None: icon = 'puzzle' if help_string is None: help_string = description self.summary_description = self.description self.icon = icon self.help_string = ' '.join(help_string.split('\n')) self.category = None self.plugin_type = None self.stock = False self.scripts = [] self.graphics = [] self.resources = [] self.enabled = True self.forward_allowed = True self._forward_button = None