Firmware
Public Member Functions | Public Attributes | List of all members
kconfiglib.Symbol Class Reference
Inheritance diagram for kconfiglib.Symbol:

Public Member Functions

def type (self)
 
def str_value (self)
 
def tri_value (self)
 
def assignable (self)
 
def visibility (self)
 
def config_string (self)
 
def set_value (self, value)
 
def unset_value (self)
 
def referenced (self)
 
def __repr__ (self)
 
def __str__ (self)
 
def custom_str (self, sc_expr_str_fn)
 
def __init__ (self)
 

Public Attributes

 user_value
 
 orig_type
 
 defaults
 
 selects
 
 implies
 
 ranges
 
 nodes
 
 choice
 
 env_var
 
 is_allnoconfig_y
 

Detailed Description

Represents a configuration symbol:

  (menu)config FOO
      ...

The following attributes are available. They should be viewed as read-only,
and some are implemented through @property magic (but are still efficient
to access due to internal caching).

Note: Prompts, help texts, and locations are stored in the Symbol's
MenuNode(s) rather than in the Symbol itself. Check the MenuNode class and
the Symbol.nodes attribute. This organization matches the C tools.

name:
  The name of the symbol, e.g. "FOO" for 'config FOO'.

type:
  The type of the symbol. One of BOOL, TRISTATE, STRING, INT, HEX, UNKNOWN.
  UNKNOWN is for undefined symbols, (non-special) constant symbols, and
  symbols defined without a type.

  When running without modules (MODULES having the value n), TRISTATE
  symbols magically change type to BOOL. This also happens for symbols
  within choices in "y" mode. This matches the C tools, and makes sense for
  menuconfig-like functionality.

orig_type:
  The type as given in the Kconfig file, without any magic applied. Used
  when printing the symbol.

str_value:
  The value of the symbol as a string. Gives the value for string/int/hex
  symbols. For bool/tristate symbols, gives "n", "m", or "y".

  This is the symbol value that's used in relational expressions
  (A = B, A != B, etc.)

  Gotcha: For int/hex symbols, the exact format of the value must often be
  preserved (e.g., when writing a .config file), hence why you can't get it
  directly as an int. Do int(int_sym.str_value) or
  int(hex_sym.str_value, 16) to get the integer value.

tri_value:
  The tristate value of the symbol as an integer. One of 0, 1, 2,
  representing n, m, y. Always 0 (n) for non-bool/tristate symbols.

  This is the symbol value that's used outside of relation expressions
  (A, !A, A && B, A || B).

assignable:
  A tuple containing the tristate user values that can currently be
  assigned to the symbol (that would be respected), ordered from lowest (0,
  representing n) to highest (2, representing y). This corresponds to the
  selections available in the menuconfig interface. The set of assignable
  values is calculated from the symbol's visibility and selects/implies.

  Returns the empty set for non-bool/tristate symbols and for symbols with
  visibility n. The other possible values are (0, 2), (0, 1, 2), (1, 2),
  (1,), and (2,). A (1,) or (2,) result means the symbol is visible but
  "locked" to m or y through a select, perhaps in combination with the
  visibility. menuconfig represents this as -M- and -*-, respectively.

  For string/hex/int symbols, check if Symbol.visibility is non-0 (non-n)
  instead to determine if the value can be changed.

  Some handy 'assignable' idioms:

    # Is 'sym' an assignable (visible) bool/tristate symbol?
    if sym.assignable:
        # What's the highest value it can be assigned? [-1] in Python
        # gives the last element.
        sym_high = sym.assignable[-1]

        # The lowest?
        sym_low = sym.assignable[0]

        # Can the symbol be set to at least m?
        if sym.assignable[-1] >= 1:
            ...

    # Can the symbol be set to m?
    if 1 in sym.assignable:
        ...

visibility:
  The visibility of the symbol. One of 0, 1, 2, representing n, m, y. See
  the module documentation for an overview of symbol values and visibility.

user_value:
  The user value of the symbol. None if no user value has been assigned
  (via Kconfig.load_config() or Symbol.set_value()).

  Holds 0, 1, or 2 for bool/tristate symbols, and a string for the other
  symbol types.

  WARNING: Do not assign directly to this. It will break things. Use
  Symbol.set_value().

config_string:
  The .config assignment string that would get written out for the symbol
  by Kconfig.write_config(). Returns the empty string if no .config
  assignment would get written out.

  In general, visible symbols, symbols with (active) defaults, and selected
  symbols get written out. This includes all non-n-valued bool/tristate
  symbols, and all visible string/int/hex symbols.

  Symbols with the (no longer needed) 'option env=...' option generate no
  configuration output, and neither does the special
  'option defconfig_list' symbol.

  Tip: This field is useful when generating custom configuration output,
  even for non-.config-like formats. To write just the symbols that would
  get written out to .config files, do this:

    if sym.config_string:
        *Write symbol, e.g. by looking sym.str_value*

  This is a superset of the symbols written out by write_autoconf().
  That function skips all n-valued symbols.

  There usually won't be any great harm in just writing all symbols either,
  though you might get some special symbols and possibly some "redundant"
  n-valued symbol entries in there.

nodes:
  A list of MenuNodes for this symbol. Will contain a single MenuNode for
  most symbols. Undefined and constant symbols have an empty nodes list.
  Symbols defined in multiple locations get one node for each location.

choice:
  Holds the parent Choice for choice symbols, and None for non-choice
  symbols. Doubles as a flag for whether a symbol is a choice symbol.

defaults:
  List of (default, cond) tuples for the symbol's 'default' properties. For
  example, 'default A && B if C || D' is represented as
  ((AND, A, B), (OR, C, D)). If no condition was given, 'cond' is
  self.kconfig.y.

  Note that 'depends on' and parent dependencies are propagated to
  'default' conditions.

selects:
  List of (symbol, cond) tuples for the symbol's 'select' properties. For
  example, 'select A if B && C' is represented as (A, (AND, B, C)). If no
  condition was given, 'cond' is self.kconfig.y.

  Note that 'depends on' and parent dependencies are propagated to 'select'
  conditions.

implies:
  Like 'selects', for imply.

ranges:
  List of (low, high, cond) tuples for the symbol's 'range' properties. For
  example, 'range 1 2 if A' is represented as (1, 2, A). If there is no
  condition, 'cond' is self.config.y.

  Note that 'depends on' and parent dependencies are propagated to 'range'
  conditions.

  Gotcha: 1 and 2 above will be represented as (undefined) Symbols rather
  than plain integers. Undefined symbols get their name as their string
  value, so this works out. The C tools work the same way.

rev_dep:
  Reverse dependency expression from other symbols selecting this symbol.
  Multiple selections get ORed together. A condition on a select is ANDed
  with the selecting symbol.

  For example, if A has 'select FOO' and B has 'select FOO if C', then
  FOO's rev_dep will be (OR, A, (AND, B, C)).

weak_rev_dep:
  Like rev_dep, for imply.

direct_dep:
  The 'depends on' dependencies. If a symbol is defined in multiple
  locations, the dependencies at each location are ORed together.

  Internally, this is used to implement 'imply', which only applies if the
  implied symbol has expr_value(self.direct_dep) != 0. 'depends on' and
  parent dependencies are automatically propagated to the conditions of
  properties, so normally it's redundant to check the direct dependencies.

referenced:
  A set() with all symbols and choices referenced in the properties and
  property conditions of the symbol.

  Also includes dependencies inherited from surrounding menus and if's.
  Choices appear in the dependencies of choice symbols.

env_var:
  If the Symbol has an 'option env="FOO"' option, this contains the name
  ("FOO") of the environment variable. None for symbols without no
  'option env'.

  'option env="FOO"' acts like a 'default' property whose value is the
  value of $FOO.

  Symbols with 'option env' are never written out to .config files, even if
  they are visible. env_var corresponds to a flag called SYMBOL_AUTO in the
  C implementation.

is_allnoconfig_y:
  True if the symbol has 'option allnoconfig_y' set on it. This has no
  effect internally (except when printing symbols), but can be checked by
  scripts.

is_constant:
  True if the symbol is a constant (quoted) symbol.

kconfig:
  The Kconfig instance this symbol is from.

Constructor & Destructor Documentation

§ __init__()

def kconfiglib.Symbol.__init__ (   self)
Symbol constructor -- not intended to be called directly by Kconfiglib
clients.

Member Function Documentation

§ __repr__()

def kconfiglib.Symbol.__repr__ (   self)
Returns a string with information about the symbol (including its name,
value, visibility, and location(s)) when it is evaluated on e.g. the
interactive Python prompt.

§ __str__()

def kconfiglib.Symbol.__str__ (   self)
Returns a string representation of the symbol when it is printed,
matching the Kconfig format, with parent dependencies propagated.

The string is constructed by joining the strings returned by
MenuNode.__str__() for each of the symbol's menu nodes, so symbols
defined in multiple locations will return a string with all
definitions.

The returned string does not end in a newline. An empty string is
returned for undefined and constant symbols.

§ assignable()

def kconfiglib.Symbol.assignable (   self)
See the class documentation.

§ config_string()

def kconfiglib.Symbol.config_string (   self)
See the class documentation.

§ custom_str()

def kconfiglib.Symbol.custom_str (   self,
  sc_expr_str_fn 
)
Works like Symbol.__str__(), but allows a custom format to be used for
all symbol/choice references. See expr_str().

§ referenced()

def kconfiglib.Symbol.referenced (   self)
See the class documentation.

§ set_value()

def kconfiglib.Symbol.set_value (   self,
  value 
)
Sets the user value of the symbol.

Equal in effect to assigning the value to the symbol within a .config
file. For bool and tristate symbols, use the 'assignable' attribute to
check which values can currently be assigned. Setting values outside
'assignable' will cause Symbol.user_value to differ from
Symbol.str/tri_value (be truncated down or up).

Setting a choice symbol to 2 (y) sets Choice.user_selection to the
choice symbol in addition to setting Symbol.user_value.
Choice.user_selection is considered when the choice is in y mode (the
"normal" mode).

Other symbols that depend (possibly indirectly) on this symbol are
automatically recalculated to reflect the assigned value.

value:
  The user value to give to the symbol. For bool and tristate symbols,
  n/m/y can be specified either as 0/1/2 (the usual format for tristate
  values in Kconfiglib) or as one of the strings "n"/"m"/"y". For other
  symbol types, pass a string.

  Values that are invalid for the type (such as "foo" or 1 (m) for a
  BOOL or "0x123" for an INT) are ignored and won't be stored in
  Symbol.user_value. Kconfiglib will print a warning by default for
  invalid assignments, and set_value() will return False.

Returns True if the value is valid for the type of the symbol, and
False otherwise. This only looks at the form of the value. For BOOL and
TRISTATE symbols, check the Symbol.assignable attribute to see what
values are currently in range and would actually be reflected in the
value of the symbol. For other symbol types, check whether the
visibility is non-n.

§ str_value()

def kconfiglib.Symbol.str_value (   self)
See the class documentation.

§ tri_value()

def kconfiglib.Symbol.tri_value (   self)
See the class documentation.

§ type()

def kconfiglib.Symbol.type (   self)
See the class documentation.

§ unset_value()

def kconfiglib.Symbol.unset_value (   self)
Resets the user value of the symbol, as if the symbol had never gotten
a user value via Kconfig.load_config() or Symbol.set_value().

§ visibility()

def kconfiglib.Symbol.visibility (   self)
See the class documentation.

The documentation for this class was generated from the following file: