[Checkins] SVN: z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/ Add real code.
Uli Fouquet
uli at gnufix.de
Mon Aug 17 12:14:39 EDT 2009
Log message for revision 102901:
Add real code.
Changed:
A z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/README.txt
A z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/__init__.py
A z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/tests.py
-=-
Added: z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/README.txt
===================================================================
--- z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/README.txt (rev 0)
+++ z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/README.txt 2009-08-17 16:14:39 UTC (rev 102901)
@@ -0,0 +1,121 @@
+Detailed Description
+********************
+
+Simple creation of directories via buildout
+===========================================
+
+Lets create a minimal `buildout.cfg` file::
+
+ >>> write('buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... parts = mydir
+ ... offline = true
+ ...
+ ... [mydir]
+ ... recipe = z3c.recipe.mkdir
+ ... ''')
+
+Now we can run buildout::
+
+ >>> print system(join('bin', 'buildout')),
+ Installing mydir.
+
+The directory was indeed created in the ``parts`` directory::
+
+ >>> ls('parts')
+ d mydir
+
+As we did not specify a special path, the name of the created
+directory is like the section name ``mydir``.
+
+
+Creating a directory in a given path
+====================================
+
+Lets create a minimal `buildout.cfg` file. This time the directory
+has a name different from section name and we have to tell explicitly,
+that we want it to be created in the ``parts/`` directory:
+
+ >>> write('buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... parts = mydir
+ ... offline = true
+ ...
+ ... [mydir]
+ ... recipe = z3c.recipe.mkdir
+ ... path = ${buildout:parts-directory}/myotherdir
+ ... ''')
+
+Now we can run buildout::
+
+ >>> print system(join('bin', 'buildout')),
+ Uninstalling mydir.
+ Installing mydir.
+
+The directory was indeed created::
+
+ >>> ls('parts')
+ d myotherdir
+
+
+Creating relative paths
+=======================
+
+If we specify a relative path, this path will be read relative to the
+buildout directory:
+
+ >>> write('buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... parts = mydir
+ ... offline = true
+ ...
+ ... [mydir]
+ ... recipe = z3c.recipe.mkdir
+ ... path = myrootdir
+ ... ''')
+
+ >>> print system(join('bin', 'buildout')),
+ Uninstalling mydir.
+ Installing mydir.
+
+ >>> ls('.')
+ - .installed.cfg
+ d bin
+ - buildout.cfg
+ d develop-eggs
+ d eggs
+ d myrootdir
+ d parts
+
+ The old directory will vanish:
+
+ >>> ls('parts') is None
+ True
+
+
+Creating intermediate paths
+===========================
+
+If we specify several levels of directories, the intermediate parts
+will be created for us as well:
+
+ >>> write('buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... parts = mydir
+ ... offline = true
+ ...
+ ... [mydir]
+ ... recipe = z3c.recipe.mkdir
+ ... path = myrootdir/other/dir/finaldir
+ ... ''')
+
+ >>> print system(join('bin', 'buildout')),
+ Uninstalling mydir.
+ Installing mydir.
+
+ >>> ls('myrootdir', 'other', 'dir')
+ d finaldir
Added: z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/__init__.py
===================================================================
--- z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/__init__.py (rev 0)
+++ z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/__init__.py 2009-08-17 16:14:39 UTC (rev 102901)
@@ -0,0 +1,37 @@
+import logging
+import os
+import re
+import stat
+import zc.buildout
+
+class Recipe:
+ def __init__(self, buildout, name, options):
+ self.buildout=buildout
+ self.name=name
+ self.options=options
+ self.logger=logging.getLogger(self.name)
+
+ self.path = None
+ if "path" in options:
+ self.path = options["path"]
+ else:
+ self.path = os.path.join(
+ buildout['buildout']['parts-directory'], name)
+ self.path = os.path.abspath(self.path)
+
+ def install(self):
+ self.createIntermediatePaths(self.path)
+ self.options.created(self.path)
+ return self.options.created()
+
+
+ def update(self):
+ return self.install()
+
+ def createIntermediatePaths(self, path):
+ parent = os.path.dirname(path)
+ if os.path.exists(path) or parent == path:
+ return
+ self.createIntermediatePaths(parent)
+ os.mkdir(path)
+ self.options.created(path)
Added: z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/tests.py
===================================================================
--- z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/tests.py (rev 0)
+++ z3c.recipe.mkdir/trunk/z3c/recipe/mkdir/tests.py 2009-08-17 16:14:39 UTC (rev 102901)
@@ -0,0 +1,56 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import os, re
+import pkg_resources
+
+import zc.buildout.testing
+
+import unittest
+import zope.testing
+from zope.testing import doctest, renormalizing
+
+
+def setUp(test):
+ zc.buildout.testing.buildoutSetUp(test)
+ zc.buildout.testing.install_develop('z3c.recipe.mkdir', test)
+ zc.buildout.testing.install('zope.testing', test)
+
+
+checker = renormalizing.RENormalizing([
+ zc.buildout.testing.normalize_path,
+ (re.compile(
+ "Couldn't find index page for '[a-zA-Z0-9.]+' "
+ "\(maybe misspelled\?\)"
+ "\n"
+ ), ''),
+ (re.compile("""['"][^\n"']+z3c.recipe.i18n[^\n"']*['"],"""),
+ "'/z3c.recipe.i18n',"),
+ (re.compile('#![^\n]+\n'), ''),
+ (re.compile('-\S+-py\d[.]\d(-\S+)?.egg'),
+ '-pyN.N.egg',
+ ),
+ ])
+
+
+def test_suite():
+ return unittest.TestSuite(
+ doctest.DocFileSuite('README.txt',
+ setUp=setUp, tearDown=zc.buildout.testing.buildoutTearDown,
+ optionflags=doctest.ELLIPSIS, checker=checker),
+ )
+
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
More information about the Checkins
mailing list