| 159 | |
| 160 | |
| 161 | def _print_options(opt_group, options): |
| 162 | for opt in sorted(options, key=lambda x: x["opt"].name): |
| 163 | opt = opt["opt"] |
| 164 | |
| 165 | if opt.name in SKIP_OPTIONS: |
| 166 | continue |
| 167 | |
| 168 | opt_default = opt.default if opt.sample_default is None else opt.sample_default |
| 169 | |
| 170 | # Special case for options which could change during this script run |
| 171 | static_option_value = STATIC_OPTION_VALUES.get(opt_group.name, {}).get( |
| 172 | opt.name, None |
| 173 | ) |
| 174 | if static_option_value: |
| 175 | assert ( |
| 176 | opt_default == static_option_value |
| 177 | ), f"opt_default={opt_default} != static_option_value={static_option_value}" |
| 178 | |
| 179 | # Special handling for list options |
| 180 | if isinstance(opt, cfg.ListOpt): |
| 181 | if opt_default: |
| 182 | value = ",".join(opt_default) |
| 183 | else: |
| 184 | value = "" |
| 185 | |
| 186 | value += " # comma separated list allowed here." |
| 187 | elif isinstance(opt_default, dict): |
| 188 | # this is for [sensorcontainer].partition_provider which |
| 189 | # is a generic cfg.Opt(type=types.Dict(value_type=types.String()) |
| 190 | value = " ".join([f"{k}:{v}" for k, v in opt_default.items()]) |
| 191 | else: |
| 192 | value = opt_default |
| 193 | |
| 194 | print(("# %s" % opt.help).strip()) |
| 195 | |
| 196 | for deprecated_opt in opt.deprecated_opts: |
| 197 | deprecated_opt: cfg.DeprecatedOpt |
| 198 | alias = ( |
| 199 | deprecated_opt.name |
| 200 | if deprecated_opt.group is None |
| 201 | else f"{deprecated_opt.group}.{deprecated_opt.name}" |
| 202 | ) |
| 203 | print(f"# This option has a deprecated alias: {alias}") |
| 204 | |
| 205 | if opt.deprecated_for_removal: |
| 206 | print( |
| 207 | f"# DEPRECATED FOR REMOVAL since {opt.deprecated_since}: {opt.deprecated_reason}".strip() |
| 208 | ) |
| 209 | |
| 210 | if isinstance(opt, cfg.StrOpt) and opt.type.choices: |
| 211 | if isinstance(opt.type.choices, OrderedDict): |
| 212 | valid_values = ", ".join([str(x) for x in opt.type.choices]) |
| 213 | else: |
| 214 | valid_values = opt.type.choices |
| 215 | print("# Valid values: %s" % (valid_values)) |
| 216 | |
| 217 | print(("%s = %s" % (opt.name, value)).strip()) |
| 218 | |