[Checkins] SVN: zc.recipe.deployment/trunk/s Made it possible to create directories whose parent directories don't

Amos Latteier amos at latteier.com
Mon Dec 4 17:08:11 EST 2006


Log message for revision 71403:
  Made it possible to create directories whose parent directories don't 
  already exist. Also modified setup.py to shut up a setuptools warning.
  

Changed:
  U   zc.recipe.deployment/trunk/setup.py
  U   zc.recipe.deployment/trunk/src/zc/recipe/deployment.py

-=-
Modified: zc.recipe.deployment/trunk/setup.py
===================================================================
--- zc.recipe.deployment/trunk/setup.py	2006-12-04 21:43:21 UTC (rev 71402)
+++ zc.recipe.deployment/trunk/setup.py	2006-12-04 22:08:10 UTC (rev 71403)
@@ -3,6 +3,7 @@
 name = 'zc.recipe.deployment'
 setup(
     name = name,
+    install_requires = ['setuptools'],
     entry_points = '[zc.buildout]\ndefault=%s:Recipe' % name,
     package_dir = {'': 'src'},
     packages = find_packages('src'),

Modified: zc.recipe.deployment/trunk/src/zc/recipe/deployment.py
===================================================================
--- zc.recipe.deployment/trunk/src/zc/recipe/deployment.py	2006-12-04 21:43:21 UTC (rev 71402)
+++ zc.recipe.deployment/trunk/src/zc/recipe/deployment.py	2006-12-04 22:08:10 UTC (rev 71403)
@@ -29,6 +29,19 @@
         options['etc-directory'] = os.path.join(options.get('etc', '/etc'),
                                                 name)
 
+    def make_dirs(self, name, uid, gid, created):
+        # modified from standard lib
+        head, tail = os.path.split(name)
+        if not tail:
+            head, tail = os.path.split(head)
+        if head and tail and not os.path.exists(head):
+            self.make_dirs(head, uid, gid, created)
+            if tail == os.curdir: # xxx/newdir/. exists if xxx/newdir exists
+                return
+        os.mkdir(name, 0755)
+        created.append(name)
+        os.chown(name, uid, gid)
+        
     def install(self):
         options = self.options
         user = options['user']
@@ -38,10 +51,7 @@
             for d in 'run', 'log', 'etc':
                 d = options[d+'-directory']
                 if not os.path.isdir(d):
-                    os.mkdir(d, 0775)
-                    created.append(d)
-                    os.chmod(d, 0775)
-                    os.chown(d, uid, gid)
+                    self.make_dirs(d, uid, gid, created)
             return created
         except:
             for d in created:



More information about the Checkins mailing list