[Checkins] SVN: z3c.recipe.filetemplate/branches/gary-powertools/ add a test, fix a bug; fix docs on the basis of ReST tests

Gary Poster gary at modernsongs.com
Thu Apr 30 14:50:14 EDT 2009


Log message for revision 99622:
  add a test, fix a bug; fix docs on the basis of ReST tests

Changed:
  U   z3c.recipe.filetemplate/branches/gary-powertools/CHANGES.txt
  U   z3c.recipe.filetemplate/branches/gary-powertools/z3c/recipe/filetemplate/README.txt
  U   z3c.recipe.filetemplate/branches/gary-powertools/z3c/recipe/filetemplate/__init__.py
  U   z3c.recipe.filetemplate/branches/gary-powertools/z3c/recipe/filetemplate/tests.txt

-=-
Modified: z3c.recipe.filetemplate/branches/gary-powertools/CHANGES.txt
===================================================================
--- z3c.recipe.filetemplate/branches/gary-powertools/CHANGES.txt	2009-04-30 17:40:33 UTC (rev 99621)
+++ z3c.recipe.filetemplate/branches/gary-powertools/CHANGES.txt	2009-04-30 18:50:14 UTC (rev 99622)
@@ -1,3 +1,4 @@
+=======
 Changes
 =======
 
@@ -2,30 +3,32 @@
 2.0 (2009-04-30)
-----------------
+================
 
-- FEATURE: Store your template files in a separate directory structure, using
-  the ``source-directory`` option.
+--------
+Features
+--------
 
-- FEATURE: Specify multiple files automatically with globs.
+- Store your template files in a separate directory structure, using the
+  ``source-directory`` option.
 
-- FEATURE: Templates can reference other buildout sections using the usual
-  syntax, e.g. ${buildout:parts}
+- Specify multiple files automatically with globs.
 
-- FEATURE: Share options with other sections using the typical ``extends``
-  option.
+- Templates can reference other buildout sections using the usual syntax, e.g.
+  ${buildout:parts}
 
-- FEATURE: Create destination directories automatically.
+- Share options with other sections using the typical ``extends`` option.
 
-- FEATURE: Define option values for templates dynamically in Python with the
+- Create destination directories automatically.
+
+- Define option values for templates dynamically in Python with the
   ``interpreted-options`` option.
 
-- FEATURE: Get paths for eggs by specifying ``eggs`` and ``extra-paths``, just
-  like zc.recipe.egg script recipe.  These are available in template options
-  in colon-delimited, space-delimited, and quoted variants.  You can also build
+- Get paths for eggs by specifying ``eggs`` and ``extra-paths``, just like
+  zc.recipe.egg script recipe.  These are available in template options in
+  colon-delimited, space-delimited, and quoted variants.  You can also build
   your own using the ``interpreted-options`` feature.
 
-- BUGFIX: templates are not processed if there are no changes to them or the
-  buildout.
+- Templates are not processed if there are no changes to them or the buildout.
 
 1.0 (2007-09-30)
-----------------
+================
 

Modified: z3c.recipe.filetemplate/branches/gary-powertools/z3c/recipe/filetemplate/README.txt
===================================================================
--- z3c.recipe.filetemplate/branches/gary-powertools/z3c/recipe/filetemplate/README.txt	2009-04-30 17:40:33 UTC (rev 99621)
+++ z3c.recipe.filetemplate/branches/gary-powertools/z3c/recipe/filetemplate/README.txt	2009-04-30 18:50:14 UTC (rev 99622)
@@ -10,6 +10,11 @@
 recipe will read a number of template files, perform variable
 substitution and write the result to the corresponding output files.
 
+The recipe has several features, but it always takes template files with a
+``.in`` suffix, processes the template, and writes out the file to the desired
+location with the same file mode, and the same name but without the ``.in``
+suffix.
+
 For example, consider this simple template for a text file:
 
     >>> write(sample_buildout, 'helloworld.txt.in',
@@ -190,6 +195,10 @@
 Also note that, if you use a source directory and your ``files`` specify a
 directory, the directory must match precisely.
 
+==============
+Advanced Usage
+==============
+
 Substituting from Other Sections
 ================================
 

Modified: z3c.recipe.filetemplate/branches/gary-powertools/z3c/recipe/filetemplate/__init__.py
===================================================================
--- z3c.recipe.filetemplate/branches/gary-powertools/z3c/recipe/filetemplate/__init__.py	2009-04-30 17:40:33 UTC (rev 99621)
+++ z3c.recipe.filetemplate/branches/gary-powertools/z3c/recipe/filetemplate/__init__.py	2009-04-30 18:50:14 UTC (rev 99622)
@@ -112,7 +112,7 @@
                     pattern = parts[-1]
                     if (dir and
                         relative_prefix != dir and
-                        dir != '.' and relative_prefix != ''):
+                        (dir != '.' or relative_prefix != '')):
                         # if a directory is specified, it must match
                         # precisely.  We also support the '.' directory.
                         continue
@@ -203,8 +203,11 @@
             template=re.sub(r"\$\{([^:]+?)\}", r"${%s:\1}" % self.name,
                             template)
             self._create_paths(os.path.dirname(dest))
+            # we process the file first so that it won't be created if there
+            # is a problem.
+            processed = self.options._sub(template, [])
             result=open(dest, "wt")
-            result.write(self.options._sub(template, []))
+            result.write(processed)
             result.close()
             os.chmod(dest, mode)
             self.options.created(rel_path[:-3])

Modified: z3c.recipe.filetemplate/branches/gary-powertools/z3c/recipe/filetemplate/tests.txt
===================================================================
--- z3c.recipe.filetemplate/branches/gary-powertools/z3c/recipe/filetemplate/tests.txt	2009-04-30 17:40:33 UTC (rev 99621)
+++ z3c.recipe.filetemplate/branches/gary-powertools/z3c/recipe/filetemplate/tests.txt	2009-04-30 18:50:14 UTC (rev 99622)
@@ -309,3 +309,59 @@
     >>> ls(sample_buildout, 'etc', 'in')
     -  helloworld.cfg
 
+This works with the ./ directory also, so you can specify a file in the root
+of the source directory.
+
+At the start, we have the ``etc`` directory but not ``helloworld.cfg``.
+
+    >>> ls(sample_buildout)
+    -  .installed.cfg
+    -  alreadyhere.txt
+    -  alreadyhere.txt.in
+    d  bin
+    -  buildout.cfg
+    d  develop-eggs
+    d  eggs
+    d  etc
+    -  goodbyeworld.txt.in
+    -  helloworld.txt.in
+    -  missing.txt.in
+    d  parts
+    d  template
+
+    >>> write(sample_buildout, 'template', 'helloworld.cfg.in',
+    ... """
+    ... Hello ${world} from the top-level .cfg file!
+    ... """)
+    >>> write(sample_buildout, 'buildout.cfg',
+    ... """
+    ... [buildout]
+    ... parts = message
+    ...
+    ... [message]
+    ... recipe = z3c.recipe.filetemplate
+    ... source-directory = template
+    ... files = ./helloworld.cfg
+    ... world = Philipp
+    ... """)
+    >>> print system(buildout)
+    Uninstalling message.
+    Installing message.
+
+Now the reverse is true.
+
+    >>> ls(sample_buildout)
+    -  .installed.cfg
+    -  alreadyhere.txt
+    -  alreadyhere.txt.in
+    d  bin
+    -  buildout.cfg
+    d  develop-eggs
+    d  eggs
+    -  goodbyeworld.txt.in
+    -  helloworld.cfg
+    -  helloworld.txt.in
+    -  missing.txt.in
+    d  parts
+    d  template
+



More information about the Checkins mailing list