holger krekel  committed 5fffb28

for local paths you can pass "mode=True" to a copy()
in order to copy permission bits (underlying mechanism
is using shutil.copymode)

  • Participants
  • Parent commits 833aadf

Comments (0)

Files changed (5)

 Changes between 1.4.12 and
+- for local paths you can pass "mode=True" to a copy()
+  in order to copy permission bits (underlying mechanism
+  is using shutil.copymode)
 - add paths arguments to py.path.local.sysfind to restrict
   search to the diretories in the path.
 - add isdir/isfile/islink to path.stat() objects allowing to perform

File py/

 (c) Holger Krekel and others, 2004-2010
-__version__ = '1.4.13.dev4'
+__version__ = '1.4.13.dev5'
 from py import _apipkg

File py/_path/

         """ return last modification time of the path. """
         return self.stat().mtime
-    def copy(self, target, archive=False):
+    def copy(self, target, mode=False):
         """ copy path to target."""
-        assert not archive, "XXX archive-mode not supported"
         if self.check(file=1):
             if target.check(dir=1):
                 target = target.join(self.basename)
             assert self!=target
             copychunked(self, target)
+            if mode:
+                copymode(self, target)
             def rec(p):
                 return p.check(link=0)
                 if x.check(link=1):
+                    continue
                 elif x.check(file=1):
                     copychunked(x, newx)
                 elif x.check(dir=1):
+                if mode:
+                    copymode(x, newx)
     def rename(self, target):
         """ rename this path to target. """
         return udir
     make_numbered_dir = classmethod(make_numbered_dir)
+def copymode(src, dest):
+    py.std.shutil.copymode(str(src), str(dest))
 def copychunked(src, dest):
     chunksize = 524288 # half a meg of bytes
     fsrc ='rb')
         description='library with cross-python path, ini-parsing, io, code, log facilities',
         long_description = open('README.txt').read(),
-        version='1.4.13.dev4',
+        version='1.4.13.dev5',
         license='MIT license',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

File testing/path/

             for x,y in oldmodes.items():
+    def test_copy_archiving(self, tmpdir):
+        f = tmpdir.ensure("a", "file1")
+        a = f.dirpath()
+        oldmode = f.stat().mode
+        newmode = oldmode ^ 1
+        f.chmod(newmode)
+        b = tmpdir.join("b")
+        a.copy(b, mode=True)
+        assert b.join(f.basename).stat().mode == newmode
     def test_chown_identity(self, path1):
         owner = path1.stat().owner
         owner = path1.stat().owner
         group = path1.stat().group
         path1.chown(owner, group)