-
-
Save Ishotihadus/feb1c7e89824e92ace52c7c116a2e506 to your computer and use it in GitHub Desktop.
qsub をラクにするやつ qq -P group run.sh arg1 arg2 ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import os | |
import shlex | |
import subprocess | |
import sys | |
from datetime import datetime | |
from pathlib import Path | |
options = [] | |
command = None | |
ignore_options = False | |
for arg in sys.argv[1:]: | |
if command: | |
command.append(arg) | |
elif ignore_options: | |
command = [arg] | |
else: | |
if options and len(options[-1]) == 1: | |
options[-1].append(arg) | |
elif arg == "--": | |
ignore_options = True | |
elif arg.startswith("-"): | |
if arg in ["-f", "-h", "-I", "-X", "-V", "-z"]: | |
options.append([arg, None]) | |
else: | |
options.append([arg]) | |
else: | |
command = [arg] | |
if not command: | |
sys.stderr.write("qq: command not specified\n") | |
sys.exit(1) | |
script_dir = Path.home() / ".cache" / "qq" | |
script_dir.mkdir(parents=True, exist_ok=True) | |
(Path.cwd() / ".qq_logs").mkdir(parents=True, exist_ok=True) | |
command_basename = os.path.basename(command[0]) | |
command_time = datetime.now().strftime("%Y%m%d-%H%M%S") | |
script_name = f"qq_{command_basename}_{command_time}.sh" | |
script_path = script_dir / script_name | |
with open(script_path, "w") as file: | |
file.write("#!/bin/sh\n\n") | |
file.write("source /etc/profile.d/modules.sh\n") | |
file.write("module load cuda\n\n") | |
file.write(shlex.join(["cd", os.getcwd()]) + "\n") | |
file.write(shlex.join(command) + "\n") | |
file.write(shlex.join(["rm", str(script_path)]) + "\n") | |
if not any(opt[0] == "-q" for opt in options): | |
options.append(["-q", "rt_HF"]) | |
if not any(opt[0] == "-l" and opt[1].startswith("select=") for opt in options): | |
options.append(["-l", "select=1"]) | |
options.append(["-k", "oed"]) | |
options.append(["-j", "oe"]) | |
options.append( | |
["-o", Path.cwd() / ".qq_logs" / f"{command_time}_{command_basename}.log"] | |
) | |
subprocess.run( | |
["qsub"] + [o for o in sum(options, []) if o is not None] + [str(script_path)] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment