diff --git a/tools/normalize_channels_yaml.py b/tools/normalize_channels_yaml.py index 714b07794d..1c986affb7 100755 --- a/tools/normalize_channels_yaml.py +++ b/tools/normalize_channels_yaml.py @@ -17,11 +17,10 @@ import locale import sys -import projectconfig_ruamellib +import projectconfig_ruamellib as yaml def main(): - yaml = projectconfig_ruamellib.YAML(strip=False) locale.setlocale(locale.LC_COLLATE, 'C') chandata = yaml.load(open('gerritbot/channels.yaml')) diff --git a/tools/normalize_projects_yaml.py b/tools/normalize_projects_yaml.py index f33f3affd0..2651b3a875 100755 --- a/tools/normalize_projects_yaml.py +++ b/tools/normalize_projects_yaml.py @@ -15,12 +15,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import projectconfig_ruamellib +import projectconfig_ruamellib as yaml def main(): - yaml = projectconfig_ruamellib.YAML() data = yaml.load(open('gerrit/projects.yaml')) for project in data: diff --git a/tools/projectconfig_ruamellib.py b/tools/projectconfig_ruamellib.py index c246fabc14..ade88d257e 100755 --- a/tools/projectconfig_ruamellib.py +++ b/tools/projectconfig_ruamellib.py @@ -21,18 +21,12 @@ def none_representer(dumper, data): class YAML(object): - def __init__(self, strip=True): - """Wrap construction of ruamel yaml object. - - :param bool strip: - Whether or not to strip additional leading spaces at the beginning - of the line. This is only needed when the root object is a list. - """ + def __init__(self): + """Wrap construction of ruamel yaml object.""" self.yaml = ruamel.yaml.YAML() self.yaml.allow_duplicate_keys = True self.yaml.representer.add_representer(type(None), none_representer) self.yaml.indent(mapping=2, sequence=4, offset=2) - self.strip = strip def load(self, stream): return self.yaml.load(stream) @@ -48,6 +42,17 @@ class YAML(object): return '\n'.join(newlines) def dump(self, data, *args, **kwargs): - if self.strip: + if isinstance(data, list): kwargs['transform'] = self.tr self.yaml.dump(data, *args, **kwargs) + + +_yaml = YAML() + + +def load(*args, **kwargs): + return _yaml.load(*args, **kwargs) + + +def dump(*args, **kwargs): + return _yaml.dump(*args, **kwargs)