common.core#

Common attributes, methods and flag values.

Classes:

DataDict(*args, **kwargs)

Custom dictionary class used to store model item data.

Timer(*args, **kwargs)

A custom QTimer class used across the app.

Functions:

add_link(path, link[, section])

Add a relative link to a link config file fount in the root of "path".

byte_to_pretty_string(num[, suffix])

Converts a numeric byte value to a human-readable string.

check_type(value, _type)

Verify the type of object.

debug(func)

Function decorator used to log a debug message.

error(func)

Decorator function used to handle exceptions and report them to the user.

get_entry_from_path(path[, is_dir])

Returns a scandir entry of the given file path.

get_hash(key)

Calculates the md5 hash of a string.

get_links(path[, section])

Returns a list of file links defined in a .links file.

get_platform()

Returns the current platform.

get_py_obj_size(obj)

Sum size of object & members.

get_sequence_and_shot(s)

Returns the sequence and shot name of the given path.

get_template_file_path(name)

Returns the path to the source template file.

get_thread_key(*args)

Returns the key associated with args and the current thread.

get_username()

Returns the name of the currently logged-in user.

int_key(x)

Makes certain we convert int keys back to int values.

is_dir(path)

Cache-back type query.

pseudo_local_bookmark()

Return a location on the local system to store temporary files.

rsc(rel_path)

Returns a resource item from the rsc directory.

sort_words(s)

Sorts a comma separated list of words found in the given string.

temp_path()

Path to the folder to store temporary files.

Data:

CONFIG

The config file name

EmbeddedMode

Startup mode used when Bookmarks runs embedded in a host DCC.

StandaloneMode

Startup mode when Bookmarks is running as a standalone Qt application

class bookmarks.common.core.DataDict(*args, **kwargs)[source]#

Bases: dict

Custom dictionary class used to store model item data.

This class adds compatibility for weakref.ref referencing and custom attributes for storing data state.

Attributes:

data_type

Returns the associated model item type.

loaded

Special attribute used by the item models and associated thread workers.

refresh_needed

Used to signal that the cached data is out of date and needs updating.

property data_type#

Returns the associated model item type.

property loaded#

Special attribute used by the item models and associated thread workers.

When set to True, the helper threads have finished populating data and the item is considered fully loaded.

property refresh_needed#

Used to signal that the cached data is out of date and needs updating.

class bookmarks.common.core.Timer(*args, **kwargs)[source]#

Bases: QTimer

A custom QTimer class used across the app.

Methods:

delete_timers()

Delete all cached timers instances.

setObjectName(v)

Set the instance object name.

classmethod delete_timers()[source]#

Delete all cached timers instances.

setObjectName(v)[source]#

Set the instance object name.

Parameters

v (str) – Object name.

Add a relative link to a link config file fount in the root of “path”.

Parameters
  • path (str) – Path to a folder where the link file resides. E.g. an asset root folder.

  • link (str) – Relative path to the link file.

  • section (str) – The settings section to look for links in. Defaults to links/assets.

bookmarks.common.core.byte_to_pretty_string(num, suffix='B')[source]#

Converts a numeric byte value to a human-readable string.

Parameters
  • num (int) – The number of bytes.

  • suffix (str) – A custom suffix.

Returns

Human readable byte value.

Return type

str

bookmarks.common.core.check_type(value, _type)[source]#

Verify the type of object.

Parameters
  • value (object) – An object of invalid type.

  • _type (type or tuple or types) – The valid type.

Raises

TypeError – When value is not of _type.

bookmarks.common.core.debug(func)[source]#

Function decorator used to log a debug message. No message will be logged, unless debug_on is set to True.

bookmarks.common.core.error(func)[source]#

Decorator function used to handle exceptions and report them to the user.

bookmarks.common.core.get_entry_from_path(path, is_dir=True)[source]#

Returns a scandir entry of the given file path.

Parameters
  • path (str) – Path to directory.

  • is_dir (bool) – Is the path a directory or a file.

Returns

A scandir entry, or None if not found.

Return type

scandir.DirEntry

bookmarks.common.core.get_hash(key)[source]#

Calculates the md5 hash of a string.

In practice, we use this function to generate hashes for file paths. These hashes are used by the ImageCache, user_settings and BookmarkDB to associate data with the file items. Generated hashes are server agnostic, meaning, if the passed string contains a known server’s name, we’ll remove it before hashing.

Parameters

key (str) – A key string to calculate a md5 hash for.

Returns

MD5 hexadecimal digest of the key.

Return type

str

Returns a list of file links defined in a .links file.

.link files are simple QSettings ini files that define a list of paths relative to the .link file. These can be used to define nested assets or bookmark item locations inside job templates.

If a .links file contains two relative paths, subfolder1/nested_asset1 and subfolder2/nested_asset2

asset/
├─ .links
├─ subfolder1/
│  ├─ nested_asset1/
├─ subfolder2/
│  ├─ nested_asset2/

…two asset will be read, nested_asset1 and nested_asset2 (but not the original root asset).

Parameters
  • path (str) – Path to a folder where the link file resides. E.g. an asset root folder.

  • section (str) – The settings section to look for links in. Optional. Defaults to ‘links/asset’.

Returns

A list of relative file paths.

Return type

list

bookmarks.common.core.get_platform()[source]#

Returns the current platform.

bookmarks.common.core.get_py_obj_size(obj)[source]#

Sum size of object & members.

bookmarks.common.core.get_sequence_and_shot(s)[source]#

Returns the sequence and shot name of the given path.

E.g. if the path is C:/SEQ050/SH010/my_file.ma will return (‘SEQ050’, ‘SH010’).

Parameters

s (str) – A file or folder path.

Returns

Sequence and shot name, or (None, None)

if not found.

Return type

tuple (str, str)

bookmarks.common.core.get_template_file_path(name)[source]#

Returns the path to the source template file.

Parameters

name (str) – The name of the template file.

Returns

The path to the template file.

Return type

str

bookmarks.common.core.get_thread_key(*args)[source]#

Returns the key associated with args and the current thread.

Parameters

*argsserver, job, root path segments.

Returns

The key value.

Return type

str

bookmarks.common.core.get_username()[source]#

Returns the name of the currently logged-in user.

bookmarks.common.core.int_key(x)[source]#

Makes certain we convert int keys back to int values.

bookmarks.common.core.is_dir(path)[source]#

Cache-back type query.

bookmarks.common.core.pseudo_local_bookmark()[source]#

Return a location on the local system to store temporary files. This is used to store thumbnails for starred items and other temporary items.

Returns

A tuple of path segments.

Return type

tuple

bookmarks.common.core.rsc(rel_path)[source]#

Returns a resource item from the rsc directory.

bookmarks.common.core.sort_words(s)[source]#

Sorts a comma separated list of words found in the given string.

Returns

A comma-separated list of sorted words.

Return type

str

bookmarks.common.core.temp_path()[source]#

Path to the folder to store temporary files.

Returns

Path to a directory.

Return type

str

bookmarks.common.core.CONFIG = 'config.json'#

The config file name

bookmarks.common.core.EmbeddedMode = 'embedded'#

Startup mode used when Bookmarks runs embedded in a host DCC.

bookmarks.common.core.StandaloneMode = 'standalone'#

Startup mode when Bookmarks is running as a standalone Qt application