Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Runs the last-modified script (if its format is a runner_map key) found in search_dir.
- import os
- import subprocess
- search_dir = "/home/tomo/Documents"
- runner_map = {"py": lambda path: os.system(f"time python -u '{path}'"),
- "hs": lambda path: os.system(f"time runghc '{path}'"),}
- fmt_regex = r".*\.\(" + r"\|".join(runner_map.keys()) + r"\)"
- find_cmd = ["find", search_dir, "-regex", fmt_regex]
- path_list = subprocess.run(find_cmd, stdout=subprocess.PIPE).stdout.decode('utf-8').split("\n")[:-1]
- path, fmt = sorted([(os.path.getmtime(path), path, path.split(".")[-1]) for path in path_list])[-1][1:]
- if path != os.path.abspath(__file__): runner_map[fmt](path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement