-
Notifications
You must be signed in to change notification settings - Fork 1
/
regiater_cmd.py
executable file
·38 lines (33 loc) · 1.31 KB
/
regiater_cmd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import sys
import argparse
if __name__ == '__main__':
# 登録するコマンド名を受け取るパーサーの作成
parser = argparse.ArgumentParser()
# 引数がなければatjudgeにする
parser.add_argument('command_name', help='commmand name to register', type=str, nargs='*', default='atjudge')
args = parser.parse_args()
targetfilepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'run.sh')
# OSの判定
if os.name == 'nt':
cmd = [targetfilepath, 'C:/commands/' + args.command_name]
# cmd = ['mklink', + args.command_name, targetfilepath]
elif os.name == 'posix':
cmd = [targetfilepath, '/usr/local/bin/' + args.command_name]
else:
print('This OS is not supported\nPlease create a symbolic link or register an alias manually\n')
print('ファイルパス:')
print(targetfilepath)
sys.exit()
print('unlink path:' + ' '.join(cmd))
try:
os.symlink(*cmd)
except FileExistsError as e:
print(e)
except OSError:
print('Permission denied\nPlease run it again with administrative privileges')
except Exception as e:
print(e)
else:
print('The command was successfully registered.')
print('We can run with "{}"'.format(args.command_name))