[Checkins] SVN: z3c.recipe.dev/trunk/ work in progress...

Roger Ineichen roger at projekt01.ch
Sat Feb 14 00:32:04 EST 2009


Log message for revision 96514:
  work in progress...
  - added mkdir and mkfile script
  - added tests
  
  Note: the implementation is take from the lovely.recipe
  which is not working on windows anymore since it uses
  the pwd module.
  
  TODO:
  implement os.chmode S_IWRITE and S_IREAD options for
  windows since this is the only permission option on windows.

Changed:
  U   z3c.recipe.dev/trunk/CHANGES.txt
  U   z3c.recipe.dev/trunk/setup.py
  U   z3c.recipe.dev/trunk/src/z3c/recipe/dev/README.txt
  A   z3c.recipe.dev/trunk/src/z3c/recipe/dev/mkdir.py
  A   z3c.recipe.dev/trunk/src/z3c/recipe/dev/mkfile.py
  U   z3c.recipe.dev/trunk/src/z3c/recipe/dev/tests.py

-=-
Modified: z3c.recipe.dev/trunk/CHANGES.txt
===================================================================
--- z3c.recipe.dev/trunk/CHANGES.txt	2009-02-13 23:11:46 UTC (rev 96513)
+++ z3c.recipe.dev/trunk/CHANGES.txt	2009-02-14 05:32:02 UTC (rev 96514)
@@ -5,14 +5,20 @@
 0.5.4 (unreleased)
 ------------------
 
+- Feature: implemented mkdir script
+
+- Feature: implemented mkfile script
+
 - fix tests
 
+
 0.5.3 (2008-04-07)
 ------------------
 
 - Bug: ``script`` ``defaults`` had a bug that prevented it from use
        renamed it to ``arguments``, now it's working
 
+
 0.5.2 (unreleased)
 ------------------
 

Modified: z3c.recipe.dev/trunk/setup.py
===================================================================
--- z3c.recipe.dev/trunk/setup.py	2009-02-13 23:11:46 UTC (rev 96513)
+++ z3c.recipe.dev/trunk/setup.py	2009-02-14 05:32:02 UTC (rev 96514)
@@ -73,6 +73,8 @@
         'zc.buildout': [
              'app = z3c.recipe.dev.app:AppSetup',
              'script = z3c.recipe.dev.script:ScriptSetup',
+             'mkdir = z3c.recipe.dev.mkdir:MkdirSetup',
+             'mkfile = z3c.recipe.dev.mkfile:MkfileSetup',
          ]
     },
 )

Modified: z3c.recipe.dev/trunk/src/z3c/recipe/dev/README.txt
===================================================================
--- z3c.recipe.dev/trunk/src/z3c/recipe/dev/README.txt	2009-02-13 23:11:46 UTC (rev 96513)
+++ z3c.recipe.dev/trunk/src/z3c/recipe/dev/README.txt	2009-02-14 05:32:02 UTC (rev 96514)
@@ -94,7 +94,7 @@
   ...
   ... principals.zcml =
   ...   <unauthenticatedPrincipal
-  ...       id="lovelybooks.anybody"
+  ...       id="zope.anybody"
   ...       title="Unauthenticated User"
   ...       />
   ...
@@ -372,3 +372,230 @@
   Hello World
   foo
   bar
+
+
+Creating Directories
+====================
+
+  >>> write(sample_buildout, 'buildout.cfg',
+  ... """
+  ... [buildout]
+  ... parts = data-dir
+  ... find-links = http://download.zope.org/distribution
+  ...
+  ... [data-dir]
+  ... recipe = z3c.recipe.dev:mkdir
+  ... path = mystuff
+  ... """)
+  >>> print system(buildout),
+  Uninstalling helloworld.
+  Installing data-dir.
+  data-dir: Creating directory mystuff
+
+  >>> ls(sample_buildout)
+  -  .installed.cfg
+  d  bin
+  -  buildout.cfg
+  d  demo1
+  d  demo2
+  d  develop-eggs
+  d  eggs
+  d  hello
+  d  mystuff
+  d  parts
+
+If we change the directory name the old directory ('mystuff') is not deleted.
+
+  >>> write(sample_buildout, 'buildout.cfg',
+  ... """
+  ... [buildout]
+  ... parts = data-dir
+  ... find-links = http://download.zope.org/distribution
+  ...
+  ... [data-dir]
+  ... recipe = z3c.recipe.dev:mkdir
+  ... path = otherdir
+  ... """)
+  >>> print system(buildout),
+  Uninstalling data-dir.
+  Installing data-dir.
+  data-dir: Creating directory otherdir
+
+  >>> ls(sample_buildout)
+  -  .installed.cfg
+  d  bin
+  -  buildout.cfg
+  d  demo1
+  d  demo2
+  d  develop-eggs
+  d  eggs
+  d  hello
+  d  mystuff
+  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 = z3c.recipe.dev:mkdir
+  ... path = with/subdir
+  ... """)
+  >>> print system(buildout),
+  data-dir: Cannot create /sample-buildout/with/subdir. /sample-buildout/with is not a directory.
+  While:
+    Installing.
+    Getting section data-dir.
+    Initializing part data-dir.
+  Error: Invalid Path
+
+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 = z3c.recipe.dev: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  demo1
+  d  demo2
+  d  develop-eggs
+  d  eggs
+  d  hello
+  d  mystuff
+  d  otherdir
+  d  parts
+  d  with
+
+
+Creating Files
+==============
+
+The mkfile recipe creates a file with a given path, content and
+permissions.
+
+  >>> write(sample_buildout, 'buildout.cfg',
+  ... """
+  ... [buildout]
+  ... parts = script
+  ...
+  ... [script]
+  ... recipe = z3c.recipe.dev:mkfile
+  ... path = file.sh
+  ... content = hoschi
+  ... mode = 0755
+  ... """)
+  >>> print system(buildout)
+  Uninstalling data-dir.
+  Installing script.
+  script: Writing file /sample-buildout/file.sh
+  <BLANKLINE>
+
+  >>> ls(sample_buildout)
+  -  .installed.cfg
+  d  bin
+  -  buildout.cfg
+  d  demo1
+  d  demo2
+  d  develop-eggs
+  d  eggs
+  -  file.sh
+  d  hello
+  d  mystuff
+  d  otherdir
+  d  parts
+  d  with
+
+The content is written to the file.
+
+  >>> cat(sample_buildout, 'file.sh')
+  hoschi
+
+And the mode is set. Note set a mode is not supported on windows
+
+  >>> import os, stat, sys
+  >>> path = os.path.join(sample_buildout, 'file.sh')
+  >>> if sys.platform[:3].lower() != "win":
+  ...     oct(stat.S_IMODE(os.stat(path)[stat.ST_MODE]))
+  ... else:
+  ...     '0755'
+  '0755'
+
+If we change the filename the old file is deleted.
+
+  >>> write(sample_buildout, 'buildout.cfg',
+  ... """
+  ... [buildout]
+  ... parts = script
+  ...
+  ... [script]
+  ... recipe = z3c.recipe.dev:mkfile
+  ... path = newfile.sh
+  ... content = hoschi
+  ... mode = 0755
+  ... """)
+  >>> print system(buildout)
+  Uninstalling script.
+  Installing script.
+  script: Writing file /sample-buildout/newfile.sh
+  <BLANKLINE>
+
+  >>> ls(sample_buildout)
+  -  .installed.cfg
+  d  bin
+  -  buildout.cfg
+  d  demo1
+  d  demo2
+  d  develop-eggs
+  d  eggs
+  d  hello
+  d  mystuff
+  -  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 = z3c.recipe.dev: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
+  <BLANKLINE>
+
+  >>> ls(sample_buildout + '/subdir/for/file')
+  -  file.sh
+
+

Added: z3c.recipe.dev/trunk/src/z3c/recipe/dev/mkdir.py
===================================================================
--- z3c.recipe.dev/trunk/src/z3c/recipe/dev/mkdir.py	                        (rev 0)
+++ z3c.recipe.dev/trunk/src/z3c/recipe/dev/mkdir.py	2009-02-14 05:32:02 UTC (rev 96514)
@@ -0,0 +1,53 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation 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.
+#
+##############################################################################
+"""Z3c development recipes
+
+$Id:$
+"""
+
+import os
+import logging
+import zc.buildout
+
+
+class MkdirSetup:
+
+    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'],
+            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)
+        return ()
+
+    def update(self):
+        pass
+

Added: z3c.recipe.dev/trunk/src/z3c/recipe/dev/mkfile.py
===================================================================
--- z3c.recipe.dev/trunk/src/z3c/recipe/dev/mkfile.py	                        (rev 0)
+++ z3c.recipe.dev/trunk/src/z3c/recipe/dev/mkfile.py	2009-02-14 05:32:02 UTC (rev 96514)
@@ -0,0 +1,63 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation 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.
+#
+##############################################################################
+"""Z3c development recipes
+
+$Id:$
+"""
+
+import os
+import logging
+import zc.buildout
+
+
+class MkfileSetup:
+
+    def __init__(self, buildout, name, options):
+        self.buildout = buildout
+        self.name = name
+        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'],
+                              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):
+                logging.getLogger(self.name).info(
+                    'Creating directory %s', dirname)
+                os.makedirs(dirname)
+        f = file(path, 'w')
+        logging.getLogger(self.name).info(
+            'Writing file %s', path)
+        f.write(self.options['content'])
+
+        f.close()
+        os.chmod(path, self.mode)
+        return path
+

Modified: z3c.recipe.dev/trunk/src/z3c/recipe/dev/tests.py
===================================================================
--- z3c.recipe.dev/trunk/src/z3c/recipe/dev/tests.py	2009-02-13 23:11:46 UTC (rev 96513)
+++ z3c.recipe.dev/trunk/src/z3c/recipe/dev/tests.py	2009-02-14 05:32:02 UTC (rev 96514)
@@ -64,6 +64,9 @@
     (re.compile('-\S+-py\d[.]\d(-\S+)?.egg'),
      '-pyN.N.egg',
     ),
+    zc.buildout.testing.normalize_path,
+    zc.buildout.testing.normalize_script,
+    zc.buildout.testing.normalize_egg_py,
     ])
 
 



More information about the Checkins mailing list