PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/test-gen-goldens.py

https://code.google.com/p/latex-makefile/
Python | 43 lines | 33 code | 7 blank | 3 comment | 11 complexity | a7e419331ab2d281df7b69279610cc9d MD5 | raw file
 1#!/usr/bin/env python
 2
 3"""Generate golden files for log.* in a test directory."""
 4
 5import os
 6import os.path
 7import subprocess
 8import sys
 9import util.ensure_version
10
11log_sed_scripts = ("color-tex.sed",
12                   "colorize-latex-errors.sed",
13                   "get-graphics.sed",
14                   "get-log-index.sed",
15                   "get-missing-inputs.sed")
16
17if len(sys.argv) == 2:
18  initial_dir = os.path.join("test", sys.argv[1])
19else:
20  initial_dir = "test"
21
22for dirpath, dirnames, filenames in os.walk(initial_dir):
23  for in_name in filenames:
24    if not in_name.startswith("log."):
25      continue
26
27    print("Generating golden files for {0}".format(in_name))
28
29    for scriptname in log_sed_scripts:
30      # remove the .sed extension if there is one
31      if scriptname.endswith(".sed"):
32        scriptname = scriptname[:-4]
33      out_name = "golden.run_sed__{script}__{log}".format(script=scriptname,
34                                                          log=in_name)
35      out_path = os.path.join(dirpath, out_name)
36      in_path = os.path.join(dirpath, in_name)
37      with open(out_path, "wb") as f:
38        args=("./run_sed", "{0}.sed".format(scriptname), in_path)
39        print(args, out_path)
40        ret = subprocess.call(args, stdout=f)
41      if ret != 0:
42        print("FAILED: removing {0}".format(out_path))
43        os.unlink(out_path)