(self, cv_name, cv_default, cv_type)
| 87 | has_content = True |
| 88 | |
| 89 | def __generate_code(self, cv_name, cv_default, cv_type): |
| 90 | |
| 91 | def add_object(config, var, value, type=None): |
| 92 | |
| 93 | def get_value(type, value): |
| 94 | |
| 95 | def have_multipliers(value, mps): |
| 96 | for m in mps: |
| 97 | if value.endswith(m): |
| 98 | return True |
| 99 | |
| 100 | return False |
| 101 | |
| 102 | if value is None or value == 'nullptr' or value == 'NULL': |
| 103 | return None |
| 104 | |
| 105 | # We want to make the type right when inserting the element into the dict. |
| 106 | if type == 'FLOAT': |
| 107 | return float(value) |
| 108 | elif type == 'INT': |
| 109 | # We need to make it YAML compliant as this will be an int, so if contains |
| 110 | # any special character like hex or a multiplier, then we make a string. ATS will |
| 111 | # parse it as string anyway. |
| 112 | if value.startswith('0x') or have_multipliers(value, ['K', 'M', 'G', 'T']): |
| 113 | return str(value) |
| 114 | else: |
| 115 | return int(value) |
| 116 | elif type == 'STRING': |
| 117 | return str(value) |
| 118 | |
| 119 | return None |
| 120 | |
| 121 | obj = {} |
| 122 | key = '' |
| 123 | index = var.find('.') |
| 124 | if index < 0: # last part |
| 125 | config[var] = get_value(type, value) |
| 126 | else: |
| 127 | key = var[:index] |
| 128 | if key not in config: |
| 129 | config[key] = {} |
| 130 | |
| 131 | add_object(config[key], var[index + 1:], value, type=type) |
| 132 | |
| 133 | name = cv_name |
| 134 | if name.startswith("proxy.config."): |
| 135 | name = name[len("proxy.config."):] |
| 136 | elif name.startswith("local.config."): |
| 137 | name = name[len("local.config."):] |
| 138 | |
| 139 | ts = {} |
| 140 | config = {} |
| 141 | |
| 142 | # Build the object |
| 143 | add_object(config, name, cv_default, cv_type) |
| 144 | ts['records'] = config |
| 145 | code = get_code(ts) |
| 146 | literal = nodes.literal_block(code, code) |
no test coverage detected