def _copy_file(source, destination, preserve_mode=False, preserve_times=False, update=False, dry_run=0): log.info("copying file %s -> %s", source, destination) with zipio.open(source, 'rb') as fp_in: if not dry_run: if os.path.exists(destination): os.unlink(destination) with open(destination, 'wb') as fp_out: data = fp_in.read() fp_out.write(data) if preserve_mode: mode = None if hasattr(zipio, 'getmode'): mode = zipio.getmode(source) elif os.path.isfile(source): mode = os.stat(source).st_mode if mode is not None: os.chmod(destination, mode) if preserve_times: mtime = zipio.getmtime(source) os.utime(destination, (mtime, mtime))
def _copy_file( source, destination, preserve_mode=False, preserve_times=False, update=False, dry_run=0, ): log.info("copying file %s -> %s", source, destination) with zipio.open(source, "rb") as fp_in: if not dry_run: if os.path.isdir(destination): destination = os.path.join(destination, os.path.basename(source)) if os.path.exists(destination): os.unlink(destination) with open(destination, "wb") as fp_out: data = fp_in.read() fp_out.write(data) if preserve_mode: mode = None if hasattr(zipio, "getmode"): mode = zipio.getmode(source) elif os.path.isfile(source): mode = stat.S_IMODE(os.stat(source).st_mode) if mode is not None: os.chmod(destination, mode) if preserve_times: mtime = zipio.getmtime(source) os.utime(destination, (mtime, mtime))
def _copy_file(source, destination, preserve_mode=False, preserve_times=False, update=False, dry_run=0): log.info("copying file %s -> %s", source, destination) with zipio.open(source, 'rb') as fp_in: if not dry_run: if os.path.exists(destination): os.unlink(destination) with open(destination, 'wb') as fp_out: data = fp_in.read() fp_out.write(data) if preserve_mode: mode = None if hasattr(zipio, 'getmode'): mode = zipio.getmode(source) elif os.path.isfile(source): mode = os.stat(source).st_mode if mode is not None: os.chmod(destination, mode) if preserve_times: mtime = zipio.getmtime(source) os.utime(destination, (mtime, mtime))
def test_getmode(self): fn = os.path.join(TESTDATA, 'test.txt') self.assertEqual(stat.S_IMODE(os.stat(fn).st_mode), zipio.getmode(fn)) # XXX: Not too happy about this... fn = os.path.join(TESTDATA, 'zipped.egg') self.assertEqual(stat.S_IMODE(os.stat(fn).st_mode), zipio.getmode(fn)) fn = os.path.join(TESTDATA, 'zipped.egg/test.txt') mode = zipio.getmode(fn) self.assertEqual(mode, 0o644) fn = os.path.join(TESTDATA, 'zipped.egg/subdir') mode = zipio.getmode(fn) self.assertEqual(mode, 0o755) fn = os.path.join(TESTDATA, 'zipped.egg/subdir4') self.assertEqual(zipio.getmode(fn), stat.S_IMODE(zipio._DFLT_DIR_MODE)) self.assertRaises(IOError, zipio.getmode, os.path.join(TESTDATA, 'no-file')) self.assertRaises(IOError, zipio.getmode, os.path.join(TESTDATA, 'zipped.egg/no-file'))