[Checkins] SVN: z3c.recipe.filetemplate/branches/dobe-force-overwrite/ added force-overwrite option
Bernd Dorn
bernd.dorn at lovelysystems.com
Wed Nov 18 11:03:35 EST 2009
Log message for revision 105831:
added force-overwrite option
Changed:
U z3c.recipe.filetemplate/branches/dobe-force-overwrite/CHANGES.txt
U z3c.recipe.filetemplate/branches/dobe-force-overwrite/z3c/recipe/filetemplate/__init__.py
U z3c.recipe.filetemplate/branches/dobe-force-overwrite/z3c/recipe/filetemplate/tests.txt
-=-
Modified: z3c.recipe.filetemplate/branches/dobe-force-overwrite/CHANGES.txt
===================================================================
--- z3c.recipe.filetemplate/branches/dobe-force-overwrite/CHANGES.txt 2009-11-18 15:49:11 UTC (rev 105830)
+++ z3c.recipe.filetemplate/branches/dobe-force-overwrite/CHANGES.txt 2009-11-18 16:03:34 UTC (rev 105831)
@@ -9,7 +9,8 @@
Features
--------
-- None yet.
+- Added the ``force-overwrite`` option to allow overwriting existing
+ files.
2.0.3 (2009-07-02)
Modified: z3c.recipe.filetemplate/branches/dobe-force-overwrite/z3c/recipe/filetemplate/__init__.py
===================================================================
--- z3c.recipe.filetemplate/branches/dobe-force-overwrite/z3c/recipe/filetemplate/__init__.py 2009-11-18 15:49:11 UTC (rev 105830)
+++ z3c.recipe.filetemplate/branches/dobe-force-overwrite/z3c/recipe/filetemplate/__init__.py 2009-11-18 16:03:34 UTC (rev 105831)
@@ -27,6 +27,8 @@
ABS_PATH_ERROR = ('%s is an absolute path. Paths must be '
'relative to the buildout directory.')
+TRUE_VALUES = ('yes', 'true', '1', 'on')
+
class FileTemplate(object):
def __init__(self, buildout, name, options):
@@ -190,7 +192,12 @@
if os.path.exists(
os.path.join(self.destination_dir, rel_path[:-3]))
]
- if already_exists:
+ force_overwrite = self.options.get(
+ 'force-overwrite', '').lower() in TRUE_VALUES
+ if already_exists and force_overwrite:
+ self.logger.info('Overwriting existing files: %s.',
+ ', '.join(already_exists))
+ elif already_exists:
self._user_error(
'Destinations already exist: %s. Please make sure that '
'you really want to generate these automatically. Then '
@@ -220,4 +227,7 @@
self.options.created(path)
def update(self):
- pass
+ if self.options.get('force-overwrite', '').lower() in TRUE_VALUES:
+ return self.install()
+ else:
+ pass
Modified: z3c.recipe.filetemplate/branches/dobe-force-overwrite/z3c/recipe/filetemplate/tests.txt
===================================================================
--- z3c.recipe.filetemplate/branches/dobe-force-overwrite/z3c/recipe/filetemplate/tests.txt 2009-11-18 15:49:11 UTC (rev 105830)
+++ z3c.recipe.filetemplate/branches/dobe-force-overwrite/z3c/recipe/filetemplate/tests.txt 2009-11-18 16:03:34 UTC (rev 105831)
@@ -14,7 +14,7 @@
... """
... Hello ${world}!
... """)
-
+
>>> write(sample_buildout, 'goodbyeworld.txt.in',
... """
... Goodbye ${world}!
@@ -56,7 +56,7 @@
... files = /etc/passwd.in
... root = me
... """)
-
+
>>> print system(buildout)
evil: /etc/passwd.in is an absolute path. Paths must be relative to the buildout directory.
While:
@@ -80,7 +80,7 @@
... recipe = z3c.recipe.filetemplate
... files = doesntexist
... """)
-
+
>>> print system(buildout)
notthere: No template found for these file names: doesntexist.in
While:
@@ -99,12 +99,12 @@
... """
... I'm already here
... """)
-
+
>>> write(sample_buildout, 'alreadyhere.txt.in',
... """
... I'm the template that's supposed to replace the file above.
... """)
-
+
>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
@@ -127,6 +127,34 @@
that you really want to generate these automatically. Then move
them away.
+If the option 'force-overwrite' is set, existing files will be
+overwritten.
+
+ >>> write(sample_buildout, 'alreadyhere.txt',
+ ... """
+ ... I'm already here
+ ... """)
+
+ >>> write(sample_buildout, 'alreadyhere.txt.in',
+ ... """
+ ... I'm the template that's supposed to replace the file above.
+ ... """)
+
+ >>> write(sample_buildout, 'buildout.cfg',
+ ... """
+ ... [buildout]
+ ... parts = alreadythere
+ ...
+ ... [alreadythere]
+ ... recipe = z3c.recipe.filetemplate
+ ... files = alreadyhere.txt
+ ... force-overwrite = true
+ ... """)
+
+ >>> print system(buildout)
+ Installing alreadythere.
+ alreadythere: Overwriting existing files: alreadyhere.txt.
+
Missing variables
-----------------
@@ -137,7 +165,7 @@
... """
... Hello ${world}!
... """)
-
+
>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
@@ -147,8 +175,9 @@
... recipe = z3c.recipe.filetemplate
... files = missing.txt
... """)
-
+
>>> print system(buildout)
+ Uninstalling alreadythere.
Installing missing.
While:
Installing missing.
@@ -158,7 +187,7 @@
-------------------------------
If there are no changes in the buildout section, or in the files it will build,
-the recipe will update, which is a no-op.
+the recipe will update, which is a no-op by default.
>>> write(sample_buildout, 'buildout.cfg',
... """
@@ -176,6 +205,28 @@
>>> print system(buildout)
Updating message.
+The ``force-overwrite`` allows to re-create the destination files upon
+update.
+
+ >>> write(sample_buildout, 'buildout.cfg',
+ ... """
+ ... [buildout]
+ ... parts = message
+ ...
+ ... [message]
+ ... recipe = z3c.recipe.filetemplate
+ ... files = helloworld.txt
+ ... world = Bert
+ ... force-overwrite = true
+ ... """)
+
+ >>> print system(buildout)
+ Uninstalling message.
+ Installing message.
+ >>> print system(buildout)
+ Updating message.
+ message: Overwriting existing files: helloworld.txt.
+
Changes in a source directory cause a re-install
------------------------------------------------
@@ -316,7 +367,6 @@
>>> ls(sample_buildout)
- .installed.cfg
- - alreadyhere.txt
- alreadyhere.txt.in
d bin
- buildout.cfg
@@ -352,7 +402,6 @@
>>> ls(sample_buildout)
- .installed.cfg
- - alreadyhere.txt
- alreadyhere.txt.in
d bin
- buildout.cfg
More information about the checkins
mailing list