Beispiel #1
0
def traversePluginPaths(m, delete, allToolsetsList, isLocal):
    ret = False
    if delete and (not isLocal):
        return True
    excludePaths = nuke.getToolsetExcludePaths()
    for d in nuke.pluginPath():
        d = d.replace('\\', '/')
        ignore = False
        for i in excludePaths:
            i = i.replace('\\', '/')
            if d.find(i) != -1:
                ignore = True
                break
        if ignore:
            continue
        if (not isLocal) and (d.find(".nuke") != -1):
            continue
        if isLocal and (d.find(".nuke") == -1):
            continue
        if os.path.isdir(d):
            dircontents = os.listdir(d)
            if "ToolSets" in dircontents:
                fullPath = "/".join([d, "ToolSets"])
                if createToolsetMenuItems(m, fullPath, fullPath, delete,
                                          allToolsetsList, isLocal):
                    ret = True
    return ret
def createToolsetMenuItems(m, rootPath, fullPath, delete, allToolsetsList,
                           isLocal):
    #TODO: CLEAN THIS FUNCTION

    filecontents = sorted(os.listdir(fullPath), key=str.lower)
    excludePaths = nuke.getToolsetExcludePaths()
    #COMMENT: First list all directories
    retval = False
    if filecontents != []:
        for group in filecontents:
            newPath = "/".join([fullPath, group])
            ignore = False
            if newPath.find(".svn") != -1:
                ignore = True
            else:
                for i in excludePaths:
                    i = i.replace('\\', '/')
                    if newPath.find(i) != -1:
                        ignore = True
                        break
            if os.path.isdir(newPath) and not ignore:
                menuName = group
                if isLocal and (menuName in allToolsetsList):
                    menuName = "[user] " + menuName
                elif not isLocal:
                    allToolsetsList.append(menuName)
                n = m.addMenu(menuName)
                retval = createToolsetMenuItems(n, rootPath,
                                                "/".join([fullPath,
                                                          group]), delete,
                                                allToolsetsList, isLocal)
                #COMMENT: if we are deleting, and the sub directory is now empty, delete the directory also
                if delete and os.listdir(fullPath) == []:
                    os.rmdir(fullPath)
        # Now list individual files
        for group in filecontents:
            fullFileName = "/".join([fullPath, group])
            if not os.path.isdir(fullFileName):

                #COMMENT: delete file with an extention ".nk~" created by edit.
                if ".nk~" in group:
                    os.remove(fullFileName)

                extPos = group.find(".nk")
                if extPos != -1 and extPos == len(group) - 3:
                    group = group.replace('.nk', '')
                    if delete:
                        subM = m.addMenu(group)
                        subM.addCommand("Edit",
                                        'nuke.scriptOpen("%s")' % fullFileName,
                                        "")
                        subM.addCommand(
                            "Rename", 'shared_toolsets.renameToolset("%s")' %
                            fullFileName, "")
                        subM.addCommand("-", "", "")
                        subM.addCommand(
                            "Delete",
                            'shared_toolsets.deleteToolset("%s", "%s")' %
                            (rootPath, fullFileName), "")
                        retval = True
                    else:
                        #COMMENT: get the filename below toolsets
                        i = fullFileName.find("SharedToolSets/")
                        if i != -1:
                            subfilename = fullFileName[i:]
                        else:
                            #COMMENT: should never happen, but just in case ...
                            subfilename = fullfilename
                        if isLocal and (subfilename in allToolsetsList):
                            #COMMENT: if we've already appended [user] to the menu name, don't need it on the filename
                            if (i != -1) and subfilename[
                                    len("SharedToolSets/"):].find("/") == -1:
                                group = "[user] " + group
                        elif not isLocal:
                            allToolsetsList.append(subfilename)

                        #TODO: get ref module name, now it is static linking
                        #current_module = sys.modules[__name__]
                        #print current_module
                        m.addCommand(
                            group, 'shared_toolsets.toolsetLoader("%s")' %
                            fullFileName, "")
                        retval = True
    return retval
Beispiel #3
0
def createToolsetMenuItems(m, rootPath, fullPath, delete, allToolsetsList,
                           isLocal):
    filecontents = sorted(os.listdir(fullPath), key=str.lower)
    excludePaths = nuke.getToolsetExcludePaths()
    # First list all directories
    retval = False
    if filecontents != []:
        for group in filecontents:
            newPath = "/".join([fullPath, group])
            ignore = False
            if newPath.find(".svn") != -1:
                ignore = True
            else:
                for i in excludePaths:
                    i = i.replace('\\', '/')
                    if newPath.find(i) != -1:
                        ignore = True
                        break
            if os.path.isdir(newPath) and not ignore:
                menuName = group
                if isLocal and (menuName in allToolsetsList):
                    menuName = "[user] " + menuName
                elif not isLocal:
                    allToolsetsList.append(menuName)
                n = m.addMenu(menuName)
                retval = createToolsetMenuItems(n, rootPath,
                                                "/".join([fullPath,
                                                          group]), delete,
                                                allToolsetsList, isLocal)
                # if we are deleting, and the sub directory is now empty, delete the directory also
                if delete and os.listdir(fullPath) == []:
                    os.rmdir(fullPath)
        # Now list individual files
        for group in filecontents:
            fullFileName = "/".join([fullPath, group])
            if not os.path.isdir(fullFileName):
                extPos = group.find(".nk")
                if extPos != -1 and extPos == len(group) - 3:
                    group = group.replace('.nk', '')
                    if delete:
                        m.addCommand(
                            group,
                            'nukescripts.toolsets.deleteToolset("%s", "%s")' %
                            (rootPath, fullFileName), "")
                        retval = True
                    else:
                        # get the filename below toolsets
                        i = fullFileName.find("ToolSets/")
                        if i != -1:
                            subfilename = fullFileName[i:]
                        else:
                            # should never happen, but just in case ...
                            subfilename = fullfilename
                        if isLocal and (subfilename in allToolsetsList):
                            # if we've already appended [user] to the menu name, don't need it on the filename
                            if (i != -1) and subfilename[
                                    len("ToolSets/"):].find("/") == -1:
                                group = "[user] " + group
                        elif not isLocal:
                            allToolsetsList.append(subfilename)
                        m.addCommand(group,
                                     'nuke.loadToolset("%s")' % fullFileName,
                                     "")
                        retval = True
    return retval
def createToolsetMenuItems(m, rootPath, fullPath, delete, allToolsetsList, isLocal):
  #TODO: CLEAN THIS FUNCTION

  filecontents = sorted(os.listdir(fullPath), key=str.lower)
  excludePaths = nuke.getToolsetExcludePaths()
  #COMMENT: First list all directories
  retval = False
  if filecontents != []:
    for group in filecontents:
      newPath = "/".join([fullPath, group])
      ignore = False
      if newPath.find(".svn") != -1:
        ignore = True
      else:
        for i in excludePaths:
          i = i.replace('\\', '/')
          if newPath.find(i) != -1:
            ignore = True
            break
      if os.path.isdir(newPath) and not ignore:
        menuName = group
        if isLocal and (menuName in allToolsetsList):
          menuName = "[user] " + menuName
        elif not isLocal:
          allToolsetsList.append(menuName)
        n = m.addMenu(menuName)
        retval = createToolsetMenuItems(n, rootPath, "/".join([fullPath, group]), delete, allToolsetsList, isLocal)
        #COMMENT: if we are deleting, and the sub directory is now empty, delete the directory also
        if delete and os.listdir(fullPath)==[]:
          os.rmdir(fullPath)
    # Now list individual files
    for group in filecontents:
      fullFileName = "/".join([fullPath, group])
      if not os.path.isdir(fullFileName):
        
        #COMMENT: delete file with an extention ".nk~" created by edit.
        if ".nk~" in group:
          os.remove(fullFileName)
        
        extPos = group.find(".nk")
        if extPos != -1 and extPos == len(group) - 3:
          group = group.replace('.nk', '')
          if delete:
            subM = m.addMenu(group)
            subM.addCommand("Edit", 'nuke.scriptOpen("%s")' % fullFileName, "")
            subM.addCommand("Rename", 'shared_toolsets.renameToolset("%s")' % fullFileName, "")
            subM.addCommand("-", "", "")
            subM.addCommand("Delete", 'shared_toolsets.deleteToolset("%s", "%s")' % (rootPath, fullFileName), "")
            retval = True
          else:
            #COMMENT: get the filename below toolsets
            i = fullFileName.find("SharedToolSets/")
            if i != -1:
              subfilename = fullFileName[i:]
            else:
              #COMMENT: should never happen, but just in case ...
              subfilename = fullfilename
            if isLocal and (subfilename in allToolsetsList):
              #COMMENT: if we've already appended [user] to the menu name, don't need it on the filename
              if (i != -1) and subfilename[len("SharedToolSets/"):].find("/") == -1:
                group = "[user] " + group
            elif not isLocal:
              allToolsetsList.append(subfilename)

            #TODO: get ref module name, now it is static linking
            #current_module = sys.modules[__name__]
            #print current_module
            m.addCommand(group, 'shared_toolsets.toolsetLoader("%s")' %  fullFileName, "")            
            retval = True
  return retval