zeitgeist team mailing list archive
-
zeitgeist team
-
Mailing list archive
-
Message #01321
[Merge] lp:~zeitgeist/zeitgeist/user-extensions into lp:zeitgeist
Mikkel Kamstrup Erlandsen has proposed merging lp:~zeitgeist/zeitgeist/user-extensions into lp:zeitgeist.
Requested reviews:
Zeitgeist Framework Team (zeitgeist)
Implements loading extensions from ~/.local/zeitgeist/extensions. All classes extension Extension found in any .py file here will be picked up
--
https://code.launchpad.net/~zeitgeist/zeitgeist/user-extensions/+merge/31581
Your team Zeitgeist Framework Team is requested to review the proposed merge of lp:~zeitgeist/zeitgeist/user-extensions into lp:zeitgeist.
=== modified file '_zeitgeist/engine/__init__.py'
--- _zeitgeist/engine/__init__.py 2010-06-22 19:53:09 +0000
+++ _zeitgeist/engine/__init__.py 2010-08-02 20:17:40 +0000
@@ -57,5 +57,7 @@
# Required version of DB schema
CORE_SCHEMA="core"
CORE_SCHEMA_VERSION = 1
+
+ USER_EXTENSION_PATH = "~/.local/share/zeitgeist/extensions"
constants = _Constants()
=== modified file '_zeitgeist/engine/extension.py'
--- _zeitgeist/engine/extension.py 2010-08-02 16:10:07 +0000
+++ _zeitgeist/engine/extension.py 2010-08-02 20:17:40 +0000
@@ -26,6 +26,7 @@
log = logging.getLogger("zeitgeist.extension")
import zeitgeist
+from _zeitgeist.engine import constants
def safe_issubclass(obj, cls):
try:
@@ -167,11 +168,26 @@
config = zeitgeist._config
log.debug("Searching for extensions in: %s" % config.extensiondir)
extensions = []
- modules = filter(lambda m : m.endswith(".py"), os.listdir(config.extensiondir))
- modules = map(lambda m : m.rpartition(".")[0], modules)
- for mod in modules:
- _zg = __import__("_zeitgeist.engine.extensions." + mod)
- ext = getattr(_zg.engine.extensions, mod)
+
+ # Find system extensions
+ sys_modules = filter(lambda m : m.endswith(".py"), os.listdir(config.extensiondir))
+ sys_modules = modules = map(lambda m : "_zeitgeist.engine.extensions." + m.rpartition(".")[0], sys_modules)
+
+ # Find user extensions
+ user_modules = []
+ try:
+ user_modules = filter(lambda m : m.endswith(".py"), os.listdir(os.path.expanduser(constants.USER_EXTENSION_PATH)))
+ user_modules = map(lambda m : m.rpartition(".")[0], user_modules)
+ except OSError:
+ pass # USER_EXTENSION_PATH doesn't exist
+
+ for mod in sys_modules + user_modules:
+ path, dot, name = mod.rpartition(".")
+ if path:
+ ext = __import__(mod, globals(), locals(), [name])
+ else:
+ ext = __import__(name)
+
for cls in dir(ext):
cls = getattr(ext, cls)
if safe_issubclass(cls, Extension) and not cls is Extension:
=== modified file 'zeitgeist-daemon.py'
--- zeitgeist-daemon.py 2010-04-01 21:16:45 +0000
+++ zeitgeist-daemon.py 2010-08-02 20:17:40 +0000
@@ -28,9 +28,15 @@
import optparse
from copy import copy
+# Make sure we can find the private _zeitgeist namespace
from zeitgeist import _config
_config.setup_path()
+# Make sure we can load user extensions, and that they take priority over
+# system level extensions
+from _zeitgeist.engine import constants
+sys.path.insert(0, os.path.expanduser(constants.USER_EXTENSION_PATH))
+
gettext.install("zeitgeist", _config.localedir, unicode=1)
def check_loglevel(option, opt, value):