in_base base directory for input files out_base base directory for output files (ignored when files list of filenames to be uncompyled (relative to in_base) outfile write output to this filename (overwrites out_base) For redirecting output to - outfile=<filename
(
in_base: str,
out_base: Optional[str],
compiled_files: list,
source_files: list,
outfile: Optional[str] = None,
showasm: Optional[str] = None,
showast={},
do_verify: Optional[str] = None,
showgrammar: bool = False,
source_encoding=None,
do_linemaps=False,
do_fragments=False,
start_offset: int = 0,
stop_offset: int = -1,
)
| 268 | |
| 269 | # FIXME: combine into an options parameter |
| 270 | def main( |
| 271 | in_base: str, |
| 272 | out_base: Optional[str], |
| 273 | compiled_files: list, |
| 274 | source_files: list, |
| 275 | outfile: Optional[str] = None, |
| 276 | showasm: Optional[str] = None, |
| 277 | showast={}, |
| 278 | do_verify: Optional[str] = None, |
| 279 | showgrammar: bool = False, |
| 280 | source_encoding=None, |
| 281 | do_linemaps=False, |
| 282 | do_fragments=False, |
| 283 | start_offset: int = 0, |
| 284 | stop_offset: int = -1, |
| 285 | ) -> Tuple[int, int, int, int]: |
| 286 | """ |
| 287 | in_base base directory for input files |
| 288 | out_base base directory for output files (ignored when |
| 289 | files list of filenames to be uncompyled (relative to in_base) |
| 290 | outfile write output to this filename (overwrites out_base) |
| 291 | |
| 292 | For redirecting output to |
| 293 | - <filename> outfile=<filename> (out_base is ignored) |
| 294 | - files below out_base out_base=... |
| 295 | - stdout out_base=None, outfile=None |
| 296 | """ |
| 297 | tot_files = okay_files = failed_files = 0 |
| 298 | verify_failed_files = 0 if do_verify else 0 |
| 299 | current_outfile = outfile |
| 300 | linemap_stream = None |
| 301 | |
| 302 | for source_path in source_files: |
| 303 | compiled_files.append(compile_file(source_path)) |
| 304 | |
| 305 | if len(compiled_files) == 0: |
| 306 | return 0, 0, 0, 0 |
| 307 | |
| 308 | for filename in compiled_files: |
| 309 | infile = osp.join(in_base, filename) |
| 310 | # print("XXX", infile) |
| 311 | if not osp.exists(infile): |
| 312 | sys.stderr.write(f"File '{infile}' doesn't exist. Skipped\n") |
| 313 | continue |
| 314 | |
| 315 | if do_linemaps: |
| 316 | linemap_stream = infile + ".pymap" |
| 317 | pass |
| 318 | |
| 319 | # print (infile, file=sys.stderr) |
| 320 | |
| 321 | if outfile: # outfile was given as parameter |
| 322 | outstream = _get_outstream(outfile) |
| 323 | elif out_base is None: |
| 324 | out_base = tempfile.mkdtemp(prefix="py-dis-") |
| 325 | if do_verify and filename.endswith(".pyc"): |
| 326 | current_outfile = osp.join(out_base, filename[0:-1]) |
| 327 | outstream = open(current_outfile, "w") |