<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def savefig(viz, name, gallery=GALLERY):
 """ Saves the figure to the gallery directory """

    if not path.exists(gallery):
        os.makedirs(gallery)

    # Must save as png
    if len(name.split(".")) > 1:
        raise ValueError("name should not specify extension")

    outpath = path.join(gallery, name+".png")
    viz.poof(outpath=outpath)
    print("created {}".format(outpath))