-
Notifications
You must be signed in to change notification settings - Fork 6
/
api_test.py
executable file
·53 lines (40 loc) · 1.32 KB
/
api_test.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
#!/usr/bin/env python
"""
Allows for generic command line testing of the ddsapi.
For example to get a list of project names:
python api_test.py get_projects | grep description
Run without any arguments to get a list of what arguments are possible:
python api_test.py
"""
import sys
import yaml
import inspect
from ddsc.config import create_config
from ddsc.core.remotestore import RemoteStore
def convertNoneStr(arg):
if arg == 'None':
return None
return arg
def main(args=None):
if args is None:
args = sys.argv[1:]
args = [convertNoneStr(arg) for arg in args]
config = create_config()
remote_store = RemoteStore(config)
ds = remote_store.data_service
if not args:
print ("Data service methods:")
for method_name in get_public_methods(ds):
method = getattr(ds, method_name)
args = [arg for arg in inspect.getargspec(method).args if arg != 'self']
print('{} {}'.format(method_name, ' '.join(args)))
print("")
else:
f = getattr(ds, args[0])
ret = f.__call__(*args[1:])
result = ret.json()
print(yaml.safe_dump(result))
def get_public_methods(obj):
return [method for method in dir(obj) if not method.startswith("_") and callable(getattr(obj, method))]
if __name__ == '__main__':
main()