def LinkOrCopyFiles(sources, dest_dir): '''Copies a list of sources to a destination directory.''' def LinkOrCopyOneFile(src, dst): if not os.path.exists(os.path.dirname(dst)): os.makedirs(os.path.dirname(dst)) if os.path.exists(dst): os.unlink(dst) try: os.link(src, dst) except: shutil.copy(src, dst) for source in sources: LinkOrCopyOneFile(source.GetInPath(), os.path.join(dest_dir, source.GetOutPath()))
def LinkOrCopyFiles(sources, dest_dir): '''Copies a list of sources to a destination directory.''' def LinkOrCopyOneFile(src, dst): try: os.makedirs(os.path.dirname(dst)) except OSError as err: if err.errno != errno.EEXIST: raise if os.path.exists(dst): os.unlink(dst) try: os.link(src, dst) except: shutil.copy(src, dst) for source in sources: LinkOrCopyOneFile(source.GetInPath(), os.path.join(dest_dir, source.GetOutPath()))
def LinkOrCopyFiles(sources, dest_dir): '''Copies a list of sources to a destination directory.''' def LinkOrCopyOneFile(src, dst): if not os.path.exists(os.path.dirname(dst)): os.makedirs(os.path.dirname(dst)) if os.path.exists(dst): # Avoid clobbering the inode if source and destination refer to the # same file already. if os.path.samefile(src, dst): return os.unlink(dst) try: os.link(src, dst) except: shutil.copy(src, dst) for source in sources: LinkOrCopyOneFile(source.GetInPath(), os.path.join(dest_dir, source.GetOutPath()))
def GetOutPaths(self): return (source.GetOutPath() for source in self._added_sources)