

__file__ = script.getResource(script.getId()+".py").getAbsolutePath()

def __init_python_path():
    import sys
    
    new_path = list()
    new_path.append(sys.path[0])

    # Add folder of script
    path = script.getFile().getParentFile().getCanonicalPath()
    if not path in new_path:
      new_path.append(path)

    # Add folder of root user scripts
    path = script.getManager().getUserFolder().getFile().getCanonicalPath()
    if not path in new_path:
      new_path.append(path)
    
    # Add folders of libs
    folders = script.getManager().getLibFolders()
    if folders != None:
        for folder in folders:
            path = folder.getCanonicalPath()
            if not path in new_path:
              new_path.append(path)

    # Add the scripts folder of system folders
    folders = script.getManager().getSystemFolder()
    if folders != None:
        for folder in folders.getUnits():
            path = folder.getFile().getCanonicalPath()
            if not path in new_path:
              new_path.append(path)
    new_path.append("__classpath__")
    new_path.append("__pyclasspath__/")
    del sys.path[:]
    sys.path.extend(new_path)


__init_python_path()

del __init_python_path


