From bb2bba6f56caa4f005666756bbc6ac2202396dd0 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Thu, 5 Mar 2015 15:49:20 -0800 Subject: [PATCH] Normalize Gerrit projects.yaml Add a script to perform the normalization. Change-Id: I9ebc75f8a5096fe65f7a30df43e60c67bb943aa0 --- gerrit/projects.yaml | 20 +++---- tools/normalize_projects_yaml.py | 98 ++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 tools/normalize_projects_yaml.py diff --git a/gerrit/projects.yaml b/gerrit/projects.yaml index 70311208e0..71fd3fd690 100755 --- a/gerrit/projects.yaml +++ b/gerrit/projects.yaml @@ -720,7 +720,7 @@ description: Standalone UI replacment for Gerrit - project: openstack-infra/yaml2ical use-storyboard: true - description: Generate iCal files from a YAML description of meetings + description: Generate iCal files from a YAML description of meetings options: - direct-release - project: openstack-infra/zmq-event-publisher @@ -977,11 +977,11 @@ docimpact-group: openstack-api-site upstream: https://github.com/chungg/oslo.middleware.git - project: openstack/oslo.policy - description: Rules engine to enforce access control policy + description: Rules engine to enforce access control policy docimpact-group: openstack-manuals upstream: git://github.com/rodrigods/oslo.policy.git groups: - - oslo + - oslo - project: openstack/oslo.rootwrap docimpact-group: openstack-manuals upstream: git://github.com/ttx/oslo.rootwrap.git @@ -1471,7 +1471,7 @@ - openstack-chef docimpact-group: openstack-chef description: Chef Cookbook - Pacemaker - upstream : git://github.com/aspiers/cookbook-pacemaker.git + upstream: git://github.com/aspiers/cookbook-pacemaker.git acl-config: /home/gerrit2/acls/stackforge/chef-cookbooks.config options: - direct-release @@ -1755,7 +1755,7 @@ - project: stackforge/libra description: Create and manage loadbalancers - project: stackforge/logaas - description: "Logging as a Service for OpenStack" + description: Logging as a Service for OpenStack upstream: https://github.com/boris-42/logaas.git - project: stackforge/magnetodb description: Key-value database service for OpenStack cloud. @@ -2092,7 +2092,7 @@ acl-config: /home/gerrit2/acls/stackforge/puppet-modules.config upstream: git://github.com/puppetlabs/puppetlabs-openstack.git - project: stackforge/puppet-openstack-cloud - description: Flexible Puppet implementation capable of configuring a scalable OpenStack Cloud + description: Flexible Puppet implementation capable of configuring a scalable OpenStack Cloud upstream: git://github.com/redhat-openstack/puppet-openstack-cloud.git - project: stackforge/puppet-openstack-specs description: Puppet for OpenStack Design Specifications @@ -2274,7 +2274,7 @@ description: 'Guest agent for Solum. See: https://wiki.openstack.org/wiki/Solum' upstream: git://github.com/julienvey/solum-guestagent.git - project: stackforge/solum-specs - description: 'Solum Design Specifications' + description: Solum Design Specifications upstream: git://github.com/rackerlabs/solum-specs - project: stackforge/sphinxcontrib-docbookrestapi description: Sphinx extension that generates documentation for api-site from RST files. @@ -2355,11 +2355,11 @@ description: SwiftPolicy Middleware for OpenStack Swift allows to use a JSON policy file to handle swift authorizations. upstream: git://github.com/cloudwatt/swiftpolicy.git - project: stackforge/swiftsync - description: "Swift mass syncronizer" + description: Swift mass syncronizer upstream: git://github.com/enovance/swiftsync.git acl-config: /home/gerrit2/acls/openstack/swiftsync.config - project: stackforge/tacker - description: "tacker: specifications a servicevm/device life cycle manager. See https://wiki.openstack.org/wiki/ServiceVM" + description: 'tacker: specifications a servicevm/device life cycle manager. See https://wiki.openstack.org/wiki/ServiceVM' - project: stackforge/tacker-specs description: Blueprints for tacker groups: @@ -2370,7 +2370,7 @@ groups: - openstack-telcowg - project: stackforge/tomograph - description: "Library to help distributed applications send trace information to metrics backends like Zipkin and Statsd." + description: Library to help distributed applications send trace information to metrics backends like Zipkin and Statsd. upstream: https://github.com/timjr/tomograph.git - project: stackforge/tricircle groups: diff --git a/tools/normalize_projects_yaml.py b/tools/normalize_projects_yaml.py new file mode 100644 index 0000000000..981c6cc5cb --- /dev/null +++ b/tools/normalize_projects_yaml.py @@ -0,0 +1,98 @@ +#! /usr/bin/env python +# +# Copyright (c) 2015 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import yaml +from collections import OrderedDict + + +def project_representer(dumper, data): + return dumper.represent_mapping('tag:yaml.org,2002:map', + data.items()) + + +def construct_yaml_map(self, node): + data = OrderedDict() + yield data + value = self.construct_mapping(node) + + if isinstance(node, yaml.MappingNode): + self.flatten_mapping(node) + else: + raise yaml.constructor.ConstructorError( + None, None, + 'expected a mapping node, but found %s' % node.id, + node.start_mark) + + mapping = OrderedDict() + for key_node, value_node in node.value: + key = self.construct_object(key_node, deep=False) + try: + hash(key) + except TypeError as exc: + raise yaml.constructor.ConstructorError( + 'while constructing a mapping', node.start_mark, + 'found unacceptable key (%s)' % exc, key_node.start_mark) + value = self.construct_object(value_node, deep=False) + mapping[key] = value + data.update(mapping) + + +class IndentedEmitter(yaml.emitter.Emitter): + def expect_block_sequence(self): + self.increase_indent(flow=False, indentless=False) + self.state = self.expect_first_block_sequence_item + + +class IndentedDumper(IndentedEmitter, yaml.serializer.Serializer, + yaml.representer.Representer, yaml.resolver.Resolver): + def __init__(self, stream, + default_style=None, default_flow_style=None, + canonical=None, indent=None, width=None, + allow_unicode=None, line_break=None, + encoding=None, explicit_start=None, explicit_end=None, + version=None, tags=None): + IndentedEmitter.__init__( + self, stream, canonical=canonical, + indent=indent, width=width, + allow_unicode=allow_unicode, + line_break=line_break) + yaml.serializer.Serializer.__init__( + self, encoding=encoding, + explicit_start=explicit_start, + explicit_end=explicit_end, + version=version, tags=tags) + yaml.representer.Representer.__init__( + self, default_style=default_style, + default_flow_style=default_flow_style) + yaml.resolver.Resolver.__init__(self) + + +def main(): + yaml.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, + construct_yaml_map) + + yaml.add_representer(OrderedDict, project_representer, + Dumper=IndentedDumper) + + data = yaml.load(open('gerrit/projects.yaml')) + + with open('gerrit/projects.yaml', 'w') as out: + out.write(yaml.dump(data, default_flow_style=False, + Dumper=IndentedDumper, width=800)) + +if __name__ == '__main__': + main()