diff --git a/goal_tools/sponsors.py b/goal_tools/sponsors.py new file mode 100644 index 0000000..edf6935 --- /dev/null +++ b/goal_tools/sponsors.py @@ -0,0 +1,47 @@ +# 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 functools +import itertools +import logging +import pkgutil + +import yaml + +LOG = logging.getLogger(__name__) + +_SPONSOR_DATA = yaml.load( + pkgutil.get_data('goal_tools', + 'sponsors.yaml').decode('utf-8') +) + + +class Sponsors: + + def __init__(self, level, data=_SPONSOR_DATA): + self._data = data + if level == 'all': + self._names = set( + n.lower() + for n in itertools.chain(*data.values()) + ) + else: + self._names = set( + n.lower() + for n in data[level] + ) + + @functools.lru_cache(maxsize=1024) + def __getitem__(self, name): + if name.lower() in self._names: + return name + return '*other' diff --git a/goal_tools/sponsors.yaml b/goal_tools/sponsors.yaml new file mode 100644 index 0000000..f3bdf8a --- /dev/null +++ b/goal_tools/sponsors.yaml @@ -0,0 +1,30 @@ +platinum: + - 'AT&T' + - Ericsson + - Huawei + - Intel + - Rackspace + - Red Hat + - SUSE + - Tencent +gold: + - 99Cloud + - Canonical + - 'China Mobile' + - 'China Telecom' + - 'China Unicorn' + - Cisco + - 'City Network' + - 'Dell EMC' + - 'Deutsche Telekom' + - EasyStack + - FiberHome + - Fujitsu + - Inspur + - inwinSTACK + - Mirantis + - NEC + - NetApp + - H3C + - UnitedStack + - 'ZTE Corporation' diff --git a/goal_tools/tests/test_sponsors.py b/goal_tools/tests/test_sponsors.py new file mode 100644 index 0000000..5b3d696 --- /dev/null +++ b/goal_tools/tests/test_sponsors.py @@ -0,0 +1,47 @@ +# 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. + +from goal_tools import sponsors +from goal_tools.tests import base + + +class TestOrganizations(base.TestCase): + + _data = { + 'platinum': ['Org1', 'Org2'], + 'gold': ['Org3'], + } + + def setUp(self): + super().setUp() + self.all = sponsors.Sponsors( + 'all', + self._data, + ) + self.platinum = sponsors.Sponsors( + 'platinum', + self._data, + ) + self.gold = sponsors.Sponsors( + 'gold', + self._data, + ) + + def test_known_org(self): + self.assertEqual('Org1', self.all['Org1']) + self.assertEqual('Org2', self.platinum['Org2']) + self.assertEqual('Org3', self.gold['Org3']) + + def test_unknown_org(self): + self.assertEqual('*other', self.all['Org4']) + self.assertEqual('*other', self.platinum['Org4']) + self.assertEqual('*other', self.gold['Org4']) diff --git a/goal_tools/who_helped/report.py b/goal_tools/who_helped/report.py index dd55dc6..7f51105 100644 --- a/goal_tools/who_helped/report.py +++ b/goal_tools/who_helped/report.py @@ -15,6 +15,8 @@ import logging from cliff import lister +from goal_tools import sponsors + LOG = logging.getLogger(__name__) @@ -29,6 +31,19 @@ class ContributionsReportBase(lister.Lister): action='append', help='filter to only include specific roles (may be repeated)', ) + parser.add_argument( + '--highlight-sponsors', + default=False, + action='store_true', + help=('highlight sponsor organizations and ' + 'combine stats for others'), + ) + parser.add_argument( + '--sponsor-level', + default='all', + choices=('all', 'platinum', 'gold'), + help='limit sponsor highlights to a subset of sponsors', + ) parser.add_argument( 'contribution_list', nargs='+', @@ -51,4 +66,13 @@ class ContributionsReportBase(lister.Lister): if roles: data = (d for d in data if d['Role'] in roles) + if parsed_args.highlight_sponsors: + sponsor_map = sponsors.Sponsors(parsed_args.sponsor_level) + + def filter_sponsors(row): + row['Organization'] = sponsor_map[row['Organization']] + return row + + data = (filter_sponsors(d) for d in data) + return data diff --git a/tools/run_contributor_report.sh b/tools/run_contributor_report.sh index 42088c4..6151fa8 100755 --- a/tools/run_contributor_report.sh +++ b/tools/run_contributor_report.sh @@ -14,6 +14,7 @@ do who-helped --debug contributions list -f csv $txt_file | tee $csv_file who-helped --debug contributions summarize $csv_file | tee $rpt_file who-helped contributions summarize -f csv $csv_file | tee $rpt_file.contributions.csv + who-helped contributions summarize -f csv --highlight-sponsors $csv_file | tee $rpt_file.sponsor-contributions.csv who-helped contributions summarize -f csv --anon $csv_file | tee $rpt_file.anon-contributions.csv who-helped contributions distinct -f csv $csv_file | tee $rpt_file.organizations.csv who-helped contributions summarize -f csv --count Name $csv_file | tee $rpt_file.people.csv