5.5. zeekpkg.uservar module

A module for zkg's notion of "user variables": named values required by packages that the user can provide in a variety of ways, including responses to zkg's input prompting.

class zeekpkg.uservar.UserVar(name, val=None, default=None, desc=None)

Bases: object

A class representing a single user variable.

User variables have a name and an optional description. They resolve to a value using a cascade of mechanisms, including command-line arguments (via --user-var), environment variables, cached previous values, and user input. They may come with a default value.

static parse_arg(arg)

Parser for NAME=VAL format string used in command-line args.

static parse_dict(metadata_dict)

Returns list of UserVars from the metadata's 'user_vars' field.

Parameters:metadata_dict (dict of str->str) -- the input metadata, e.g. from a configparser entry value.
Returns:list of UserVar. If the 'user_vars' field is not present, an empty list is returned. If malformed, returns None.
resolve(name, config, user_var_args=None, force=False)

Populates user variables with updated values and returns them.

This function resolves the variable in the following order:

  1. Use any value provided on the command line via --user-var
  2. If force is not used, prompt the user for input
  3. use an environment variables of the same name,
  4. retrieve from the provided config parser's "user_vars" section,
  5. use the default value of the user variable.

The resolved value is stored with the instance (to be retrieved via .val() in the future) and also returned.

  • name (str) -- the requesting entity, e.g. a package name
  • config (configparser.ConfigParser) -- the zkg configuration
  • user_var_args (list of UserVar) -- user-var instances provided via command line
  • force (bool) -- whether to skip prompting for input

the resulting variable value

Return type:



ValueError -- when we couldn't produce a value for the variable


Returns file-system-safe, lower-case version of the input string.

Any character sequence outside of [a-zA-Z0-9_]+ gets replaced by a single underscore. If the variable has no value or the value is an empty string, returns the given default.