Author: jvloothuis
Date: Fri Oct 12 11:57:04 2007
New Revision: 47408

Modified:
   kukit/kss.base/trunk/kss/base/__init__.py
   kukit/kss.base/trunk/kss/base/plugin.py
   kukit/kss.base/trunk/kss/base/plugin.txt
Log:

Added more tests for the plugin module (in specific the utility
functions). In the process also removed some unneeded code.


Modified: kukit/kss.base/trunk/kss/base/__init__.py
==============================================================================
--- kukit/kss.base/trunk/kss/base/__init__.py   (original)
+++ kukit/kss.base/trunk/kss/base/__init__.py   Fri Oct 12 11:57:04 2007
@@ -1,10 +1,2 @@
-# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
-try:
-    __import__('pkg_resources').declare_namespace(__name__)
-except ImportError:
-    from pkgutil import extend_path
-    __path__ = extend_path(__path__, __name__)
-
-
 from kss.base.commands import KSSCommands
 from kss.base.plugin import load_plugins

Modified: kukit/kss.base/trunk/kss/base/plugin.py
==============================================================================
--- kukit/kss.base/trunk/kss/base/plugin.py     (original)
+++ kukit/kss.base/trunk/kss/base/plugin.py     Fri Oct 12 11:57:04 2007
@@ -23,18 +23,14 @@
 
 def javascripts_from(path):
     javascripts = []
-    if os.path.isdir(path):
-        for dirpath, dirnames, filenames in os.walk(path):
-            for filename in filenames:
-                if filename.endswith('.js'):
-                    javascripts.append(os.path.join(dirpath, filename))
-    else:
-       if path.endswith('.js'):
-           javascripts.append(os.path.abspath(path))
-       else:
-           return javascripts_from(os.path.dirname(os.path.abspath(path)))
-    return javascripts
+    if not os.path.isdir(path):
+        raise ValueError('Path is not a directory: %s' % path)
 
+    for dirpath, dirnames, filenames in os.walk(path):
+        for filename in filenames:
+            if filename.endswith('.js'):
+                yield os.path.join(dirpath, filename)
+    
 def module_path(mod):
     return os.path.join(os.path.dirname(os.path.abspath(mod.__file__)))
 

Modified: kukit/kss.base/trunk/kss/base/plugin.txt
==============================================================================
--- kukit/kss.base/trunk/kss/base/plugin.txt    (original)
+++ kukit/kss.base/trunk/kss/base/plugin.txt    Fri Oct 12 11:57:04 2007
@@ -77,3 +77,33 @@
   >>> tuple(activated_plugins())
   (('kss-testing', <ExamplePlugin object at ...>),)
 
+
+-----------------
+Utility functions
+-----------------
+
+When you write a plugin you will need to do a few things. For some of
+these things there are helper functions available.
+
+Getting full path names for Javascripts
+---------------------------------------
+
+One of the helpers which is usefull mostly for extra Javascripts is
+`javascripts_from`. This function whill recursively generate an
+iterator of all javascripts from a certain path.
+
+  >>> from kss.base.plugin import javascripts_from, module_path
+  >>> list(javascripts_from(module_path(kss.base)))
+  [.../kukit/kukit/serveraction.js', ...'.../kukit/kukit/dom.js'...]
+
+When we try to load from something which is not a directory we will
+get an error.
+
+  >>> import os
+  >>> list(javascripts_from(os.path.join(module_path(kss.base),
+  ...                                    '__init__.py')))
+  Traceback (most recent call last):
+  ...
+  ValueError: Path is not a directory: .../kss/base/__init__.py
+
+
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to