Commits

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 1.4.13.dev
 ==================================================
 
+- 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/__init__.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/local.py

         """ 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)
         else:
             def rec(p):
                 return p.check(link=0)
                 newx.dirpath().ensure(dir=1)
                 if x.check(link=1):
                     newx.mksymlinkto(x.readlink())
+                    continue
                 elif x.check(file=1):
                     copychunked(x, newx)
                 elif x.check(dir=1):
                     newx.ensure(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 = src.open('rb')
         name='py',
         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',
         url='http://pylib.readthedocs.org/',
         license='MIT license',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

File testing/path/test_local.py

             for x,y in oldmodes.items():
                 x.chmod(y)
 
+    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
+
     @failsonjython
     def test_chown_identity(self, path1):
         owner = path1.stat().owner
         owner = path1.stat().owner
         group = path1.stat().group
         path1.chown(owner, group)
+