[Checkins] SVN: z3c.recipe.mkdir/trunk/ Merge changes from ulif-dont-del-olddirs branch.
Uli Fouquet
uli at gnufix.de
Thu Aug 20 05:34:55 EDT 2009
Log message for revision 102992:
Merge changes from ulif-dont-del-olddirs branch.
Changed:
U z3c.recipe.mkdir/trunk/CHANGES.txt
U z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/README.txt
U z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/__init__.py
-=-
Modified: z3c.recipe.mkdir/trunk/CHANGES.txt
===================================================================
--- z3c.recipe.mkdir/trunk/CHANGES.txt 2009-08-20 09:27:38 UTC (rev 102991)
+++ z3c.recipe.mkdir/trunk/CHANGES.txt 2009-08-20 09:34:55 UTC (rev 102992)
@@ -9,7 +9,14 @@
* Created directories are now displayed during buildout runs.
+* Changed default behaviour: directories created once will not be
+ removed on updates, except you require that explicitly.
+* Added new option ``remove-on-update``: if set to ``yes``, ``true``
+ or ``on`` the set directories will be removed on updates of
+ `buildout` configuration.
+
+
0.2 (2009-08-19)
================
Modified: z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/README.txt
===================================================================
--- z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/README.txt 2009-08-20 09:27:38 UTC (rev 102991)
+++ z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/README.txt 2009-08-20 09:34:55 UTC (rev 102992)
@@ -19,7 +19,17 @@
/path/to/buildout-dir/foo/bar
+* ``remove-on-update``
+ Default: ``no``
+ By default, created directories are not removed
+ on updates of buildout configuration. This is a security measure
+ as created directories might contain valuable data.
+
+ You can, however, enforce automatic removing on updates by
+ setting this option to ``on``, ``yes`` or ``true``.
+
+
Simple creation of directories via buildout
===========================================
@@ -79,9 +89,78 @@
The directory was indeed created:
>>> ls('parts')
+ d mydir
d myotherdir
+Creating directories that are removed on updates
+================================================
+
+We can tell, that a directory should be removed on updates by using
+the ``remove-on-update`` option:
+
+ >>> write('buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... parts = mydir
+ ... offline = true
+ ...
+ ... [mydir]
+ ... recipe = z3c.recipe.mkdir
+ ... remove-on-update = true
+ ... paths = newdir
+ ... ''')
+
+ >>> print system(join('bin', 'buildout')),
+ Uninstalling mydir.
+ Installing mydir.
+ mydir: created path: /sample-buildout/newdir
+
+The ``newdir/`` directory was created:
+
+ >>> ls('.')
+ - .installed.cfg
+ d bin
+ - buildout.cfg
+ d develop-eggs
+ d eggs
+ d newdir
+ d parts
+
+We rewrite `buildout.cfg` and set a different path:
+
+ >>> write('buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... parts = mydir
+ ... offline = true
+ ...
+ ... [mydir]
+ ... recipe = z3c.recipe.mkdir
+ ... remove-on-update = true
+ ... paths = newdir2
+ ... ''')
+
+ >>> print system(join('bin', 'buildout')),
+ Uninstalling mydir.
+ Installing mydir.
+ mydir: created path: /sample-buildout/newdir2
+
+Now ``newdir/`` has vanished and ``newdir2`` exists:
+
+ >>> ls('.')
+ - .installed.cfg
+ d bin
+ - buildout.cfg
+ d develop-eggs
+ d eggs
+ d newdir2
+ d parts
+
+Note, that the created directory will be removed on next modification
+of `buildout.cfg`.
+
+
Creating relative paths
=======================
@@ -114,10 +193,11 @@
d myrootdir
d parts
- The old directory will vanish:
+ The old directories will **not** vanish:
- >>> ls('parts') is None
- True
+ >>> ls('parts')
+ d mydir
+ d myotherdir
Creating intermediate paths
@@ -200,6 +280,7 @@
>>> ls('myroot')
+ d bar
d dir1
d dir2
@@ -245,6 +326,9 @@
mydir: created path: /sample-buildout/myroot/dir4
>>> ls('myroot')
+ d bar
+ d dir1
+ d dir2
d dir3
d dir4
@@ -252,7 +336,8 @@
=====================
If you change the setting of some path, the old directory and all its
-contents will be lost:
+contents will **not** be deleted (as you might expect from a buildout
+recipe):
>>> write('buildout.cfg',
... '''
@@ -293,9 +378,10 @@
mydir: created path: /sample-buildout/path2
<BLANKLINE>
+The file we created above is still alive:
+
>>> ls('path1')
- Traceback (most recent call last):
- OSError: [Errno ...] No such file or directory: 'path1'
+ - myfile
Things, one should not do
@@ -315,17 +401,17 @@
...
... [mydir]
... recipe = z3c.recipe.mkdir
- ... paths = myrootdir/somefile/foo
+ ... paths = rootdir2/somefile/foo
... ''')
Now we create the first part of the path beforehand:
>>> import os
- >>> os.mkdir('myrootdir')
+ >>> os.mkdir('rootdir2')
And make the second part of the path a file:
- >>> write(join('myrootdir', 'somefile'),
+ >>> write(join('rootdir2', 'somefile'),
... '''
... blah
... ''')
@@ -335,7 +421,7 @@
Installing mydir.
While:
Installing mydir.
- Error: Cannot create directory: /.../myrootdir/somefile. It's a file.
+ Error: Cannot create directory: /.../rootdir2/somefile. It's a file.
Don't use ``path`` option
@@ -355,6 +441,7 @@
... [mydir]
... recipe = z3c.recipe.mkdir
... path = myrootdir
+ ... remove-on-update = yes
... ''')
>>> print system(join('bin', 'buildout')),
@@ -363,3 +450,5 @@
mydir: created path: /sample-buildout/parts/mydir
The ``path`` option will be supported only for a limited time!
+
+
Modified: z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/__init__.py
===================================================================
--- z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/__init__.py 2009-08-20 09:27:38 UTC (rev 102991)
+++ z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/__init__.py 2009-08-20 09:34:55 UTC (rev 102992)
@@ -8,6 +8,8 @@
self.name=name
self.options=options
self.logger=logging.getLogger(self.name)
+ self.remove_on_update = string_to_bool(
+ options.get('remove-on-update', 'no'))
paths = None
@@ -29,7 +31,6 @@
def install(self):
for path in self.paths:
self.createIntermediatePaths(path)
- self.options.created(path)
self.logger.info('created path: %s' % path)
return self.options.created()
@@ -46,4 +47,11 @@
return
self.createIntermediatePaths(parent)
os.mkdir(path)
- self.options.created(path)
+ if self.remove_on_update:
+ self.options.created(path)
+
+def string_to_bool(value):
+ if value is True or value is False:
+ return value
+ value = value.lower()
+ return value in ['yes', 'on', 'true', '1']
More information about the Checkins
mailing list