[Checkins] SVN: lovely.recipe/trunk/ - added option "createpath" to
mkfile and mkdir recipe
Juergen Kartnaller
juergen at kartnaller.at
Thu Apr 24 04:09:42 EDT 2008
Log message for revision 85690:
- added option "createpath" to mkfile and mkdir recipe
Changed:
U lovely.recipe/trunk/CHANGES.txt
U lovely.recipe/trunk/setup.py
U lovely.recipe/trunk/src/lovely/recipe/fs/README.txt
U lovely.recipe/trunk/src/lovely/recipe/fs/mkdir.py
U lovely.recipe/trunk/src/lovely/recipe/fs/mkfile.py
U lovely.recipe/trunk/src/lovely/recipe/fs/tests.py
-=-
Modified: lovely.recipe/trunk/CHANGES.txt
===================================================================
--- lovely.recipe/trunk/CHANGES.txt 2008-04-24 06:57:28 UTC (rev 85689)
+++ lovely.recipe/trunk/CHANGES.txt 2008-04-24 08:09:41 UTC (rev 85690)
@@ -8,6 +8,11 @@
BIG TODO: add tests for lovely.recipe.zeo and lovely.recipe.zope to test and
to show for what this all is for.
+2008/04/24 0.3.1b3:
+===================
+
+- added option "createpath" to mkfile and mkdir recipe
+
2008/02/24 0.3.1b2:
===================
Modified: lovely.recipe/trunk/setup.py
===================================================================
--- lovely.recipe/trunk/setup.py 2008-04-24 06:57:28 UTC (rev 85689)
+++ lovely.recipe/trunk/setup.py 2008-04-24 08:09:41 UTC (rev 85690)
@@ -13,7 +13,7 @@
setup (
name='lovely.recipe',
- version='0.3.1b2',
+ version='0.3.1b3',
author = "Lovely Systems",
author_email = "office at lovelysystems.com",
license = "ZPL 2.1",
Modified: lovely.recipe/trunk/src/lovely/recipe/fs/README.txt
===================================================================
--- lovely.recipe/trunk/src/lovely/recipe/fs/README.txt 2008-04-24 06:57:28 UTC (rev 85689)
+++ lovely.recipe/trunk/src/lovely/recipe/fs/README.txt 2008-04-24 08:09:41 UTC (rev 85690)
@@ -55,6 +55,54 @@
d otherdir
d parts
+We can also create a full path.
+
+ >>> write(sample_buildout, 'buildout.cfg',
+ ... """
+ ... [buildout]
+ ... parts = data-dir
+ ... find-links = http://download.zope.org/distribution
+ ...
+ ... [data-dir]
+ ... recipe = lovely.recipe:mkdir
+ ... path = with/subdir
+ ... """)
+ >>> print system(buildout),
+ data-dir: Cannot create /sample-buildout/with/subdir. /sample-buildout/with is not a directory.
+ ...
+
+But we need to activate this function explicitely.
+
+ >>> write(sample_buildout, 'buildout.cfg',
+ ... """
+ ... [buildout]
+ ... parts = data-dir
+ ... find-links = http://download.zope.org/distribution
+ ...
+ ... [data-dir]
+ ... recipe = lovely.recipe:mkdir
+ ... createpath = True
+ ... path = with/subdir
+ ... """)
+ >>> print system(buildout),
+ Uninstalling data-dir.
+ Installing data-dir.
+ data-dir: Creating directory with/subdir
+
+ >>> ls(sample_buildout)
+ - .installed.cfg
+ d bin
+ - buildout.cfg
+ d develop-eggs
+ d eggs
+ d mystuff
+ d otherdir
+ d parts
+ d with
+ >>> ls(sample_buildout + '/with')
+ d subdir
+
+
Creating Files
==============
@@ -88,6 +136,7 @@
d mystuff
d otherdir
d parts
+ d with
The content is written to the file.
@@ -130,4 +179,28 @@
- newfile.sh
d otherdir
d parts
+ d with
+We can also specify to create the path for the file.
+
+ >>> write(sample_buildout, 'buildout.cfg',
+ ... """
+ ... [buildout]
+ ... parts = script
+ ...
+ ... [script]
+ ... recipe = lovely.recipe:mkfile
+ ... createpath = On
+ ... path = subdir/for/file/file.sh
+ ... content = hoschi
+ ... mode = 0755
+ ... """)
+ >>> print system(buildout)
+ Uninstalling script.
+ Installing script.
+ script: Creating directory /sample-buildout/subdir/for/file
+ script: Writing file /sample-buildout/subdir/for/file/file.sh
+
+ >>> ls(sample_buildout + '/subdir/for/file')
+ - file.sh
+
Modified: lovely.recipe/trunk/src/lovely/recipe/fs/mkdir.py
===================================================================
--- lovely.recipe/trunk/src/lovely/recipe/fs/mkdir.py 2008-04-24 06:57:28 UTC (rev 85689)
+++ lovely.recipe/trunk/src/lovely/recipe/fs/mkdir.py 2008-04-24 08:09:41 UTC (rev 85690)
@@ -7,11 +7,15 @@
self.buildout = buildout
self.name = name
self.options = options
+ self.originalPath = options['path']
options['path'] = os.path.join(
buildout['buildout']['directory'],
- options['path'],
+ self.originalPath,
)
- if not os.path.isdir(os.path.dirname(options['path'])):
+ self.createPath = options.get('createpath', 'False').lower() in ['true', 'on', '1']
+ if ( not self.createPath
+ and not os.path.isdir(os.path.dirname(options['path']))
+ ):
logging.getLogger(self.name).error(
'Cannot create %s. %s is not a directory.',
options['path'], os.path.dirname(options['path']))
@@ -21,8 +25,8 @@
path = self.options['path']
if not os.path.isdir(path):
logging.getLogger(self.name).info(
- 'Creating directory %s', os.path.basename(path))
- os.mkdir(path)
+ 'Creating directory %s', self.originalPath)
+ os.makedirs(path)
return ()
def update(self):
Modified: lovely.recipe/trunk/src/lovely/recipe/fs/mkfile.py
===================================================================
--- lovely.recipe/trunk/src/lovely/recipe/fs/mkfile.py 2008-04-24 06:57:28 UTC (rev 85689)
+++ lovely.recipe/trunk/src/lovely/recipe/fs/mkfile.py 2008-04-24 08:09:41 UTC (rev 85690)
@@ -9,11 +9,15 @@
self.options = options
self.mode = int(options.get('mode', '0644'), 8)
options['content']
+ self.originalPath = options['path']
options['path'] = os.path.join(
buildout['buildout']['directory'],
- options['path'],
+ self.originalPath,
)
- if not os.path.isdir(os.path.dirname(options['path'])):
+ self.createPath = options.get('createpath', 'False').lower() in ['true', 'on', '1']
+ if ( not self.createPath
+ and not os.path.isdir(os.path.dirname(options['path']))
+ ):
logging.getLogger(self.name).error(
'Cannot create file %s. %s is not a directory.',
options['path'], os.path.dirname(options['path']))
@@ -21,6 +25,10 @@
def install(self):
path = self.options['path']
+ if self.createPath:
+ logging.getLogger(self.name).info(
+ 'Creating directory %s', os.path.dirname(self.options['path']))
+ os.makedirs(os.path.dirname(self.options['path']))
f = file(path, 'w')
logging.getLogger(self.name).info(
'Writing file %s', path)
Modified: lovely.recipe/trunk/src/lovely/recipe/fs/tests.py
===================================================================
--- lovely.recipe/trunk/src/lovely/recipe/fs/tests.py 2008-04-24 06:57:28 UTC (rev 85689)
+++ lovely.recipe/trunk/src/lovely/recipe/fs/tests.py 2008-04-24 08:09:41 UTC (rev 85690)
@@ -26,12 +26,14 @@
def test_suite():
return unittest.TestSuite((
- doctest.DocFileSuite('README.txt',
- setUp=setUpBuildout,
- tearDown=testing.buildoutTearDown,
- checker=renormalizing.RENormalizing([
+ doctest.DocFileSuite(
+ 'README.txt',
+ setUp=setUpBuildout,
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+ tearDown=testing.buildoutTearDown,
+ checker=renormalizing.RENormalizing([
testing.normalize_path,
testing.normalize_script,
testing.normalize_egg_py])
- )))
+ )))
More information about the Checkins
mailing list