[kupfer] Introduce capability blocker environmental variables
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] Introduce capability blocker environmental variables
- Date: Thu, 11 Feb 2010 16:59:15 +0000 (UTC)
commit 1378e4ec848192b40a5f010e1b2dbb1294490275
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Fri Feb 5 16:29:26 2010 +0100
Introduce capability blocker environmental variables
Implement KUPFER_NO_CACHE and KUPFER_NO_CUSTOM_PLUGINS
Documentation/Quickstart.rst | 10 ++++++++++
kupfer/config.py | 3 +++
kupfer/core/sources.py | 8 ++++++++
kupfer/plugin/__init__.py | 3 +++
4 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/Documentation/Quickstart.rst b/Documentation/Quickstart.rst
index e0c3768..77ae6f5 100644
--- a/Documentation/Quickstart.rst
+++ b/Documentation/Quickstart.rst
@@ -74,6 +74,16 @@ Custom plugins are added to kupfer by installing them to the directory
*~/.local/share/kupfer/plugins*, or any kupfer/plugins directory in any
of ``$XDG_DATA_DIRS``.
+ENVIRONMENT VARIABLES
+=====================
+
+If *KUPFER_NO_CUSTOM_PLUGINS* is set, only allow loading built-in
+plugins (installed in the program's python package).
+
+If *KUPFER_NO_CACHE* is set, do not load from or write to any source
+cache files.
+
+
.. vim: ft=rst tw=72
.. this document best viewed with::
rst2pdf Quickstart.rst && xdg-open Quickstart.pdf
diff --git a/kupfer/config.py b/kupfer/config.py
index aa48bc5..c4ffa68 100644
--- a/kupfer/config.py
+++ b/kupfer/config.py
@@ -10,6 +10,9 @@ PACKAGE_NAME="kupfer"
class ResourceLookupError (StandardError):
pass
+def has_capability(cap):
+ return not bool(os.getenv("KUPFER_NO_%s" % cap, False))
+
def get_cache_home():
"""
Directory where cache files should be put
diff --git a/kupfer/core/sources.py b/kupfer/core/sources.py
index 8e2288c..ff7563e 100644
--- a/kupfer/core/sources.py
+++ b/kupfer/core/sources.py
@@ -83,6 +83,9 @@ class SourcePickler (pretty.OutputMixin):
def __init__(self):
self.open = lambda f,mode: gzip.open(f, mode, compresslevel=3)
+ def should_use_cache(self):
+ return config.has_capability("CACHE")
+
def rm_old_cachefiles(self):
"""Checks if there are old cachefiles from last version,
and deletes those
@@ -117,6 +120,9 @@ class SourcePickler (pretty.OutputMixin):
return os.path.join(config.get_cache_home(), filename)
def unpickle_source(self, source):
+ if not self.should_use_cache():
+ return None
+
cached = self._unpickle_source(self.get_filename(source))
if not cached:
return None
@@ -143,6 +149,8 @@ class SourcePickler (pretty.OutputMixin):
return source
def pickle_source(self, source):
+ if not self.should_use_cache():
+ return None
return self._pickle_source(self.get_filename(source), source)
def _pickle_source(self, pickle_file, source):
"""
diff --git a/kupfer/plugin/__init__.py b/kupfer/plugin/__init__.py
index efa5fdd..b5cb1a5 100644
--- a/kupfer/plugin/__init__.py
+++ b/kupfer/plugin/__init__.py
@@ -5,6 +5,9 @@ def _extend_path():
from kupfer import config
from kupfer import pretty
+ if not config.has_capability("CUSTOM_PLUGINS"):
+ return
+
# Add plugins in data directories
__path__.extend(config.get_data_dirs("plugins"))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]