Post-processes a single write operation, as intercepted during codegen.
(parts, data: str)
| 256 | |
| 257 | |
| 258 | def postprocess_write(parts, data: str) -> str: |
| 259 | """ |
| 260 | Post-processes a single write operation, as intercepted during codegen. |
| 261 | """ |
| 262 | # test whether filename starts with 'libopenage/' |
| 263 | if parts[0] != b"libopenage": |
| 264 | raise ValueError("Not in libopenage source directory") |
| 265 | |
| 266 | # test whether filename matches the pattern *.gen.* |
| 267 | name, extension = os.path.splitext(parts[-1].decode()) |
| 268 | if not name.endswith('.gen'): |
| 269 | raise ValueError("Doesn't match required filename format .gen.SUFFIX") |
| 270 | |
| 271 | # check file extension, and use the appropriate comment prefix |
| 272 | if extension in {'.h', '.cpp'}: |
| 273 | comment_prefix = '//' |
| 274 | else: |
| 275 | raise ValueError("Extension not in {.h, .cpp}") |
| 276 | |
| 277 | datalines = data.decode('ascii').split('\n') |
| 278 | if 'Copyright' in datalines[0]: |
| 279 | datalines = datalines[1:] |
| 280 | |
| 281 | headerlines = [] |
| 282 | for line in get_header_lines(): |
| 283 | if line: |
| 284 | headerlines.append(comment_prefix + " " + line) |
| 285 | else: |
| 286 | headerlines.append("") |
| 287 | |
| 288 | return '\n'.join(chain(headerlines, datalines)).encode('ascii') |
no test coverage detected