*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects
Commit 5472dc2c authored by Moser, Maximilian's avatar Moser, Maximilian
Browse files

Add pickle as an output file format for formatscaper

* also set it as default, because it's much faster and smaller than yaml
parent d0ffae4c
No related branches found
No related tags found
1 merge request!11Add pickle as an output file format for formatscaper
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import argparse import argparse
import dataclasses import dataclasses
import pickle
import re import re
import subprocess import subprocess
import sys import sys
...@@ -43,8 +44,15 @@ parser.add_argument( ...@@ -43,8 +44,15 @@ parser.add_argument(
parser.add_argument( parser.add_argument(
"--output", "--output",
"-o", "-o",
default="results.yml", default="results.{FORMAT}",
help="file in which to store the identified format for each file (default: results.yml)", # noqa help="file in which to store the identified format for each file (default: results.{FORMAT})", # noqa
)
parser.add_argument(
"--output-format",
"-F",
default="pickle",
choices=["pickle", "yaml"],
help="format of the results (default: pickle)",
) )
parser.add_argument( parser.add_argument(
"--parallel", "--parallel",
...@@ -215,12 +223,21 @@ if endangered_files: ...@@ -215,12 +223,21 @@ if endangered_files:
# store the results to files # store the results to files
output_file_name = args.output.format(FORMAT=args.output_format)
try: try:
with open(args.output, "w") as output_file: simple_results = [dataclasses.asdict(res) for res in all_results]
yaml.dump([dataclasses.asdict(res) for res in all_results], output_file) file_mode = "w" if args.output_format == "yaml" else "wb"
with open(output_file_name, file_mode) as output_file:
if args.output_format == "yaml":
yaml.dump(simple_results, output_file)
elif args.output_format == "pickle":
pickle.dump(simple_results, output_file)
except OSError: except OSError:
print(f"WARN: couldn't store the results ({args.output})", file=sys.stderr) print(
f"WARN: couldn't store the results to file ({output_file_name})",
file=sys.stderr,
)
try: try:
updated_formats = [dataclasses.asdict(f) for f in formats.values()] updated_formats = [dataclasses.asdict(f) for f in formats.values()]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment