(destination)
Ensure unique filename.

    Makes sure filenames are never overwritten. If file name already exists,
    makes a new one based on the first 50 chars of the original file name,
    having a uuid4 appended afterwards.

    :param string destination:
    :return string:
Ensure unique filename.
Ensure unique filename .
def ensure_unique_filename(destination):
    """Ensure unique filename.

    Makes sure filenames are never overwritten. If file name already exists,
    makes a new one based on the first 50 chars of the original file name,
    having a uuid4 appended afterwards.

    :param string destination:
    :return string:
    """
    if os.path.exists(destination):
        dest, filename = os.path.split(destination)
        filename, extension = os.path.splitext(filename)
        return os.path.join(
            dest, "{0}_{1}{2}".format(filename[:30], uuid.uuid4(), extension)
        )
    else:
        return destination
def ensure_unique_filename ( destination ) : if os . path . exists ( destination ) : dest , filename = os . path . split ( destination ) filename , extension = os . path . splitext ( filename ) return os . path . join ( dest , "{0}_{1}{2}" . format ( filename [ : 30 ] , uuid . uuid4 ( ) , extension ) ) else : return destination