2018-05-12 16:23:05 +02:00
|
|
|
#!/usr/bin/env python3
|
2018-09-12 20:28:42 +02:00
|
|
|
|
2018-05-12 16:23:05 +02:00
|
|
|
import itertools
|
|
|
|
|
import subprocess
|
|
|
|
|
import pathlib
|
|
|
|
|
import shutil
|
2026-04-12 12:37:43 +00:00
|
|
|
from typing import Iterable
|
2018-05-12 16:23:05 +02:00
|
|
|
|
2018-09-12 20:28:42 +02:00
|
|
|
|
2018-05-12 16:23:05 +02:00
|
|
|
def generate_snapshots():
|
2020-10-06 16:57:47 +01:00
|
|
|
single_styles = ["changes", "grid", "header", "numbers", "rule"]
|
2018-05-12 16:23:05 +02:00
|
|
|
collective_styles = ["full", "plain"]
|
|
|
|
|
|
|
|
|
|
for num in range(len(single_styles)):
|
|
|
|
|
for grouped in itertools.combinations(single_styles, num + 1):
|
2018-09-10 19:19:43 -07:00
|
|
|
generate_style_snapshot(",".join(grouped))
|
2018-05-12 16:23:05 +02:00
|
|
|
|
|
|
|
|
for style in collective_styles:
|
2018-09-10 19:19:43 -07:00
|
|
|
generate_style_snapshot(style)
|
2018-05-12 16:23:05 +02:00
|
|
|
|
2018-09-12 20:28:42 +02:00
|
|
|
|
2018-09-10 19:19:43 -07:00
|
|
|
def generate_style_snapshot(style):
|
2026-04-12 12:37:43 +00:00
|
|
|
generate_snapshot(style.replace(",", "_"), ["--style={}".format(style)])
|
2018-09-12 20:28:42 +02:00
|
|
|
|
2018-09-10 19:19:43 -07:00
|
|
|
|
2026-04-12 12:37:43 +00:00
|
|
|
def generate_snapshot(name: str, arguments: Iterable[str]):
|
2026-04-12 11:43:12 +00:00
|
|
|
output_file = "output/{name}.snapshot.txt".format(name=name)
|
|
|
|
|
command = [
|
|
|
|
|
"cargo", "run", "--", "--paging=never", "--color=never",
|
2026-04-12 12:37:43 +00:00
|
|
|
"--decorations=always", *arguments, "sample.rs"
|
2026-04-12 11:43:12 +00:00
|
|
|
]
|
2018-09-10 19:19:43 -07:00
|
|
|
print("generating snapshot for {}".format(name))
|
2026-04-12 11:43:12 +00:00
|
|
|
with open(output_file, "w") as f:
|
|
|
|
|
subprocess.call(command, stdout=f)
|
2018-05-12 16:23:05 +02:00
|
|
|
|
2018-09-12 20:28:42 +02:00
|
|
|
|
2018-05-24 12:06:02 +02:00
|
|
|
def build_bat():
|
|
|
|
|
print("building bat")
|
2026-04-12 11:43:12 +00:00
|
|
|
subprocess.call(["cargo", "build"], cwd="../..")
|
2018-05-24 12:06:02 +02:00
|
|
|
|
2018-09-12 20:28:42 +02:00
|
|
|
|
2018-05-12 16:23:05 +02:00
|
|
|
def prepare_output_dir():
|
|
|
|
|
shutil.rmtree("output", ignore_errors=True)
|
|
|
|
|
pathlib.Path("output").mkdir()
|
|
|
|
|
|
2018-09-12 20:28:42 +02:00
|
|
|
|
2018-05-12 16:23:05 +02:00
|
|
|
def modify_sample_file():
|
|
|
|
|
print("modifying sample.rs to show changes")
|
|
|
|
|
shutil.copyfile("sample.modified.rs", "sample.rs")
|
|
|
|
|
|
2018-09-12 20:28:42 +02:00
|
|
|
|
2018-05-12 16:23:05 +02:00
|
|
|
def undo_sample_file_modification():
|
|
|
|
|
print("undoing sample.rs modifications")
|
2026-04-12 11:43:12 +00:00
|
|
|
subprocess.call(["git", "checkout", "--", "sample.rs"])
|
2018-05-12 16:23:05 +02:00
|
|
|
|
2018-09-12 20:28:42 +02:00
|
|
|
|
2018-05-24 12:06:02 +02:00
|
|
|
build_bat()
|
2018-05-12 16:23:05 +02:00
|
|
|
prepare_output_dir()
|
|
|
|
|
modify_sample_file()
|
|
|
|
|
generate_snapshots()
|
|
|
|
|
undo_sample_file_modification()
|