Skip to content

Commit

Permalink
Add support for extracting RFCs from XML.
Browse files Browse the repository at this point in the history
Fallback to .txt if the XML file cannot be found.
  • Loading branch information
jclarke-csco committed Nov 8, 2024
1 parent 976b80a commit eea0ad8
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions extractors/rfc_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,21 @@ def __init__(self, rfc_extractor_paths: RFCExtractorPaths, debug_level: int):
self.__create_ietf_rfcs_list()

def __create_ietf_rfcs_list(self):
self.ietf_rfcs = [
f
for f in os.listdir(self.rfc_extractor_paths.rfc_path)
if os.path.isfile(os.path.join(self.rfc_extractor_paths.rfc_path, f))
]
for f in os.listdir(self.rfc_extractor_paths.rfc_path):
if not f.endswith(".txt"):
continue

(base, _) = os.path.splitext(f)
full_path = os.path.join(self.rfc_extractor_paths.rfc_path, f)
fname = f
xml_file = os.path.join(self.rfc_extractor_paths.rfc_path, base + ".xml")
if os.path.isfile(xml_file):
full_path = xml_file
fname = base + ".xml"

if os.path.isfile(full_path):
self.ietf_rfcs.append(fname)

self.ietf_rfcs.sort()
print('IETF RFCs list created')

Expand Down Expand Up @@ -95,6 +105,7 @@ def extract_from_rfc_file(self, rfc_file: str) -> list[str]:
force_revision_pyang=False,
force_revision_regexp=True,
extract_code_snippets=True,
rfcxml=(rfc_file.endswith(".xml")),
code_snippets_dir=os.path.join(self.code_snippets_directory, os.path.splitext(rfc_file)[0]),
)

Expand Down

0 comments on commit eea0ad8

Please sign in to comment.