Skip to content
This repository has been archived by the owner on Apr 24, 2019. It is now read-only.

Commit

Permalink
- added option "createpath" to mkfile and mkdir recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
jukart committed Apr 24, 2008
1 parent 280e8bd commit e0bbc06
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Expand Up @@ -8,6 +8,11 @@ After
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:
===================

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -13,7 +13,7 @@

setup (
name='lovely.recipe',
version='0.3.1b2',
version='0.3.1b3',
author = "Lovely Systems",
author_email = "office@lovelysystems.com",
license = "ZPL 2.1",
Expand Down
73 changes: 73 additions & 0 deletions src/lovely/recipe/fs/README.txt
Expand Up @@ -55,6 +55,54 @@ If we change the directory name the old directory ('mystuff') is not deleted.
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
==============

Expand Down Expand Up @@ -88,6 +136,7 @@ permissions.
d mystuff
d otherdir
d parts
d with

The content is written to the file.

Expand Down Expand Up @@ -130,4 +179,28 @@ If we change the filename the old file is deleted.
- 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

12 changes: 8 additions & 4 deletions src/lovely/recipe/fs/mkdir.py
Expand Up @@ -7,11 +7,15 @@ def __init__(self, buildout, name, options):
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']))
Expand All @@ -21,8 +25,8 @@ def install(self):
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):
Expand Down
12 changes: 10 additions & 2 deletions src/lovely/recipe/fs/mkfile.py
Expand Up @@ -9,18 +9,26 @@ def __init__(self, buildout, name, options):
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']))
raise zc.buildout.UserError('Invalid Path')

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)
Expand Down
12 changes: 7 additions & 5 deletions src/lovely/recipe/fs/tests.py
Expand Up @@ -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])
)))
)))

0 comments on commit e0bbc06

Please sign in to comment.