-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpain.py
executable file
·66 lines (53 loc) · 2.26 KB
/
pain.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/python3
import argparse
import subprocess
def run_in_shell(cmd):
results = subprocess.run(cmd, shell=True, universal_newlines=True, check=True)
if results.stdout:
print(results.stdout)
if results.stderr:
print(results.stderr)
if results.returncode != 0:
raise Exception("Failed to run command: {}".format(cmd))
def config_project(args):
if args.clean:
run_in_shell('xmake f -c')
return
run_in_shell('xmake f -cv --mode={}'.format(args.mode))
def build_project(args):
cmd = ['xmake', 'b', '-v'] + args.rest
run_in_shell(' '.join(cmd))
if args.install:
run_in_shell('xmake install -o output')
pass
def format_project(args):
run_in_shell('xmake format -f "src/**.h:src/**.cc:protocols/**.proto:include/**.h"')
def line_project(args):
run_in_shell('find include src -iname "*.h" -o -iname "*.cc" | xargs wc -l')
def install_project(args):
if not args.rest:
run_in_shell('xmake install -o output')
return
for target in args.rest:
run_in_shell('xmake install -o output {}'.format(target))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Description of your program')
parser.add_argument('-g', '--global')
subparsers = parser.add_subparsers(dest="subparser_name", required=True)
format_parser = subparsers.add_parser('format', aliases=['f'])
format_parser.set_defaults(func=format_project)
config_parser = subparsers.add_parser('config')
config_parser.set_defaults(func=config_project)
config_parser.add_argument('-c', '--clean', action='store_true')
config_parser.add_argument('-m', '--mode', default='debug', choices=['debug', 'releasedbg'])
build_parser = subparsers.add_parser('build', aliases=['b'])
build_parser.set_defaults(func=build_project)
build_parser.add_argument('-i', '--install', action='store_true')
build_parser.add_argument('rest', nargs=argparse.REMAINDER)
line_parser = subparsers.add_parser('line')
line_parser.set_defaults(func=line_project)
install_parser = subparsers.add_parser('install')
install_parser.set_defaults(func=install_project)
install_parser.add_argument('rest', nargs=argparse.REMAINDER)
args = parser.parse_args()
args.func(args)