Skip to content

local_settings

Package to deal with saving and retrieving user specific settings.

ASettingRegistry

Bases: ABC

Abstract class defining structure of SettingRegistry class.

It is implementing methods to store secure items into keyring, otherwise mechanism for storing common items must be implemented in abstract methods.

Attributes:

Name Type Description
_name str

Registry names.

Source code in client/ayon_core/lib/local_settings.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
class ASettingRegistry(ABC):
    """Abstract class defining structure of **SettingRegistry** class.

    It is implementing methods to store secure items into keyring, otherwise
    mechanism for storing common items must be implemented in abstract
    methods.

    Attributes:
        _name (str): Registry names.

    """

    def __init__(self, name):
        # type: (str) -> ASettingRegistry
        super(ASettingRegistry, self).__init__()

        self._name = name
        self._items = {}

    def set_item(self, name, value):
        # type: (str, str) -> None
        """Set item to settings registry.

        Args:
            name (str): Name of the item.
            value (str): Value of the item.

        """
        self._set_item(name, value)

    @abstractmethod
    def _set_item(self, name, value):
        # type: (str, str) -> None
        # Implement it
        pass

    def __setitem__(self, name, value):
        self._items[name] = value
        self._set_item(name, value)

    def get_item(self, name):
        # type: (str) -> str
        """Get item from settings registry.

        Args:
            name (str): Name of the item.

        Returns:
            value (str): Value of the item.

        Raises:
            ValueError: If item doesn't exist.

        """
        return self._get_item(name)

    @abstractmethod
    def _get_item(self, name):
        # type: (str) -> str
        # Implement it
        pass

    def __getitem__(self, name):
        return self._get_item(name)

    def delete_item(self, name):
        # type: (str) -> None
        """Delete item from settings registry.

        Args:
            name (str): Name of the item.

        """
        self._delete_item(name)

    @abstractmethod
    def _delete_item(self, name):
        # type: (str) -> None
        """Delete item from settings."""
        pass

    def __delitem__(self, name):
        del self._items[name]
        self._delete_item(name)

delete_item(name)

Delete item from settings registry.

Parameters:

Name Type Description Default
name str

Name of the item.

required
Source code in client/ayon_core/lib/local_settings.py
290
291
292
293
294
295
296
297
298
def delete_item(self, name):
    # type: (str) -> None
    """Delete item from settings registry.

    Args:
        name (str): Name of the item.

    """
    self._delete_item(name)

get_item(name)

Get item from settings registry.

Parameters:

Name Type Description Default
name str

Name of the item.

required

Returns:

Name Type Description
value str

Value of the item.

Raises:

Type Description
ValueError

If item doesn't exist.

Source code in client/ayon_core/lib/local_settings.py
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
def get_item(self, name):
    # type: (str) -> str
    """Get item from settings registry.

    Args:
        name (str): Name of the item.

    Returns:
        value (str): Value of the item.

    Raises:
        ValueError: If item doesn't exist.

    """
    return self._get_item(name)

set_item(name, value)

Set item to settings registry.

Parameters:

Name Type Description Default
name str

Name of the item.

required
value str

Value of the item.

required
Source code in client/ayon_core/lib/local_settings.py
244
245
246
247
248
249
250
251
252
253
def set_item(self, name, value):
    # type: (str, str) -> None
    """Set item to settings registry.

    Args:
        name (str): Name of the item.
        value (str): Value of the item.

    """
    self._set_item(name, value)

AYONSecureRegistry

Store information using keyring.

Registry should be used for private data that should be available only for user.

All passed registry names will have added prefix AYON/ to easier identify which data were created by AYON.

Parameters:

Name Type Description Default
name(str)

Name of registry used as identifier for data.

required
Source code in client/ayon_core/lib/local_settings.py
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
class AYONSecureRegistry:
    """Store information using keyring.

    Registry should be used for private data that should be available only for
    user.

    All passed registry names will have added prefix `AYON/` to easier
    identify which data were created by AYON.

    Args:
        name(str): Name of registry used as identifier for data.
    """
    def __init__(self, name):
        try:
            import keyring

        except Exception:
            raise NotImplementedError(
                "Python module `keyring` is not available."
            )

        # hack for cx_freeze and Windows keyring backend
        if platform.system().lower() == "windows":
            from keyring.backends import Windows

            keyring.set_keyring(Windows.WinVaultKeyring())

        # Force "AYON" prefix
        self._name = "/".join(("AYON", name))

    def set_item(self, name, value):
        # type: (str, str) -> None
        """Set sensitive item into system's keyring.

        This uses `Keyring module`_ to save sensitive stuff into system's
        keyring.

        Args:
            name (str): Name of the item.
            value (str): Value of the item.

        .. _Keyring module:
            https://github.com/jaraco/keyring

        """
        import keyring

        keyring.set_password(self._name, name, value)

    @lru_cache(maxsize=32)
    def get_item(self, name, default=_PLACEHOLDER):
        """Get value of sensitive item from system's keyring.

        See also `Keyring module`_

        Args:
            name (str): Name of the item.
            default (Any): Default value if item is not available.

        Returns:
            value (str): Value of the item.

        Raises:
            ValueError: If item doesn't exist and default is not defined.

        .. _Keyring module:
            https://github.com/jaraco/keyring

        """
        import keyring

        value = keyring.get_password(self._name, name)
        if value is not None:
            return value

        if default is not _PLACEHOLDER:
            return default

        # NOTE Should raise `KeyError`
        raise ValueError(
            "Item {}:{} does not exist in keyring.".format(self._name, name)
        )

    def delete_item(self, name):
        # type: (str) -> None
        """Delete value stored in system's keyring.

        See also `Keyring module`_

        Args:
            name (str): Name of the item to be deleted.

        .. _Keyring module:
            https://github.com/jaraco/keyring

        """
        import keyring

        self.get_item.cache_clear()
        keyring.delete_password(self._name, name)

delete_item(name)

Delete value stored in system's keyring.

See also Keyring module_

Parameters:

Name Type Description Default
name str

Name of the item to be deleted.

required

.. _Keyring module: https://github.com/jaraco/keyring

Source code in client/ayon_core/lib/local_settings.py
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
def delete_item(self, name):
    # type: (str) -> None
    """Delete value stored in system's keyring.

    See also `Keyring module`_

    Args:
        name (str): Name of the item to be deleted.

    .. _Keyring module:
        https://github.com/jaraco/keyring

    """
    import keyring

    self.get_item.cache_clear()
    keyring.delete_password(self._name, name)

get_item(name, default=_PLACEHOLDER) cached

Get value of sensitive item from system's keyring.

See also Keyring module_

Parameters:

Name Type Description Default
name str

Name of the item.

required
default Any

Default value if item is not available.

_PLACEHOLDER

Returns:

Name Type Description
value str

Value of the item.

Raises:

Type Description
ValueError

If item doesn't exist and default is not defined.

.. _Keyring module: https://github.com/jaraco/keyring

Source code in client/ayon_core/lib/local_settings.py
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
@lru_cache(maxsize=32)
def get_item(self, name, default=_PLACEHOLDER):
    """Get value of sensitive item from system's keyring.

    See also `Keyring module`_

    Args:
        name (str): Name of the item.
        default (Any): Default value if item is not available.

    Returns:
        value (str): Value of the item.

    Raises:
        ValueError: If item doesn't exist and default is not defined.

    .. _Keyring module:
        https://github.com/jaraco/keyring

    """
    import keyring

    value = keyring.get_password(self._name, name)
    if value is not None:
        return value

    if default is not _PLACEHOLDER:
        return default

    # NOTE Should raise `KeyError`
    raise ValueError(
        "Item {}:{} does not exist in keyring.".format(self._name, name)
    )

set_item(name, value)

Set sensitive item into system's keyring.

This uses Keyring module_ to save sensitive stuff into system's keyring.

Parameters:

Name Type Description Default
name str

Name of the item.

required
value str

Value of the item.

required

.. _Keyring module: https://github.com/jaraco/keyring

Source code in client/ayon_core/lib/local_settings.py
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
def set_item(self, name, value):
    # type: (str, str) -> None
    """Set sensitive item into system's keyring.

    This uses `Keyring module`_ to save sensitive stuff into system's
    keyring.

    Args:
        name (str): Name of the item.
        value (str): Value of the item.

    .. _Keyring module:
        https://github.com/jaraco/keyring

    """
    import keyring

    keyring.set_password(self._name, name, value)

AYONSettingsRegistry

Bases: JSONSettingRegistry

Class handling AYON general settings registry.

Parameters:

Name Type Description Default
name Optional[str]

Name of the registry.

None
Source code in client/ayon_core/lib/local_settings.py
550
551
552
553
554
555
556
557
558
559
560
561
class AYONSettingsRegistry(JSONSettingRegistry):
    """Class handling AYON general settings registry.

    Args:
        name (Optional[str]): Name of the registry.
    """

    def __init__(self, name=None):
        if not name:
            name = "AYON_settings"
        path = get_launcher_storage_dir()
        super(AYONSettingsRegistry, self).__init__(name, path)

IniSettingRegistry

Bases: ASettingRegistry

Class using :mod:configparser.

This class is using :mod:configparser (ini) files to store items.

Source code in client/ayon_core/lib/local_settings.py
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
class IniSettingRegistry(ASettingRegistry):
    """Class using :mod:`configparser`.

    This class is using :mod:`configparser` (ini) files to store items.

    """

    def __init__(self, name, path):
        # type: (str, str) -> IniSettingRegistry
        super(IniSettingRegistry, self).__init__(name)
        # get registry file
        self._registry_file = os.path.join(path, "{}.ini".format(name))
        if not os.path.exists(self._registry_file):
            with open(self._registry_file, mode="w") as cfg:
                print("# Settings registry", cfg)
                now = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
                print("# {}".format(now), cfg)

    def set_item_section(self, section, name, value):
        # type: (str, str, str) -> None
        """Set item to specific section of ini registry.

        If section doesn't exists, it is created.

        Args:
            section (str): Name of section.
            name (str): Name of the item.
            value (str): Value of the item.

        """
        value = str(value)
        config = configparser.ConfigParser()

        config.read(self._registry_file)
        if not config.has_section(section):
            config.add_section(section)
        current = config[section]
        current[name] = value

        with open(self._registry_file, mode="w") as cfg:
            config.write(cfg)

    def _set_item(self, name, value):
        # type: (str, str) -> None
        self.set_item_section("MAIN", name, value)

    def set_item(self, name, value):
        # type: (str, str) -> None
        """Set item to settings ini file.

        This saves item to ``DEFAULT`` section of ini as each item there
        must reside in some section.

        Args:
            name (str): Name of the item.
            value (str): Value of the item.

        """
        # this does the some, overridden just for different docstring.
        # we cast value to str as ini options values must be strings.
        super(IniSettingRegistry, self).set_item(name, str(value))

    def get_item(self, name):
        # type: (str) -> str
        """Gets item from settings ini file.

        This gets settings from ``DEFAULT`` section of ini file as each item
        there must reside in some section.

        Args:
            name (str): Name of the item.

        Returns:
            str: Value of item.

        Raises:
            ValueError: If value doesn't exist.

        """
        return super(IniSettingRegistry, self).get_item(name)

    @lru_cache(maxsize=32)
    def get_item_from_section(self, section, name):
        # type: (str, str) -> str
        """Get item from section of ini file.

        This will read ini file and try to get item value from specified
        section. If that section or item doesn't exist, :exc:`ValueError`
        is risen.

        Args:
            section (str): Name of ini section.
            name (str): Name of the item.

        Returns:
            str: Item value.

        Raises:
            ValueError: If value doesn't exist.

        """
        config = configparser.ConfigParser()
        config.read(self._registry_file)
        try:
            value = config[section][name]
        except KeyError:
            raise ValueError(
                "Registry doesn't contain value {}:{}".format(section, name))
        return value

    def _get_item(self, name):
        # type: (str) -> str
        return self.get_item_from_section("MAIN", name)

    def delete_item_from_section(self, section, name):
        # type: (str, str) -> None
        """Delete item from section in ini file.

        Args:
            section (str): Section name.
            name (str): Name of the item.

        Raises:
            ValueError: If item doesn't exist.

        """
        self.get_item_from_section.cache_clear()
        config = configparser.ConfigParser()
        config.read(self._registry_file)
        try:
            _ = config[section][name]
        except KeyError:
            raise ValueError(
                "Registry doesn't contain value {}:{}".format(section, name))
        config.remove_option(section, name)

        # if section is empty, delete it
        if len(config[section].keys()) == 0:
            config.remove_section(section)

        with open(self._registry_file, mode="w") as cfg:
            config.write(cfg)

    def _delete_item(self, name):
        """Delete item from default section."""
        self.delete_item_from_section("MAIN", name)

delete_item_from_section(section, name)

Delete item from section in ini file.

Parameters:

Name Type Description Default
section str

Section name.

required
name str

Name of the item.

required

Raises:

Type Description
ValueError

If item doesn't exist.

Source code in client/ayon_core/lib/local_settings.py
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
def delete_item_from_section(self, section, name):
    # type: (str, str) -> None
    """Delete item from section in ini file.

    Args:
        section (str): Section name.
        name (str): Name of the item.

    Raises:
        ValueError: If item doesn't exist.

    """
    self.get_item_from_section.cache_clear()
    config = configparser.ConfigParser()
    config.read(self._registry_file)
    try:
        _ = config[section][name]
    except KeyError:
        raise ValueError(
            "Registry doesn't contain value {}:{}".format(section, name))
    config.remove_option(section, name)

    # if section is empty, delete it
    if len(config[section].keys()) == 0:
        config.remove_section(section)

    with open(self._registry_file, mode="w") as cfg:
        config.write(cfg)

get_item(name)

Gets item from settings ini file.

This gets settings from DEFAULT section of ini file as each item there must reside in some section.

Parameters:

Name Type Description Default
name str

Name of the item.

required

Returns:

Name Type Description
str

Value of item.

Raises:

Type Description
ValueError

If value doesn't exist.

Source code in client/ayon_core/lib/local_settings.py
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
def get_item(self, name):
    # type: (str) -> str
    """Gets item from settings ini file.

    This gets settings from ``DEFAULT`` section of ini file as each item
    there must reside in some section.

    Args:
        name (str): Name of the item.

    Returns:
        str: Value of item.

    Raises:
        ValueError: If value doesn't exist.

    """
    return super(IniSettingRegistry, self).get_item(name)

get_item_from_section(section, name) cached

Get item from section of ini file.

This will read ini file and try to get item value from specified section. If that section or item doesn't exist, :exc:ValueError is risen.

Parameters:

Name Type Description Default
section str

Name of ini section.

required
name str

Name of the item.

required

Returns:

Name Type Description
str

Item value.

Raises:

Type Description
ValueError

If value doesn't exist.

Source code in client/ayon_core/lib/local_settings.py
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
@lru_cache(maxsize=32)
def get_item_from_section(self, section, name):
    # type: (str, str) -> str
    """Get item from section of ini file.

    This will read ini file and try to get item value from specified
    section. If that section or item doesn't exist, :exc:`ValueError`
    is risen.

    Args:
        section (str): Name of ini section.
        name (str): Name of the item.

    Returns:
        str: Item value.

    Raises:
        ValueError: If value doesn't exist.

    """
    config = configparser.ConfigParser()
    config.read(self._registry_file)
    try:
        value = config[section][name]
    except KeyError:
        raise ValueError(
            "Registry doesn't contain value {}:{}".format(section, name))
    return value

set_item(name, value)

Set item to settings ini file.

This saves item to DEFAULT section of ini as each item there must reside in some section.

Parameters:

Name Type Description Default
name str

Name of the item.

required
value str

Value of the item.

required
Source code in client/ayon_core/lib/local_settings.py
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
def set_item(self, name, value):
    # type: (str, str) -> None
    """Set item to settings ini file.

    This saves item to ``DEFAULT`` section of ini as each item there
    must reside in some section.

    Args:
        name (str): Name of the item.
        value (str): Value of the item.

    """
    # this does the some, overridden just for different docstring.
    # we cast value to str as ini options values must be strings.
    super(IniSettingRegistry, self).set_item(name, str(value))

set_item_section(section, name, value)

Set item to specific section of ini registry.

If section doesn't exists, it is created.

Parameters:

Name Type Description Default
section str

Name of section.

required
name str

Name of the item.

required
value str

Value of the item.

required
Source code in client/ayon_core/lib/local_settings.py
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
def set_item_section(self, section, name, value):
    # type: (str, str, str) -> None
    """Set item to specific section of ini registry.

    If section doesn't exists, it is created.

    Args:
        section (str): Name of section.
        name (str): Name of the item.
        value (str): Value of the item.

    """
    value = str(value)
    config = configparser.ConfigParser()

    config.read(self._registry_file)
    if not config.has_section(section):
        config.add_section(section)
    current = config[section]
    current[name] = value

    with open(self._registry_file, mode="w") as cfg:
        config.write(cfg)

JSONSettingRegistry

Bases: ASettingRegistry

Class using json file as storage.

Source code in client/ayon_core/lib/local_settings.py
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
class JSONSettingRegistry(ASettingRegistry):
    """Class using json file as storage."""

    def __init__(self, name, path):
        # type: (str, str) -> JSONSettingRegistry
        super(JSONSettingRegistry, self).__init__(name)
        #: str: name of registry file
        self._registry_file = os.path.join(path, "{}.json".format(name))
        now = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
        header = {
            "__metadata__": {"generated": now},
            "registry": {}
        }

        if not os.path.exists(os.path.dirname(self._registry_file)):
            os.makedirs(os.path.dirname(self._registry_file), exist_ok=True)
        if not os.path.exists(self._registry_file):
            with open(self._registry_file, mode="w") as cfg:
                json.dump(header, cfg, indent=4)

    @lru_cache(maxsize=32)
    def _get_item(self, name):
        # type: (str) -> object
        """Get item value from registry json.

        Note:
            See :meth:`ayon_core.lib.JSONSettingRegistry.get_item`

        """
        with open(self._registry_file, mode="r") as cfg:
            data = json.load(cfg)
            try:
                value = data["registry"][name]
            except KeyError:
                raise ValueError(
                    "Registry doesn't contain value {}".format(name))
        return value

    def get_item(self, name):
        # type: (str) -> object
        """Get item value from registry json.

        Args:
            name (str): Name of the item.

        Returns:
            value of the item

        Raises:
            ValueError: If item is not found in registry file.

        """
        return self._get_item(name)

    def _set_item(self, name, value):
        # type: (str, object) -> None
        """Set item value to registry json.

        Note:
            See :meth:`ayon_core.lib.JSONSettingRegistry.set_item`

        """
        with open(self._registry_file, "r+") as cfg:
            data = json.load(cfg)
            data["registry"][name] = value
            cfg.truncate(0)
            cfg.seek(0)
            json.dump(data, cfg, indent=4)

    def set_item(self, name, value):
        # type: (str, object) -> None
        """Set item and its value into json registry file.

        Args:
            name (str): name of the item.
            value (Any): value of the item.

        """
        self._set_item(name, value)

    def _delete_item(self, name):
        # type: (str) -> None
        self._get_item.cache_clear()
        with open(self._registry_file, "r+") as cfg:
            data = json.load(cfg)
            del data["registry"][name]
            cfg.truncate(0)
            cfg.seek(0)
            json.dump(data, cfg, indent=4)

get_item(name)

Get item value from registry json.

Parameters:

Name Type Description Default
name str

Name of the item.

required

Returns:

Type Description

value of the item

Raises:

Type Description
ValueError

If item is not found in registry file.

Source code in client/ayon_core/lib/local_settings.py
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
def get_item(self, name):
    # type: (str) -> object
    """Get item value from registry json.

    Args:
        name (str): Name of the item.

    Returns:
        value of the item

    Raises:
        ValueError: If item is not found in registry file.

    """
    return self._get_item(name)

set_item(name, value)

Set item and its value into json registry file.

Parameters:

Name Type Description Default
name str

name of the item.

required
value Any

value of the item.

required
Source code in client/ayon_core/lib/local_settings.py
528
529
530
531
532
533
534
535
536
537
def set_item(self, name, value):
    # type: (str, object) -> None
    """Set item and its value into json registry file.

    Args:
        name (str): name of the item.
        value (Any): value of the item.

    """
    self._set_item(name, value)

get_addons_resources_dir(addon_name, *args)

Get directory for storing resources for addons.

Some addons might need to store ad-hoc resources that are not part of addon client package (e.g. because of size). Studio might define dedicated directory to store them with 'AYON_ADDONS_RESOURCES_DIR' environment variable. By default, is used 'addons_resources' in launcher storage (might be shared across platforms).

Parameters:

Name Type Description Default
addon_name str

Addon name.

required
*args str

Subfolders in resources directory.

()

Returns:

Name Type Description
str str

Path to resources directory.

Source code in client/ayon_core/lib/local_settings.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
def get_addons_resources_dir(addon_name: str, *args) -> str:
    """Get directory for storing resources for addons.

    Some addons might need to store ad-hoc resources that are not part of
        addon client package (e.g. because of size). Studio might define
        dedicated directory to store them with 'AYON_ADDONS_RESOURCES_DIR'
        environment variable. By default, is used 'addons_resources' in
        launcher storage (might be shared across platforms).

    Args:
        addon_name (str): Addon name.
        *args (str): Subfolders in resources directory.

    Returns:
        str: Path to resources directory.

    """
    addons_resources_dir = os.getenv("AYON_ADDONS_RESOURCES_DIR")
    if not addons_resources_dir:
        addons_resources_dir = get_launcher_storage_dir("addons_resources")

    return os.path.join(addons_resources_dir, addon_name, *args)

get_ayon_appdirs(*args)

Local app data directory of AYON client.

Deprecated

Use 'get_launcher_local_dir' or 'get_launcher_storage_dir' based on use-case. Deprecation added 24/08/09 (0.4.4-dev.1).

Parameters:

Name Type Description Default
*args Iterable[str]

Subdirectories/files in local app data dir.

()

Returns:

Name Type Description
str

Path to directory/file in local app data dir.

Source code in client/ayon_core/lib/local_settings.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def get_ayon_appdirs(*args):
    """Local app data directory of AYON client.

    Deprecated:
        Use 'get_launcher_local_dir' or 'get_launcher_storage_dir' based on
            use-case. Deprecation added 24/08/09 (0.4.4-dev.1).

    Args:
        *args (Iterable[str]): Subdirectories/files in local app data dir.

    Returns:
        str: Path to directory/file in local app data dir.

    """
    warnings.warn(
        (
            "Function 'get_ayon_appdirs' is deprecated. Should be replaced"
            " with 'get_launcher_local_dir' or 'get_launcher_storage_dir'"
            " based on use-case."
        ),
        DeprecationWarning
    )
    return _get_ayon_appdirs(*args)

get_ayon_username()

AYON username used for templates and publishing.

Uses curet ayon api username.

Returns:

Name Type Description
str

Username.

Source code in client/ayon_core/lib/local_settings.py
591
592
593
594
595
596
597
598
599
600
def get_ayon_username():
    """AYON username used for templates and publishing.

    Uses curet ayon api username.

    Returns:
        str: Username.

    """
    return ayon_api.get_user()["name"]

get_launcher_local_dir(*subdirs)

Get local directory for launcher.

Local directory is used for storing machine or user specific data.

The location is user specific.

Note

This function should be called at least once on bootstrap.

Parameters:

Name Type Description Default
*subdirs str

Subdirectories relative to local dir.

()

Returns:

Name Type Description
str str

Path to local directory.

Source code in client/ayon_core/lib/local_settings.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def get_launcher_local_dir(*subdirs: str) -> str:
    """Get local directory for launcher.

    Local directory is used for storing machine or user specific data.

    The location is user specific.

    Note:
        This function should be called at least once on bootstrap.

    Args:
        *subdirs (str): Subdirectories relative to local dir.

    Returns:
        str: Path to local directory.

    """
    storage_dir = os.getenv("AYON_LAUNCHER_LOCAL_DIR")
    if not storage_dir:
        storage_dir = _get_ayon_appdirs()

    return os.path.join(storage_dir, *subdirs)

get_launcher_storage_dir(*subdirs)

Get storage directory for launcher.

Storage directory is used for storing shims, addons, dependencies, etc.

It is not recommended, but the location can be shared across multiple machines.

Note

This function should be called at least once on bootstrap.

Parameters:

Name Type Description Default
*subdirs str

Subdirectories relative to storage dir.

()

Returns:

Name Type Description
str str

Path to storage directory.

Source code in client/ayon_core/lib/local_settings.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def get_launcher_storage_dir(*subdirs: str) -> str:
    """Get storage directory for launcher.

    Storage directory is used for storing shims, addons, dependencies, etc.

    It is not recommended, but the location can be shared across
        multiple machines.

    Note:
        This function should be called at least once on bootstrap.

    Args:
        *subdirs (str): Subdirectories relative to storage dir.

    Returns:
        str: Path to storage directory.

    """
    storage_dir = os.getenv("AYON_LAUNCHER_STORAGE_DIR")
    if not storage_dir:
        storage_dir = _get_ayon_appdirs()

    return os.path.join(storage_dir, *subdirs)

get_local_site_id()

Get local site identifier.

Identifier is created if does not exist yet.

Source code in client/ayon_core/lib/local_settings.py
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
def get_local_site_id():
    """Get local site identifier.

    Identifier is created if does not exist yet.
    """
    # used for background syncing
    site_id = os.environ.get("AYON_SITE_ID")
    if site_id:
        return site_id

    site_id_path = get_launcher_local_dir("site_id")
    if os.path.exists(site_id_path):
        with open(site_id_path, "r") as stream:
            site_id = stream.read()

    if site_id:
        return site_id

    try:
        from ayon_common.utils import get_local_site_id as _get_local_site_id
        site_id = _get_local_site_id()
    except ImportError:
        raise ValueError("Couldn't access local site id")

    return site_id