Esempio n. 1
0
    def remove_file(cls, path):
        try:
            file_type = check_file_existence(path)
        except (InvalidFilePathError, FileNotFoundError):
            return True

        if file_type not in [FileType.FILE, FileType.LINK]:
            logger.error("not a file: '%s'" % (path))
            return False

        if cls.__dry_run:
            return True

        try:
            os.remove(path)
        except Exception:
            _, e, _ = sys.exc_info()  # for python 2.5 compatibility
            logger.exception(e)
            return False

        return True
Esempio n. 2
0
    def rename(cls, src_path, dst_path):
        try:
            check_file_existence(src_path)
        except (InvalidFilePathError, FileNotFoundError):
            _, e, _ = sys.exc_info()  # for python 2.5 compatibility
            logger.exception(e)
            return False

        if dataproperty.is_empty_string(dst_path):
            logger.error("empty destination path")
            return False

        if os.path.lexists(dst_path):
            logger.error("'%s' already exists" % (dst_path))
            return False

        logger.info("rename: %s -> %s" % (src_path, dst_path))
        if not cls.__dry_run:
            os.rename(src_path, dst_path)

        return True
Esempio n. 3
0
    def remove_directory(cls, path):
        try:
            file_type = check_file_existence(path)
        except (InvalidFilePathError, FileNotFoundError):
            return True

        if file_type not in [FileType.DIRECTORY]:
            logger.error("not a directory: '%s'" % (path))
            return False

        logger.debug("remove directory: " + path)
        if cls.__dry_run:
            return True

        try:
            import shutil
            shutil.rmtree(path, False)
        except (ImportError, IOError):
            _, e, _ = sys.exc_info()  # for python 2.5 compatibility
            logger.exception(e)
            return False

        return True
Esempio n. 4
0
 def test_smoke(self, message, caller):
     logger.error(message, caller)