-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.py
94 lines (70 loc) · 2.87 KB
/
build.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import argparse
import sys
from builder import handler
class HelpFormatter(argparse.ArgumentDefaultsHelpFormatter):
def __init__(self, prog, indent_increment=1, max_help_position=48, width=256):
super(HelpFormatter, self).__init__(prog,
indent_increment=indent_increment,
max_help_position=max_help_position,
width=width)
def get_parser():
parser = argparse.ArgumentParser(
description="m2y building tool",
prog="build.py",
usage='%(prog)s [-h, --help]',
formatter_class=argparse.HelpFormatter,
)
subparser = parser.add_subparsers()
set_clean_argument(subparser)
set_build_argument(subparser)
set_check_argument(subparser)
set_test_argument(subparser)
return parser
def set_build_argument(subparser):
sp = subparser.add_parser("build", help="build m2y", formatter_class=HelpFormatter)
sp.add_argument("--skip-check", action="store_true", default=False, help="build without checking code")
sp.add_argument("--skip-test", action="store_true", default=False, help="build without running unit test")
sp.add_argument("--format-goimports", action="store_true", default=False, help="format go imports")
sp.add_argument("-c", "--clean", action="store_true", default=False, help="clean before building")
sp.add_argument("-f",
"--force",
action="store_true",
default=False,
help="clean before building, then build without checking code and running unit test")
sp.set_defaults(func=build)
def set_clean_argument(subparser):
sp = subparser.add_parser("clean", help="clean omeb", formatter_class=HelpFormatter)
sp.set_defaults(func=clean)
def set_check_argument(subparser):
sp = subparser.add_parser("check", help="check code", formatter_class=HelpFormatter)
sp.add_argument("--format-goimports", action="store_true", default=False, help="format go imports")
sp.set_defaults(func=check)
def set_test_argument(subparser):
sp = subparser.add_parser("test", help="run unit test", formatter_class=HelpFormatter)
sp.set_defaults(func=test)
def build(args):
if not handler.build(args):
return 1
return 0
def clean(args):
if not handler.clean(args):
return 1
return 0
def check(args):
if not handler.check(args):
print('Check code failed, please check "code_check.txt" for reason.')
return 1
return 0
def test(args):
if not handler.test(args):
return 1
return 0
if __name__ == "__main__":
parser = get_parser()
args = parser.parse_args()
if hasattr(args, 'func') and args.func is not None:
sys.exit(args.func(args))
parser.print_usage()
sys.exit(0)