File: list-horizon-plugins.py

package info (click to toggle)
horizon 3%3A18.6.2-5%2Bdeb11u2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 29,444 kB
  • sloc: python: 93,101; javascript: 47,025; sh: 421; makefile: 78
file content (100 lines) | stat: -rwxr-xr-x 3,267 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
#    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 argparse
import csv
import glob
import os

import yaml


# The script picks up deliverables whose type is 'horizon-plugin' in the
# openstack/releases repository. Some horizon plugins are released together
# with other repositories and we cannot pick them up for such case.
# EXTRA_PLUGINS is used to declare such horizon plugins.
# Each entry is a tuple of
# - the deliverable name in the releases repo, and
# - the repository name of the dashboard.
EXTRA_PLUGINS = {
    'networking-bgpvpn': 'networking-bgpvpn',
}


def read_plugin_data_from_releases(releases_repo, release):
    plugins = {}
    deliverables_glob = '%s/deliverables/%s/*.yaml' % (releases_repo, release)
    for deliverable in glob.glob(deliverables_glob):
        with open(deliverable) as f:
            data = yaml.safe_load(f)

        name = os.path.splitext(os.path.basename(deliverable))[0]
        if data['type'] == 'horizon-plugin':
            pass
        elif name in EXTRA_PLUGINS:
            name = EXTRA_PLUGINS[name]
        else:
            continue

        repos = [repo for repo in data['repository-settings']
                 if os.path.basename(repo) == name]
        if not repos:
            repos = list(data['repository-settings'].keys())[0]
        data['repository'] = repos[0]
        plugins[name] = data
    return plugins


def get_plugin_info(name, config):
    repo = ':opendev-repo:`%s`' % config['repository']
    if 'storyboard' in config:
        bug_tracker = ':storyboard:`%s`' % config['storyboard']
    elif 'launchpad' in config:
        bug_tracker = ':launchpad:`%s`' % config['launchpad']
    else:
        bug_tracker = None
    return [name, repo, bug_tracker]


def write_csv(plugins, csv_file):
    with open(csv_file, 'w', newline='') as csvfile:
        csvwriter = csv.writer(csvfile, lineterminator='\n',
                               quoting=csv.QUOTE_MINIMAL)
        csvwriter.writerow(['Plugin', 'Repository', 'Bug Tracker'])
        for name in sorted(plugins):
            csvwriter.writerow(get_plugin_info(name, plugins[name]))


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--csv-file',
        default='plugin-registry.csv',
        help='Path to a CSV file which contains the plugin list.'
    )
    parser.add_argument(
        'repo',
        help='Path to openstack/releases repository cloned to local.'
    )
    parser.add_argument(
        'release',
        help='Release name like "ussuri'
    )
    args = parser.parse_args()
    plugins = read_plugin_data_from_releases(args.repo, args.release)

    write_csv(plugins, args.csv_file)


if __name__ == '__main__':
    main()