Font renaming code originally from:
    https://github.com/chrissimpkins/fontname.py/blob/master/fontname.py

def rename_font(font_path, font_name):
    """
    Font renaming code originally from:
    https://github.com/chrissimpkins/fontname.py/blob/master/fontname.py
    """
    tt = ttLib.TTFont(font_path)
    namerecord_list = tt["name"].names
    variant = ""

    # determine font variant for this file path from name record nameID 2
    for record in namerecord_list:
        if record.nameID == 2:
            variant = (
                record.toUnicode()
            )  # cast to str type in Py 3, unicode type in Py 2
            break

    # test that a variant name was found in the OpenType tables of the font
    if len(variant) == 0:
        raise ValueError(
            "Unable to detect the font variant from the OpenType name table in: %s" % font_path)

    # used for the Postscript name in the name table (no spaces allowed)
    postscript_font_name = font_name.replace(" ", "")
    # font family name
    nameID1_string = font_name
    # full font name
    nameID4_string = font_name + " " + variant
    # Postscript name
    # - no spaces allowed in family name or the PostScript suffix. should be dash delimited
    nameID6_string = postscript_font_name + "-" + variant.replace(" ", "")

    # modify the opentype table data in memory with updated values
    for record in namerecord_list:
        if record.nameID == 1:
            record.string = nameID1_string
        elif record.nameID == 4:
            record.string = nameID4_string
        elif record.nameID == 6:
            record.string = nameID6_string

    # write changes to the font file
    try:
        tt.save(font_path)
    except:
        raise RuntimeError(
            "ERROR: unable to write new name to OpenType tables for: %s" % font_path)