Return a list, divided into one-string-per-bolt-section, with whitespace collapsed into single spaces.
(boltdir: str, num: int)
| 126 | |
| 127 | |
| 128 | def load_bolt(boltdir: str, num: int) -> List[str]: |
| 129 | """Return a list, divided into one-string-per-bolt-section, with |
| 130 | whitespace collapsed into single spaces. |
| 131 | |
| 132 | """ |
| 133 | boltfile = glob.glob("{}/{}-*md".format(boltdir, str(num).zfill(2))) |
| 134 | if len(boltfile) == 0: |
| 135 | print("Cannot find bolt {} in {}".format(num, boltdir), file=sys.stderr) |
| 136 | sys.exit(1) |
| 137 | elif len(boltfile) > 1: |
| 138 | print( |
| 139 | "More than one bolt {} in {}? {}".format(num, boltdir, boltfile), |
| 140 | file=sys.stderr, |
| 141 | ) |
| 142 | sys.exit(1) |
| 143 | |
| 144 | # We divide it into sections, and collapse whitespace. |
| 145 | boltsections = [] |
| 146 | with open(boltfile[0]) as f: |
| 147 | sect = "" |
| 148 | for line in f.readlines(): |
| 149 | if line.startswith("#"): |
| 150 | # Append with whitespace collapsed. |
| 151 | boltsections.append(collapse_whitespace(sect)) |
| 152 | sect = "" |
| 153 | sect += line |
| 154 | boltsections.append(collapse_whitespace(sect)) |
| 155 | |
| 156 | return boltsections |
| 157 | |
| 158 | |
| 159 | def find_quote( |
no test coverage detected