def param(self, name, type, default_value=None, description=None): fullname = name if self._current_section and self._current_section != 'DEFAULT': fullname = '%s.%s' % (self._current_section, name) self.file.write(" - name: %s\n" % yaml_string(fullname, allowSimple=True)) self.file.write(" type: %s\n" % yaml_string(type, allowSimple=True)) self.file.write(" default: %s\n" % yaml_value(default_value)) if description: self.file.write(" help: %s\n" % yaml_string(description)) self.file.write("\n")
def yaml_dump_schema_records(records): lines = [] for record in records: if len(record['added']) == 0 and len(record['removed']) == 0: continue lines.append('- version: %s' % yaml_string(str(record['version']))) if 'checkpoint' in record: lines.append(' checkpoint: %s' % yaml_value(record['checkpoint'])) if 'added' in record and len(record['added']) > 0: lines.append(' added:') for param in record['added']: lines.append('') lines.append(' - name: %s' % yaml_string(param['name'], allowSimple=True)) lines.append(' type: %s' % yaml_string(param['type'], allowSimple=True)) if 'default' in param: lines.append(' default: %s' % yaml_value(param['default'])) if 'help' in param: lines.append(' help: %s' % yaml_string(param['help'])) extra_data = [k for k in param.keys() if k not in ['name', 'type', 'default', 'help']] for attr in extra_data: lines.append(' %s: %s' % (attr, yaml_value(param[attr]))) if 'removed' in record and len(record['removed']) > 0: lines.append(' removed:') for removed in record['removed']: lines.append(' - %s' % yaml_string(removed, allowSimple=True)) lines.append('') lines.append('# ====================================================') lines.append('') return "\n".join(lines)