Tooldata

Folder Hierarchy:

root
    |-hotkeys
    |-tools
        |- toolName
                |-settingOne.json
                |SettingTwoFolder
                            |-setting.json
exception RootAlreadyExistsError

Bases: Exception

exception RootDoesntExistError

Bases: Exception

exception InvalidSettingsPath

Bases: Exception

exception InvalidRootError

Bases: Exception

class ToolSet

Bases: object

# Create some roots
tset = ToolSet()

# the order you add roots is important
tset.addRoot(os.path.expanduser("~/Documents/maya/2018/scripts/zootools_preferences"), "userPreferences")

# create a settings instance, if one exists already within one of the roots that setting will be used unless you
# specify the root to use, in which the associated settingsObject for the root will be returned
newSetting = tset.createSetting(relative="tools/tests/helloworld",
                                root="userPreferences",
                                data={"someData": "hello"})
print os.path.exists(newSetting.path())
print newSetting.path()
# lets open a setting
foundSetting = tset.findSetting(relative="tools/tests/helloworld", root="userPreferences")
rootNameForPath(path)
root(name)
addRoot(fullPath, name)

Add root

Parameters:
  • fullPath

  • name

Returns:

deleteRoot(root)

Deletes the root folder location and all files.

Parameters:

root (str) – the root name to delete

Returns:

Return type:

bool

findSetting(relativePath, root=None, extension=None)

Finds a settings object by searching the roots in reverse order.

The first path to exist will be the one to be resolved. If a root is specified and the root+relativePath exists then that will be returned instead

Parameters:
  • relativePath (str) –

  • root (str or None) – The Root name to search if root is None then all roots in reverse order will be search until a settings is found.

Returns:

Return type:

SettingObject

settingFromRootPath(relativePath, rootPath, extension=None)
createSetting(relative, root, data)
open(root, relativePath, extension=None)
class SettingObject(root, relativePath=None, **kwargs)

Bases: dict

Settings class to encapsulate the json data for a given setting

rootPath()
path()
isValid()
save(indent=False, sort=False)

Saves file to disk as json

Parameters:

indent (bool) – If True format the json nicely (indent=2)

Return fullPath:

The full path to the saved .json file

Rtype fullPath:

str

class DirectoryPath(path=None, id_=None, alias=None, pref=None)

Bases: ObjectDict

Parameters:
  • pref

  • id

  • alias

  • path

serialize()

Get the dict

Returns: