This repository has been archived by the owner on Jun 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaptools.py
executable file
·95 lines (77 loc) · 3.22 KB
/
maptools.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
95
#!/usr/bin/env python
import logging
import logging.config
import argparse
import os
import sys
from commands.config import mapcfg
from commands.build import mapbuild
from commands.package import mappackage
from commands.deploy import mapdeploy, mapcopy
THIS_SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))
logging.config.fileConfig(os.path.abspath(THIS_SCRIPT_PATH + "/logging.conf"))
def print_color(string, color):
colors = {'red':'31', 'yellow':'33', 'blue':'34', 'magenta':'35', 'turquoise':'36', 'white':'37'}
attr = []
attr.append(colors[color])
attr.append('1')
print('\x1b[%sm%s\x1b[0m' % (';'.join(attr), string))
def ASSERT(string):
print_color('ASSERT: %s' %(string), 'red')
def WARNING(string):
print_color('%s' %(string), 'yellow')
class maptools(object):
default_multiap_root = os.path.abspath(os.path.dirname(__file__)+'/../') #one dir above the tools repo
def __init__(self):
self.logger = logging.getLogger("maptools")
self.parent_parser = argparse.ArgumentParser(description="MultiAP Tools")
self.parent_parser.add_argument("--map-path", "-m", default=maptools.default_multiap_root, help="path to multiap sources tree")
self.parent_parser.add_argument("--verbose", "-v", action="store_true", help="verbosity on")
self.parent_parser.add_argument("--user", "-u", type=str, help="use custom username when connecting to jira")
self.child_parser = self.parent_parser.add_subparsers(title="subcommand", help="subcommand help", dest="cmd")
self.config_command = self.child_parser.add_parser('config')
self.build_command = self.child_parser.add_parser('build')
self.package_command = self.child_parser.add_parser('package')
self.deploy_command = self.child_parser.add_parser('deploy')
self.copy_command = self.child_parser.add_parser('copy')
mapcfg.configure_parser(self.config_command)
mapbuild.configure_parser(self.build_command)
mappackage.configure_parser(self.package_command)
mapdeploy.configure_parser(self.deploy_command)
mapcopy.configure_parser(self.copy_command)
self.args = self.parent_parser.parse_args()
if self.args.verbose: self.logger.setLevel(logging.DEBUG)
def __str__(self):
return str(self.args)
def __config__(self):
mapcfg(self.args)
def __build__(self):
mapbuild(self.args)
def __package__(self):
mappackage(self.args)
def __deploy__(self):
mapdeploy(self.args)
def __copy__(self):
mapcopy(self.args)
def run(self):
commands = {
'config': self.__config__,
'build': self.__build__,
'package': self.__package__,
'deploy': self.__deploy__,
'copy': self.__copy__
}
try:
self.logger.debug(self.args.cmd)
commands[self.args.cmd]()
except KeyError as err:
if not self.args.cmd:
self.parent_parser.print_help()
sys.exit(0)
raise Exception("Operation not supported ({}, err={})".format(self.args.cmd, err))
if __name__ == '__main__':
try:
maptools().run()
except Exception as e:
ASSERT(e)
raise