-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamcli.py
102 lines (95 loc) · 2.59 KB
/
amcli.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
96
97
98
99
100
101
102
import sys
import argparse
import datetime as dt
from amapi.AmDistributions import AmDistributions
from amapi.AmAttributions import AmAttributions
from amapi.AmUninstalls import AmUninstalls
def valid_date(s):
try:
return dt.datetime.strptime(s, "%Y-%m-%d")
except ValueError:
msg = "Not a valid date: '{0}'.".format(s)
raise argparse.ArgumentTypeError(msg)
def dist(args):
if args.output == 'txt':
AmDistributions(args).reportTXT()
else:
AmDistributions(args).reportCSV()
def attr(args):
if args.output == 'txt':
AmAttributions(args).reportTXT()
else:
AmAttributions(args).reportCSV()
def unin(args):
if args.output == 'txt':
AmUninstalls(args).reportTXT()
else:
AmUninstalls(args).reportCSV()
def build_arg_parser():
parser = argparse.ArgumentParser()
parser.add_argument(
"report_mnemonic",
help="produce the report specified here",
choices=["dist","attr","unin"]
)
parser.add_argument(
"-u",
"--username",
help="username for authentication"
)
parser.add_argument(
"-p",
"--password",
help="password for authentication. as of 2020.10.01, atlassian requires the use of API tokens. those can be generated here - https://id.atlassian.com/manage-profile/security/api-tokens"
)
parser.add_argument(
"-A",
"--app",
help="app key to report on"
)
parser.add_argument(
"-V",
"--vendor",
help="vendor key to report on"
)
parser.add_argument(
"-b",
"--begdate",
help="beginning date for report yyyy-mm-dd",
type=valid_date
)
parser.add_argument(
"-e",
"--enddate",
help="ending date for report yyyy-mm-dd",
default=dt.datetime.utcnow(),
type=valid_date
)
parser.add_argument(
"-d",
"--t_minus_days",
help="# of days backward to report",
default=30,
type=int
)
parser.add_argument(
"-O",
"--output",
help="produce the report in specified format",
default="csv",
choices=["txt","csv"]
)
parser.add_argument(
"-v",
"--verbosity",
action="count",
help="enable verbose output to print details of input records",
default=0
)
return parser
def main():
args = build_arg_parser().parse_args()
this = sys.modules[__name__]
getattr(this, args.report_mnemonic)(args)
if __name__ == '__main__':
main()