Advertisement
Toumo

auto_code_runner.py

Apr 6th, 2023 (edited)
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. # Runs the last-modified script (if its format is a runner_map key) found in search_dir.
  2.  
  3. import os
  4. import subprocess
  5.  
  6. search_dir = "/home/tomo/Documents"
  7. runner_map = {"py": lambda path: os.system(f"time python -u '{path}'"),
  8.               "hs": lambda path: os.system(f"time runghc '{path}'"),}
  9.  
  10. fmt_regex = r".*\.\(" +  r"\|".join(runner_map.keys()) + r"\)"
  11. find_cmd = ["find", search_dir, "-regex", fmt_regex]
  12. path_list = subprocess.run(find_cmd, stdout=subprocess.PIPE).stdout.decode('utf-8').split("\n")[:-1]
  13. path, fmt = sorted([(os.path.getmtime(path), path, path.split(".")[-1]) for path in path_list])[-1][1:]
  14.  
  15. if path != os.path.abspath(__file__): runner_map[fmt](path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement