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

Commit

Permalink
- Re-arranged the fs recipe code to not check for directory existence…
Browse files Browse the repository at this point in the history
… during

  initialisation phase.

- Fixed some test issues.
  • Loading branch information
Christian Theune committed Jul 1, 2008
1 parent 9aad324 commit f0cb55d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 34 deletions.
9 changes: 7 additions & 2 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ After
=====

BIG TODO: add tests for lovely.recipe.zeo and lovely.recipe.zope to test and
to show for what this all is for.
to show what this all is for.

- Re-arranged the fs recipe code to not check for directory existence during
initialisation phase.

- Fixed some test issues.

2008/04/24 0.3.1b4:
===================

- fixed os error if a path already esists
- fixed os error if a path already exists

2008/04/24 0.3.1b3:
===================
Expand Down
10 changes: 8 additions & 2 deletions src/lovely/recipe/fs/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Creating Directories
... path = mystuff
... """)
>>> print system(buildout),
Getting distribution for 'ZODB3'.
Got ZODB3 3...
Installing data-dir.
data-dir: Creating directory mystuff

Expand Down Expand Up @@ -68,8 +70,12 @@ We can also create a full path.
... path = with/subdir
... """)
>>> print system(buildout),
Uninstalling data-dir.
Installing data-dir.
data-dir: Cannot create /sample-buildout/with/subdir. /sample-buildout/with is not a directory.
...
While:
Installing data-dir.
Error: Invalid Path

But we need to activate this function explicitely.

Expand All @@ -85,8 +91,8 @@ But we need to activate this function explicitely.
... path = with/subdir
... """)
>>> print system(buildout),
Uninstalling data-dir.
Installing data-dir.
data-dir: Creating parent directory /sample-buildout/with
data-dir: Creating directory with/subdir

>>> ls(sample_buildout)
Expand Down
31 changes: 19 additions & 12 deletions src/lovely/recipe/fs/mkdir.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import logging
import zc.buildout

class Mkdir:

class Mkdir(object):

def __init__(self, buildout, name, options):
self.buildout = buildout
Expand All @@ -13,20 +15,25 @@ def __init__(self, buildout, name, options):
self.originalPath,
)
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']))
raise zc.buildout.UserError('Invalid Path')

def install(self):
path = self.options['path']
if not os.path.isdir(path):
logging.getLogger(self.name).info(
'Creating directory %s', self.originalPath)
os.makedirs(path)
dirname = os.path.dirname(self.options['path'])

if not os.path.isdir(dirname):
if self.createPath:
logging.getLogger(self.name).info(
'Creating parent directory %s', dirname)
os.makedirs(dirname)
else:
logging.getLogger(self.name).error(
'Cannot create %s. %s is not a directory.',
path, dirname)
raise zc.buildout.UserError('Invalid Path')

logging.getLogger(self.name).info(
'Creating directory %s', self.originalPath)
os.mkdir(path)
return ()

def update(self):
Expand Down
35 changes: 17 additions & 18 deletions src/lovely/recipe/fs/mkfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import logging

class Mkfile:

class Mkfile(object):

def __init__(self, buildout, name, options):
self.buildout = buildout
Expand All @@ -15,28 +16,26 @@ def __init__(self, buildout, name, options):
self.originalPath,
)
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:
dirname = os.path.dirname(self.options['path'])
if not os.path.isdir(dirname):
filename = self.options['path']
dirname = os.path.dirname(self.options['path'])

if not os.path.isdir(dirname):
if self.createPath:
logging.getLogger(self.name).info(
'Creating directory %s', dirname)
os.makedirs(dirname)
f = file(path, 'w')
else:
logging.getLogger(self.name).error(
'Cannot create file %s. %s is not a directory.',
filename, dirname)
raise zc.buildout.UserError('Invalid path')

f = file(filename, 'w')
logging.getLogger(self.name).info(
'Writing file %s', path)
'Writing file %s', filename)
f.write(self.options['content'])

f.close()
os.chmod(path, self.mode)
return path

os.chmod(filename, self.mode)
return filename

0 comments on commit f0cb55d

Please sign in to comment.