From c53b73228f08ae39344aece2fffc5267caefe4ef Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Tue, 6 Dec 2016 06:27:10 -0800 Subject: [PATCH] Update the metadata tool (#18765) * Latest spreadsheet version uses different fields for support. * Format the metadata to be a little nicer (multiple lines) --- hacking/metadata-tool.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/hacking/metadata-tool.py b/hacking/metadata-tool.py index 42409cfec69..623ec68b1a4 100755 --- a/hacking/metadata-tool.py +++ b/hacking/metadata-tool.py @@ -5,7 +5,7 @@ import csv import os import sys from distutils.version import StrictVersion -from pprint import pprint +from pprint import pformat, pprint import yaml @@ -267,9 +267,18 @@ def remove_metadata(module_data, start_line, start_col, end_line, end_col): def insert_metadata(module_data, new_metadata, insertion_line, targets=('ANSIBLE_METADATA',)): """Insert a new set of metadata at a specified line""" - new_line = '{} = {}'.format(' = '.join(targets), new_metadata) - lines = module_data.split('\n') - lines.insert(insertion_line, new_line) + assignments = ' = '.join(targets) + pretty_metadata = pformat(new_metadata, width=1).split('\n') + + new_lines = [] + new_lines.append('{} = {}'.format(assignments, pretty_metadata[0])) + + if len(pretty_metadata) > 1: + for line in pretty_metadata[1:]: + new_lines.append('{}{}'.format(' ' * (len(assignments) - 1 + len(' = {')), line)) + + old_lines = module_data.split('\n') + lines = old_lines[:insertion_line] + new_lines + [''] + old_lines[insertion_line:] return '\n'.join(lines) @@ -293,15 +302,15 @@ def parse_assigned_metadata_initial(csvfile): for record in csv.reader(f): module = record[0] - if record[11] == 'core': + if record[12] == 'core': supported_by = 'core' - elif record[11] == 'curated': + elif record[12] == 'curated': supported_by = 'committer' - elif record[11] == 'community': + elif record[12] == 'community': supported_by = 'community' else: - raise Exception('Module record has no supported_by field: %s' % record) - #supported_by = 'community' + print('Module %s has no supported_by field. Using community' % record[0]) + supported_by = 'community' status = [] if record[6]: