remove dependency on sphinx app from members parsing code

Use the logging module to report warnings instead of requiring a
Sphinx Application instance as argument.

Change-Id: I9fcb635099e116905057c4a15465cf3280763937
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann
2018-10-08 19:17:45 -04:00
parent 6e7253899c
commit d387f3f8f6
2 changed files with 6 additions and 4 deletions

View File

@@ -43,7 +43,6 @@ class MembersTable(tables.Table):
def run(self): def run(self):
env = self.state.document.settings.env env = self.state.document.settings.env
app = env.app
# The required argument to the directive is the name of the # The required argument to the directive is the name of the
# file to parse. # file to parse.
@@ -73,7 +72,7 @@ class MembersTable(tables.Table):
rel_filename, filename = env.relfn2path(datafile) rel_filename, filename = env.relfn2path(datafile)
# Build the table node using the parsed file # Build the table node using the parsed file
data_iter = members.parse_members_file(app, filename) data_iter = members.parse_members_file(filename)
table_node = self.build_table( table_node = self.build_table(
data_iter, data_iter,
col_widths, col_widths,

View File

@@ -10,13 +10,16 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
import re import re
LOG = logging.getLogger(__name__)
# Full name (IRC) <E-mail> [expires in] {role} # Full name (IRC) <E-mail> [expires in] {role}
_PATTERN = re.compile('(?P<name>.*)\s+\((?P<irc>.*)\)\s+\<(?P<email>.*)\>\s+\[(?P<date>.*)\](\s+\{(?P<role>.*)\})?') _PATTERN = re.compile('(?P<name>.*)\s+\((?P<irc>.*)\)\s+\<(?P<email>.*)\>\s+\[(?P<date>.*)\](\s+\{(?P<role>.*)\})?')
def parse_members_file(app, filename): def parse_members_file(filename):
"""Load the members file and return each row as a dictionary. """Load the members file and return each row as a dictionary.
""" """
with open(filename, 'r') as f: with open(filename, 'r') as f:
@@ -26,7 +29,7 @@ def parse_members_file(app, filename):
continue continue
m = _PATTERN.match(line) m = _PATTERN.match(line)
if not m: if not m:
app.warning('Could not parse line %d of %s: %r' % LOG.warning('Could not parse line %d of %s: %r' %
(linum, filename, line)) (linum, filename, line))
continue continue
yield m.groupdict() yield m.groupdict()