[Checkins] SVN: z3c.pt/trunk/ Switch from hardcoding all options in config.py to using parameters

Wichert Akkerman wichert at wiggy.net
Fri Aug 8 06:15:25 EDT 2008


Log message for revision 89539:
  Switch from hardcoding all options in config.py to using parameters
  for the template. This also allows us to use the more logical
  auto_reload flag instead of reusing PROD_MODE, which is also used
  for other purposes.
  

Changed:
  U   z3c.pt/trunk/CHANGES.txt
  U   z3c.pt/trunk/src/z3c/pt/config.py
  U   z3c.pt/trunk/src/z3c/pt/filecache.py
  U   z3c.pt/trunk/src/z3c/pt/template.py

-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt	2008-08-08 10:09:05 UTC (rev 89538)
+++ z3c.pt/trunk/CHANGES.txt	2008-08-08 10:15:24 UTC (rev 89539)
@@ -4,6 +4,12 @@
 Version 0.9.x
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+- Switch from hardcoding all options in config.py to using parameters
+  for the template. This also allows us to use the more logical
+  auto_reload flag instead of reusing PROD_MODE, which is also used
+  for other purposes.
+  [wichert]
+
 - Treat comments, processing instructions, and named entities in the
   source template as "literals", which will be rendered into the
   output unchanged. [chrism]

Modified: z3c.pt/trunk/src/z3c/pt/config.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/config.py	2008-08-08 10:09:05 UTC (rev 89538)
+++ z3c.pt/trunk/src/z3c/pt/config.py	2008-08-08 10:15:24 UTC (rev 89539)
@@ -7,11 +7,6 @@
 
 PROD_MODE = not DEBUG_MODE
 
-FILECACHE_KEY = 'Z3C_PT_FILECACHE'
-FILECACHE = os.environ.get(FILECACHE_KEY, None)
-if FILECACHE is not None:
-    FILECACHE = abspath(FILECACHE)
-
 DISABLE_I18N_KEY = 'Z3C_PT_DISABLE_I18N'
 DISABLE_I18N = os.environ.get(DISABLE_I18N_KEY, 'false')
 DISABLE_I18N = DISABLE_I18N.lower() in ('yes', 'true', 'on')

Modified: z3c.pt/trunk/src/z3c/pt/filecache.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/filecache.py	2008-08-08 10:09:05 UTC (rev 89538)
+++ z3c.pt/trunk/src/z3c/pt/filecache.py	2008-08-08 10:15:24 UTC (rev 89539)
@@ -7,8 +7,6 @@
 from sha import sha
 from UserDict import UserDict
 
-from z3c.pt.config import FILECACHE
-
 MAGIC = get_magic()
 
 def code_read(filename, timestamp):
@@ -41,10 +39,10 @@
 
 class CachingDict(UserDict):
 
-    def __init__(self, filename, mtime):
+    def __init__(self, cachedir, filename, mtime):
         UserDict.__init__(self)
         signature = sha(filename).hexdigest()
-        self.cachedir = os.path.join(FILECACHE, signature)
+        self.cachedir = os.path.join(cachedir, signature)
         self.mtime = mtime
 
     def load(self, pagetemplate):

Modified: z3c.pt/trunk/src/z3c/pt/template.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/template.py	2008-08-08 10:09:05 UTC (rev 89538)
+++ z3c.pt/trunk/src/z3c/pt/template.py	2008-08-08 10:15:24 UTC (rev 89539)
@@ -3,7 +3,7 @@
 import codegen
 import traceback
 
-from z3c.pt.config import DEBUG_MODE, PROD_MODE, FILECACHE
+from z3c.pt.config import DEBUG_MODE, PROD_MODE
 from z3c.pt import filecache
 import z3c.pt.generation
 
@@ -101,8 +101,10 @@
 
 class BaseTemplateFile(BaseTemplate):
 
-    def __init__(self, filename):
+    def __init__(self, filename, auto_reload=False, cachedir=None):
         BaseTemplate.__init__(self, None)
+        self.auto_reload = auto_reload
+        self.cachedir = cachedir
 
         if not os.path.isabs(filename):
             for depth in (1, 2):
@@ -124,8 +126,9 @@
         # make sure file exists
         os.lstat(filename)
         self.filename = filename
-        if FILECACHE:
-            self.registry = filecache.CachingDict(filename, self.mtime())
+        if self.cachedir:
+            self.registry = filecache.CachingDict(cachedir, filename,
+                                                  self.mtime())
             self.registry.load(self)
         else:
             self.registry = {}
@@ -172,7 +175,7 @@
         self.annotations = generator.stream.annotations
         
         _globals.update(suite._globals)
-        if FILECACHE:
+        if self.cachedir:
             self.registry.store(params, suite.code)
 
         return self.execute(suite.code, _globals)
@@ -202,7 +205,7 @@
         return self.safe_render(template, **kwargs)
 
     def _cook_check(self):
-        if self._v_last_read and PROD_MODE:
+        if self._v_last_read and not self.auto_reload:
             return False
 
         if self.mtime() == self._v_last_read:



More information about the Checkins mailing list