File: locations.rst

package info (click to toggle)
python-oslo.config 1%3A8.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,192 kB
  • sloc: python: 10,740; makefile: 30; sh: 10
file content (69 lines) | stat: -rw-r--r-- 2,334 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
==========================
 Option Setting Locations
==========================

.. currentmodule:: oslo_config.cfg

The :func:`~ConfigOpts.get_location` method of :class:`ConfigOpts` can
be used to determine where the value for an option was set, either by
the user or by the application code. The return value is a
:class:`LocationInfo` instance, which includes 2 fields: ``location``
and ``detail``.

The ``location`` value is a member of the :class:`Locations` enum,
which has 5 possible values. The ``detail`` value is a string
describing the location. Its value depends on the ``location``.

.. list-table::
   :header-rows: 1
   :widths: 15 15 35 35

   * - Value
     - ``is_user_controlled``
     - Description
     - ``detail``
   * - ``opt_default``
     - ``False``
     - The original default set when the option was defined.
     - The source file name where the option is defined.
   * - ``set_default``
     - ``False``
     - A default value set by the application as an override of the
       original default. This usually only applies to options defined
       in libraries.
     - The source file name where :func:`~ConfigOpts.set_default` or
       :func:`set_defaults` was called.
   * - ``set_override``
     - ``False``
     - A forced value set by the application.
     - The source file name where :func:`~ConfigOpts.set_override` was
       called.
   * - ``user``
     - ``True``
     - A value set by the user through a configuration backend such as
       a file.
     - The configuration file where the option is set.
   * - ``command_line``
     - ``True``
     - A value set by the user on the command line.
     - Empty string.
   * - ``environment``
     - ``True``
     - A value set by the user in the process environment.
     - The name of the environment variable.

Did a user set a configuration option?
======================================

Each :class:`Locations` enum value has a boolean property indicating
whether that type of location is managed by the user. This eliminates
the need for application code to track which types of locations are
user-controlled separately.

.. code-block:: python

   loc = CONF.get_location('normal_opt').location
   if loc.is_user_controlled:
      print('normal_opt was set by the user')
   else:
      print('normal_opt was set by the application')