forked from shinglyu/moztrap-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoztrap.py
executable file
·66 lines (54 loc) · 2.67 KB
/
moztrap.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
#!/usr/bin/python
import argparse
import logging
import mtapi
import diff
#logging.basicConfig(level=logging.INFO)
#logging.basicConfig(level=logging.DEBUG)
def main():
# query = " ".join(sys.argv[1:])
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest="action",
help="use \"[command] -h\" to see help message for individual command")
parser_clone = subparsers.add_parser('clone')
parser_clone.add_argument('resource_type', type=str,
choices=['caseversion', 'case', 'suite'], help="Resource type")
parser_clone.add_argument('id', type=int, help="Resource ID")
parser_diff = subparsers.add_parser('diff')
parser_diff.add_argument('filename', type=str, help="File to be diffed")
parser_push = subparsers.add_parser('push')
parser_push.add_argument('-f', '--force', action="store_true",
help="Force overwrite (BE CAREFUL!)", required=True)
parser_push.add_argument('filename', type=str, help="File to be pushed")
parser_push.add_argument('-u', '--username',
help="MozTrap username", required=True)
parser_push.add_argument('-k', '--api_key',
help="MozTrap api key", required=True)
parser_push = subparsers.add_parser('create')
# parser_push.add_argument('-f', '--force', action="store_true",
# help="Force overwrite (BE CAREFUL!)", required=True)
parser_push.add_argument('filename', type=str, help="File to be created")
parser_push.add_argument('-u', '--username',
help="MozTrap username", required=True)
parser_push.add_argument('-k', '--api_key',
help="MozTrap api key", required=True)
args = parser.parse_args()
# #print args
if args.action == "clone":
mtapi.clone(args.resource_type, args.id)
elif args.action == "diff":
diff.diff(args)
elif args.action == "push":
#if not args.force:
# raise Exception("Push will force override everything on the server."
# + " Use \"push -f\" to acknowledge the risk")
credental = {'username': args.username, 'api_key': args.api_key}
mtapi.push(args.filename, credental)
elif args.action == "create":
#if not args.force:
# raise Exception("Push will force override everything on the server."
# + " Use \"push -f\" to acknowledge the risk")
credental = {'username': args.username, 'api_key': args.api_key}
mtapi.create(args.filename, credental)
if __name__ == '__main__':
main()