-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatcli.py
More file actions
executable file
·51 lines (41 loc) · 1.38 KB
/
atcli.py
File metadata and controls
executable file
·51 lines (41 loc) · 1.38 KB
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
#!/usr/bin/env python3
import json, os, sys
import atcli
from argparse import ArgumentParser
from apilassian import session
def get_args():
parser = ArgumentParser()
parser.add_argument('element', choices=['bamboo', 'bitbucket', 'crowd', 'jira'])
parser.add_argument('-p', '--profile', default='default')
parser.add_argument('-i', '--input')
parser.add_argument('-o', '--output')
return parser.parse_args()
def load_profile(profile):
settings = {}
filename = os.path.join(os.getenv('HOME'), '.config', 'atcli.json')
if(os.path.isfile(filename)):
with open(filename, 'r') as fn:
contents = json.load(fn)
settings.update(contents.get('profiles', dict()).get(profile, dict()))
return settings
def parse_input(inputparams):
inputs = {}
for element in inputparams.split(','):
keyvalue = element.split('=')
inputs[keyvalue[0]] = ''.join(keyvalue[1:])
return inputs
def main():
args = get_args()
settings = load_profile(args.profile)
instance_map = {
'bitbucket' : atcli.bitbucket,
#'bamboo' : atcli.bamboo,
#'jira' : atcli.jira,
#'crowd' : atcli.crowd
}
inputs = parse_input(args.input) if args.input else dict()
inputs.update(settings)
action = instance_map[args.element]
action.call(args.output)(inputs)
if __name__ == '__main__':
main()