Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/addon.py
diff options
context:
space:
mode:
authorSimon Poirier <simpoir@gmail.com>2009-07-11 21:39:46 (GMT)
committer Simon Poirier <simpoir@gmail.com>2009-07-11 22:00:30 (GMT)
commit0c3f127c86af818d260966d2292b199757087157 (patch)
tree62cf941aef5bde83641a17ec492e03d0ecb17386 /tutorius/addon.py
parent9fafb49af210e956d43d6a00106558d1a00d13df (diff)
repackage
Diffstat (limited to 'tutorius/addon.py')
-rw-r--r--tutorius/addon.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/tutorius/addon.py b/tutorius/addon.py
new file mode 100644
index 0000000..51791d1
--- /dev/null
+++ b/tutorius/addon.py
@@ -0,0 +1,76 @@
+# Copyright (C) 2009, Tutorius.org
+# Copyright (C) 2009, Simon Poirier <simpoir@gmail.com>
+#
+#
+# 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 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+"""
+This module manages the loading and listing of tutorius addons.
+Addons are modular actions and events that are package in such a way that they
+can be autodetected and can integrate with Tutorius components (the editor)
+without any configuration or explicit dependencies (python import).
+
+An action addon is expected to have a metadata dict such as this one:
+__action__ = {
+ "name" : "HelloWorld",
+ "display_name" : "Hello World!",
+ "icon" : "hello",
+ "class" : HelloAction,
+ "mandatory_props" : ["text"],
+}
+"""
+
+import os
+import re
+import logging
+
+PREFIX = __name__+"s"
+PATH = re.sub("addon\\.py[c]$", "", __file__)+"addons"
+
+_cache = None
+
+def _reload_addons():
+ global _cache
+ _cache = {}
+ for addon in filter(lambda x: x.endswith("py"), os.listdir(PATH)):
+ mod = __import__(PREFIX+'.'+re.sub("\\.py$", "", addon), {}, {}, [""])
+ if hasattr(mod, "__action__"):
+ _cache[mod.__action__['name']] = mod.__action__
+ continue
+ if hasattr(mod, "__event__"):
+ _cache[mod.__event__['name']] = mod.__event__
+
+def create(name, *args, **kwargs):
+ global _cache
+ if not _cache:
+ _reload_addons()
+ try:
+ return _cache[name]['class'](*args, **kwargs)
+ except KeyError:
+ logging.error("Addon not found for class '%s'", name)
+ return None
+
+def list_addons():
+ global _cache
+ if not _cache:
+ _reload_addons()
+ return _cache.keys()
+
+def get_addon_meta(name):
+ global _cache
+ if not _cache:
+ _reload_addons()
+ return _cache[name]
+
+# vim:set ts=4 sts=4 sw=4 et: