Skip to content

Commit 8635333

Browse files
committed
Retrieve title of the draft. See ietf-tools#588
- Legacy-Id: 2826
1 parent ea57dcb commit 8635333

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

ietf/utils/draft.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def __init__(self, text):
127127
self._pagecount = None
128128
self._status = None
129129
self._creation_date = None
130+
self._title = None
130131

131132
# ------------------------------------------------------------------
132133
def _parse_draftname(self):
@@ -502,6 +503,28 @@ def get_authors(self):
502503

503504
return self._authors
504505

506+
# ------------------------------------------------------------------
507+
def get_title(self):
508+
if self._title:
509+
return self._title
510+
title_re = re.compile('(.+\n){1,3}(\s+<?draft-\S+\s*\n)')
511+
match = title_re.search(self.pages[0])
512+
if match:
513+
title = match.group(1)
514+
title = title.strip()
515+
self._title = title
516+
return self._title
517+
# unusual title extract
518+
unusual_title_re = re.compile('(.+\n|.+\n.+\n)(\s*status of this memo\s*\n)', re.I)
519+
match = unusual_title_re.search(self.pages[0])
520+
if match:
521+
title = match.group(1)
522+
title = title.strip()
523+
self._title = title
524+
return self._title
525+
self.errors["title"] = "Could not find the title on the first page."
526+
527+
505528
# ----------------------------------------------------------------------
506529
def _output(fields):
507530
if opt_timestamp:
@@ -546,6 +569,7 @@ def _printmeta(timestamp, fn):
546569
fields["doctag"] = draft.filename or fn[:-7]
547570
fields["docrev"] = draft.revision
548571

572+
fields["doctitle"] = draft.get_title()
549573
fields["docpages"] = str(draft.get_pagecount())
550574
fields["docauthors"] = ", ".join(draft.get_authors())
551575
deststatus = draft.get_status()

0 commit comments

Comments
 (0)