Esempio n. 1
0
def copy_link(src, targetLink, useLink):
    logger.info("MEDIAFILE: [%s]" % (os.path.basename(targetLink)), 'COPYLINK')
    logger.info("SOURCE FOLDER: [%s]" % (os.path.dirname(src)), 'COPYLINK')
    logger.info("TARGET FOLDER: [%s]" % (os.path.dirname(targetLink)),
                'COPYLINK')

    if src != targetLink and os.path.exists(targetLink):
        logger.info(
            "MEDIAFILE already exists in the TARGET folder, skipping ...",
            'COPYLINK')
        return True
    elif src == targetLink and os.path.isfile(targetLink) and os.path.isfile(
            src):
        logger.info("SOURCE AND TARGET files are the same, skipping ...",
                    'COPYLINK')
        return True
    elif src == os.path.dirname(targetLink):
        logger.info("SOURCE AND TARGET folders are the same, skipping ...",
                    'COPYLINK')
        return True

    makeDir(os.path.dirname(targetLink))
    try:
        if useLink == 'dir':
            logger.info("Directory linking SOURCE FOLDER -> TARGET FOLDER",
                        'COPYLINK')
            linktastic.dirlink(src, targetLink)
            return True
        if useLink == 'junction':
            logger.info(
                "Directory junction linking SOURCE FOLDER -> TARGET FOLDER",
                'COPYLINK')
            linktastic.dirlink(src, targetLink)
            return True
        elif useLink == "hard":
            logger.info("Hard linking SOURCE MEDIAFILE -> TARGET FOLDER",
                        'COPYLINK')
            linktastic.link(src, targetLink)
            return True
        elif useLink == "sym":
            logger.info("Sym linking SOURCE MEDIAFILE -> TARGET FOLDER",
                        'COPYLINK')
            shutil.move(src, targetLink)
            linktastic.symlink(targetLink, src)
            return True
        elif useLink == "move":
            logger.info("Moving SOURCE MEDIAFILE -> TARGET FOLDER", 'COPYLINK')
            shutil.move(src, targetLink)
            return True
    except Exception, e:
        logger.warning("Error: %s, copying instead ... " % (e), 'COPYLINK')
Esempio n. 2
0
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

    makeDir(outputDestination)
    if useLink == "hard":
        try:
            logger.info("COPYLINK: Hard linking %s to %s" % (filePath, targetDirectory))
            linktastic.link(filePath, targetDirectory)
        except:
            logger.error("COPYLINK")
            if os.path.isfile(targetDirectory):
                logger.warning(
                    "COPYLINK: Something went wrong in linktastic.link, but the destination file was created")
            else:
                logger.warning("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.error("COPYLINK")
            if os.path.isfile(targetDirectory):
                logger.warning(
                    "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
Esempio n. 3
0
def copy_link(src, targetLink, useLink):
    logger.info("MEDIAFILE: [%s]" % (os.path.basename(targetLink)), 'COPYLINK')
    logger.info("SOURCE FOLDER: [%s]" % (os.path.dirname(src)), 'COPYLINK')
    logger.info("TARGET FOLDER: [%s]" % (os.path.dirname(targetLink)), 'COPYLINK')

    if src != targetLink and os.path.exists(targetLink):
        logger.info("MEDIAFILE already exists in the TARGET folder, skipping ...", 'COPYLINK')
        return True
    elif src == targetLink and os.path.isfile(targetLink) and os.path.isfile(src):
        logger.info("SOURCE AND TARGET files are the same, skipping ...", 'COPYLINK')
        return True
    elif src == os.path.dirname(targetLink):
        logger.info("SOURCE AND TARGET folders are the same, skipping ...", 'COPYLINK')
        return True

    makeDir(os.path.dirname(targetLink))
    try:
        if useLink == 'dir':
            logger.info("Directory linking SOURCE FOLDER -> TARGET FOLDER", 'COPYLINK')
            linktastic.dirlink(src, targetLink)
            return True
        if useLink == 'junction':
            logger.info("Directory junction linking SOURCE FOLDER -> TARGET FOLDER", 'COPYLINK')
            linktastic.dirlink(src, targetLink)
            return True
        elif useLink == "hard":
            logger.info("Hard linking SOURCE MEDIAFILE -> TARGET FOLDER", 'COPYLINK')
            linktastic.link(src, targetLink)
            return True
        elif useLink == "sym":
            logger.info("Sym linking SOURCE MEDIAFILE -> TARGET FOLDER", 'COPYLINK')
            shutil.move(src, targetLink)
            linktastic.symlink(targetLink, src)
            return True
        elif useLink == "move":
            logger.info("Moving SOURCE MEDIAFILE -> TARGET FOLDER", 'COPYLINK')
            shutil.move(src, targetLink)
            return True
    except Exception, e:
        logger.warning("Error: %s, copying instead ... " % (e), 'COPYLINK')