def moveFile(self, old, dest): dest = ss(dest) try: if self.conf('file_action') == 'hardlink': linktastic.link(old, dest) elif self.conf('file_action') == 'symlink': linktastic.symlink(old, dest) elif self.conf('file_action') == 'copy': shutil.copy(old, dest) elif self.conf('file_action') == 'move_symlink': shutil.move(old, dest) linktastic.symlink(dest, old) else: shutil.move(old, dest) try: os.chmod(dest, Env.getPermission('file')) if os.name == 'nt' and self.conf('ntfs_permission'): os.popen('icacls "' + dest + '"* /reset /T') except: log.error('Failed setting permissions for file: %s, %s', (dest, traceback.format_exc(1))) except OSError, err: # Copying from a filesystem with octal permission to an NTFS file system causes a permission error. In this case ignore it. if not hasattr(os, 'chmod') or err.errno != errno.EPERM: raise else: if os.path.exists(dest): os.unlink(old)
def copy_link(filePath, targetDirectory, useLink, outputDestination): create_destination(outputDestination) if useLink == "hard": try: Logger.info("COPYLINK: Hard linking %s to %s", filePath, targetDirectory) linktastic.link(filePath, targetDirectory) except: Logger.exception("COPYLINK") if os.path.isfile(targetDirectory): Logger.warn("COPYLINK: Something went wrong in linktastic.link, but the destination file was created") else: Logger.warn("COPYLINK: Something went wrong in linktastic.link, copying instead") Logger.debug("COPYLINK: Copying %s to %s", filePath, targetDirectory) shutil.copy(filePath, targetDirectory) elif useLink == "sym": try: Logger.info("COPYLINK: Moving %s to %s before sym linking", filePath, targetDirectory) shutil.move(filePath, targetDirectory) Logger.info("COPYLINK: Sym linking %s to %s", targetDirectory, filePath) linktastic.symlink(targetDirectory, filePath) except: Logger.exception("COPYLINK") if os.path.isfile(targetDirectory): Logger.warn("COPYLINK: Something went wrong in linktastic.link, but the destination file was created") else: Logger.info("COPYLINK: Something went wrong in linktastic.link, copying instead") Logger.debug("COPYLINK: Copying %s to %s", filePath, targetDirectory) shutil.copy(filePath, targetDirectory) else: Logger.debug("Copying %s to %s", filePath, targetDirectory) shutil.copy(filePath, targetDirectory) return True
def copy_link(filePath, targetDirectory, useLink, outputDestination): if os.path.isfile(targetDirectory): Logger.info("COPYLINK: target file already exists. Nothing to be done") return True create_destination(outputDestination) if useLink == "hard": try: Logger.info("COPYLINK: Hard linking %s to %s", filePath, targetDirectory) linktastic.link(filePath, targetDirectory) except: Logger.exception("COPYLINK") if os.path.isfile(targetDirectory): Logger.warn( "COPYLINK: Something went wrong in linktastic.link, but the destination file was created" ) else: Logger.warn( "COPYLINK: Something went wrong in linktastic.link, copying instead" ) Logger.debug("COPYLINK: Copying %s to %s", filePath, targetDirectory) shutil.copy(filePath, targetDirectory) elif useLink == "sym": try: Logger.info("COPYLINK: Moving %s to %s before sym linking", filePath, targetDirectory) shutil.move(filePath, targetDirectory) Logger.info("COPYLINK: Sym linking %s to %s", targetDirectory, filePath) linktastic.symlink(targetDirectory, filePath) except: Logger.exception("COPYLINK") if os.path.isfile(targetDirectory): Logger.warn( "COPYLINK: Something went wrong in linktastic.link, but the destination file was created" ) else: Logger.info( "COPYLINK: Something went wrong in linktastic.link, copying instead" ) Logger.debug("COPYLINK: Copying %s to %s", filePath, targetDirectory) shutil.copy(filePath, targetDirectory) elif useLink == "move": Logger.debug("Moving %s to %s", filePath, targetDirectory) shutil.move(filePath, targetDirectory) else: Logger.debug("Copying %s to %s", filePath, targetDirectory) shutil.copy(filePath, targetDirectory) return True