Got one OK for this from Bo...JMarc? Jose?

Richard Heck wrote:
Bo Peng wrote:
So yes, it seems like a python bug, but one we should probably try to
work around.

I am worried that your patch does not do everything shutil.copy is
doing, and may fail under other circumstances.
Here's a simpler patch. This essentially is the shutil.copy() code but try-excepting the chmod stuff. Here's that code:
def copy(src, dst):
   """Copy data and mode bits ("cp src dst").

   The destination may be a directory.

   """
   if os.path.isdir(dst):
       dst = os.path.join(dst, os.path.basename(src))
   copyfile(src, dst)
   copymode(src, dst)
We're copying files, so the isdir stuff isn't needed by us, though I've added a check to exclude them.

OK to commit this one? (I've also filed a bug report with the python folks.)

Richard

------------------------------------------------------------------------

Index: ext_copy.py
===================================================================
--- ext_copy.py (revision 19264)
+++ ext_copy.py (working copy)
@@ -71,6 +71,8 @@
# copy all matching files in from_dir to to_dir
     for file in os.listdir(from_dir):
+      if os.path.isdir(file):
+        continue
       junk, ext = os.path.splitext(os.path.basename(file))
       ext = ext.lower()[1:] #strip the leading dot
       try:
@@ -81,7 +83,11 @@
         continue #not found
       from_file = os.path.join(from_dir, file)
       to_file  = os.path.join(to_dir, file)
-      shutil.copy(from_file, to_file)
+      shutil.copyfile(from_file, to_file)
+      try:
+        shutil.copymode(from_file, to_file)
+      except:
+        pass
     return 0
if __name__ == "__main__":


--
==================================================================
Richard G Heck, Jr
Professor of Philosophy
Brown University
http://frege.brown.edu/heck/
==================================================================
Get my public key from http://sks.keyserver.penguin.de
Hash: 0x1DE91F1E66FFBDEC
Learn how to sign your email using Thunderbird and GnuPG at:
http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto

Index: ext_copy.py
===================================================================
--- ext_copy.py	(revision 19264)
+++ ext_copy.py	(working copy)
@@ -71,6 +71,8 @@
 
     # copy all matching files in from_dir to to_dir
     for file in os.listdir(from_dir):
+      if os.path.isdir(file):
+        continue
       junk, ext = os.path.splitext(os.path.basename(file))
       ext = ext.lower()[1:] #strip the leading dot
       try:
@@ -81,7 +83,11 @@
         continue #not found
       from_file = os.path.join(from_dir, file)
       to_file  = os.path.join(to_dir, file)
-      shutil.copy(from_file, to_file)
+      shutil.copyfile(from_file, to_file)
+      try:
+        shutil.copymode(from_file, to_file)
+      except:
+        pass
     return 0
 
 if __name__ == "__main__":

Reply via email to