From 6e7253899c31c03fe109c6fa8dfdb99245b47461 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Mon, 8 Oct 2018 19:15:14 -0400 Subject: [PATCH] move members file parsing into a reusable module Set up openstack_governance as a package for reusable code and move the members parsing function there. Change-Id: Ic8845296d9fe8ee7822f2543d83a18000e96b6ff Signed-off-by: Doug Hellmann --- doc/source/_exts/members.py | 23 ++--------------------- openstack_governance/__init__.py | 0 openstack_governance/members.py | 32 ++++++++++++++++++++++++++++++++ setup.cfg | 4 ++++ 4 files changed, 38 insertions(+), 21 deletions(-) create mode 100644 openstack_governance/__init__.py create mode 100644 openstack_governance/members.py diff --git a/doc/source/_exts/members.py b/doc/source/_exts/members.py index e0bd18ddb..c6b134871 100644 --- a/doc/source/_exts/members.py +++ b/doc/source/_exts/members.py @@ -13,31 +13,12 @@ """Build a table of the current members of the TC. """ -import re - from docutils import nodes from docutils.parsers.rst import directives from docutils.parsers.rst.directives import tables from docutils.utils import SystemMessagePropagation -# Full name (IRC) [expires in] {role} -_PATTERN = re.compile('(?P.*)\s+\((?P.*)\)\s+\<(?P.*)\>\s+\[(?P.*)\](\s+\{(?P.*)\})?') - - -def _parse_members_file(app, filename): - """Load the members file and return each row as a dictionary. - """ - with open(filename, 'r') as f: - for linum, line in enumerate(f, 1): - line = line.strip() - if not line or line.startswith('#'): - continue - m = _PATTERN.match(line) - if not m: - app.warning('Could not parse line %d of %s: %r' % - (linum, filename, line)) - continue - yield m.groupdict() +from openstack_governance import members class MembersTable(tables.Table): @@ -92,7 +73,7 @@ class MembersTable(tables.Table): rel_filename, filename = env.relfn2path(datafile) # Build the table node using the parsed file - data_iter = _parse_members_file(app, filename) + data_iter = members.parse_members_file(app, filename) table_node = self.build_table( data_iter, col_widths, diff --git a/openstack_governance/__init__.py b/openstack_governance/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/openstack_governance/members.py b/openstack_governance/members.py new file mode 100644 index 000000000..c1aa66430 --- /dev/null +++ b/openstack_governance/members.py @@ -0,0 +1,32 @@ +# 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 re + +# Full name (IRC) [expires in] {role} +_PATTERN = re.compile('(?P.*)\s+\((?P.*)\)\s+\<(?P.*)\>\s+\[(?P.*)\](\s+\{(?P.*)\})?') + + +def parse_members_file(app, filename): + """Load the members file and return each row as a dictionary. + """ + with open(filename, 'r') as f: + for linum, line in enumerate(f, 1): + line = line.strip() + if not line or line.startswith('#'): + continue + m = _PATTERN.match(line) + if not m: + app.warning('Could not parse line %d of %s: %r' % + (linum, filename, line)) + continue + yield m.groupdict() diff --git a/setup.cfg b/setup.cfg index d4b9277ae..e7a78b9f3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,6 +8,10 @@ author = OpenStack TC author-email = openstack-tc@lists.openstack.org home-page = http://www.openstack.org/ +[files] +packages = + openstack_governance + [build_sphinx] all_files = 1 build-dir = doc/build