-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.py
executable file
·185 lines (157 loc) · 4.67 KB
/
cli.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env python3
import os, click, requests
import xml.dom.minidom
@click.group()
@click.option(
"--host", envvar="NAZGUL_PATH", default="http://localhost:8000", show_default=True
)
@click.option("--username", envvar="NAZGUL_USER", default="admin", show_default=True)
@click.option("--password", envvar="NAZGUL_PASS", default="admin", show_default=True)
@click.pass_context
def main(ctx, **kwargs):
ctx.obj = dict(**kwargs)
pass
def cli_out(data):
try:
dom = xml.dom.minidom.parseString(data)
pretty_xml = dom.toprettyxml()
print(pretty_xml)
except:
print(data)
@main.command()
@click.pass_obj
@click.argument("product")
@click.option(
"--fuzzy/--no-fuzzy",
"fuzzy",
show_default=True,
help="True = find similar product names, False = exact match of product name",
)
def location_show(ctx, **kwargs):
r = requests.get(ctx["host"] + "/api/location_show/", params=dict(**kwargs))
cli_out(r.text)
@main.command()
@click.pass_obj
@click.argument("product")
@click.argument("os")
@click.argument("path")
def location_add(ctx, **kwargs):
r = requests.post(
ctx["host"] + "/api/location_add/",
data=dict(**kwargs),
auth=requests.auth.HTTPBasicAuth(ctx["username"], ctx["password"]),
)
cli_out(r.text)
@main.command()
@click.pass_obj
@click.argument("product")
@click.argument("os")
@click.argument("path")
def location_modify(ctx, **kwargs):
r = requests.post(
ctx["host"] + "/api/location_modify/",
data=dict(**kwargs),
auth=requests.auth.HTTPBasicAuth(ctx["username"], ctx["password"]),
)
cli_out(r.text)
@main.command()
@click.pass_obj
@click.argument("location_id")
def location_delete(ctx, **kwargs):
r = requests.post(
ctx["host"] + "/api/location_delete/",
data=dict(**kwargs),
auth=requests.auth.HTTPBasicAuth(ctx["username"], ctx["password"]),
)
cli_out(r.text)
@main.command()
@click.pass_obj
@click.argument("product")
@click.option(
"--fuzzy/--no-fuzzy",
"fuzzy",
show_default=True,
help="True = find similar product names, False = exact match of product name",
)
def product_show(ctx, **kwargs):
r = requests.get(ctx["host"] + "/api/product_show/", params=dict(**kwargs))
cli_out(r.text)
@main.command()
@click.pass_obj
@click.argument("product")
@click.argument("languages")
@click.argument("ssl_only")
def product_add(ctx, **kwargs):
kwargs["languages"] = kwargs["languages"].split(",")
r = requests.post(
ctx["host"] + "/api/product_add/",
data=dict(**kwargs),
auth=requests.auth.HTTPBasicAuth(ctx["username"], ctx["password"]),
)
cli_out(r.text)
@main.command()
@click.pass_obj
@click.option(
"-pid", "--product_id", default=None, help="id of product to add/delete/update/show"
)
@click.option(
"-p", "--product", default=None, help="name of product to add/delete/update/show"
)
def product_delete(ctx, **kwargs):
r = requests.post(
ctx["host"] + "/api/product_delete/",
data=dict(**kwargs),
auth=requests.auth.HTTPBasicAuth(ctx["username"], ctx["password"]),
)
cli_out(r.text)
@main.command()
@click.pass_obj
@click.argument("product")
@click.argument("languages")
def product_language_add(ctx, **kwargs):
kwargs["languages"] = kwargs["languages"].split(",")
r = requests.post(
ctx["host"] + "/api/product_language_add/",
data=dict(**kwargs),
auth=requests.auth.HTTPBasicAuth(ctx["username"], ctx["password"]),
)
cli_out(r.text)
@main.command()
@click.pass_obj
@click.argument("product")
@click.argument("languages")
def product_language_delete(ctx, **kwargs):
if kwargs["languages"] != "*":
kwargs["languages"] = kwargs["languages"].split(",")
r = requests.post(
ctx["host"] + "/api/product_language_delete/",
data=dict(**kwargs),
auth=requests.auth.HTTPBasicAuth(ctx["username"], ctx["password"]),
)
cli_out(r.text)
@main.command()
@click.pass_obj
@click.argument("product")
@click.argument("os")
@click.option(
"--fuzzy/--no-fuzzy",
"fuzzy",
show_default=True,
help="True = find similar product names, False = exact match of product name",
)
def uptake(ctx, **kwargs):
r = requests.get(ctx["host"] + "/api/uptake/", params=dict(**kwargs))
cli_out(r.text)
@main.command()
@click.pass_obj
@click.argument("alias")
@click.argument("related_product")
def create_update_alias(ctx, **kwargs):
r = requests.post(
ctx["host"] + "/api/create_update_alias/",
data=dict(**kwargs),
auth=requests.auth.HTTPBasicAuth(ctx["username"], ctx["password"]),
)
cli_out(r.text)
if __name__ == "__main__":
main()