# automatic folder generation

class CreateWriteDir(KellerNukePlugin):
    def configurePlugin(self):
        nuke.knobDefault('Write.beforeRender','createWriteDir.createWriteDir()')
        nuke.knobDefault('DeepWrite.beforeRender', 'createWriteDir.createWriteDir()')

    def unconfigurePlugin(self):
        nuke.knobDefault('Write.beforeRender','')
        nuke.knobDefault('DeepWrite.beforeRender', '')
    
def createWriteDir():
    import os
    file = nuke.filename(nuke.thisNode())
    dir = os.path.dirname(file)
    osdir = nuke.callbacks.filenameFilter(dir)
    #nuke.debug("createWriteDir: Creating writedir: %s" % osdir)
    try:
        os.makedirs(osdir)
    except OSError:
        pass
