4
|
1 import sys
|
|
2 import shutil
|
|
3 from py_ts import TrustStoreClient, ts_utils
|
|
4
|
5
|
5 def printNice(elem, f, depth):
|
|
6 try:
|
|
7 f.write('\t'*depth + elem.name + " (" + str(len(elem.fragments)) + " parts)\n")
|
|
8 except AttributeError:
|
|
9 f.write('\t'*depth + elem.name + "\n")
|
|
10 for child in elem.children:
|
|
11 printNice(child, f, depth+1)
|
|
12
|
4
|
13 if __name__ == '__main__':
|
|
14
|
|
15 kms_url = sys.argv[1]
|
|
16 ims_url = sys.argv[2]
|
|
17 username = sys.argv[3]
|
|
18 password = sys.argv[4]
|
|
19 client_key = sys.argv[5]
|
|
20 client_secret = sys.argv[6]
|
|
21 storename = sys.argv[7]
|
|
22 path = sys.argv[8]
|
5
|
23 filename = ""
|
|
24 outputFile = ""
|
|
25 if len(sys.argv) > 10:
|
|
26 filename = sys.argv[9]
|
|
27 outputFile = sys.argv[10]
|
|
28 else:
|
|
29 outputFile = sys.argv[9]
|
4
|
30
|
|
31 config = TrustStoreClient.Config(ims_url, kms_url, client_key, client_secret)
|
|
32 ts = TrustStoreClient.TrustStoreClient(headless=True, config=config)
|
|
33 try:
|
|
34 ts.authenticate(username, password)
|
|
35 except TrustStoreClient.TrustStoreClientAuthenticationException as e:
|
|
36 print e
|
|
37 sys.exit(5)
|
|
38 ts.getPrivateKey('privkey.pem')
|
|
39 listing = ts.listStores()
|
|
40 found = False
|
|
41 for store in listing:
|
|
42 if store.friendly_name == storename:
|
|
43 found = True
|
|
44 root = ts.listDirectory(store)
|
|
45 location = None
|
|
46 if path != "/":
|
|
47 location = ts_utils.ts_utils.dirAtPath(root, path)
|
|
48 if not location:
|
|
49 print "Path not found"
|
|
50 sys.exit(3)
|
|
51 else:
|
|
52 location = root
|
5
|
53 if filename and filename != "":
|
|
54 downloadMe = ts_utils.ts_utils.recurseToChildNamed(location, filename)
|
|
55 if downloadMe:
|
|
56 download = ts.getFile(store, downloadMe)
|
|
57 shutil.copy(download, outputFile)
|
|
58 else:
|
|
59 print "File not found"
|
|
60 sys.exit(4)
|
4
|
61 else:
|
5
|
62 with open(outputFile, 'w+') as f:
|
|
63 try:
|
|
64 for child in root.children:
|
|
65 printNice(child, f, 0)
|
|
66 except AttributeError as e:
|
|
67 print e
|
|
68 print root
|
4
|
69 if not found:
|
|
70 print "Store not found"
|
|
71 sys.exit(2)
|