comparison TrustStoreGalaxyImport.py @ 4:32d9b3343955

Toooool upload.
author Catherine Wise <catherine.wise@csiro.au>
date Thu, 12 Dec 2013 13:07:45 +1100
parents
children 159d2159e745
comparison
equal deleted inserted replaced
3:6de426d89bb9 4:32d9b3343955
1 import sys
2 import shutil
3 from py_ts import TrustStoreClient, ts_utils
4
5 if __name__ == '__main__':
6
7 kms_url = sys.argv[1]
8 ims_url = sys.argv[2]
9 username = sys.argv[3]
10 password = sys.argv[4]
11 client_key = sys.argv[5]
12 client_secret = sys.argv[6]
13 storename = sys.argv[7]
14 path = sys.argv[8]
15 filename = sys.argv[9]
16 outputFile = sys.argv[10]
17
18 config = TrustStoreClient.Config(ims_url, kms_url, client_key, client_secret)
19 ts = TrustStoreClient.TrustStoreClient(headless=True, config=config)
20 try:
21 ts.authenticate(username, password)
22 except TrustStoreClient.TrustStoreClientAuthenticationException as e:
23 print e
24 sys.exit(5)
25 ts.getPrivateKey('privkey.pem')
26 listing = ts.listStores()
27 found = False
28 for store in listing:
29 if store.friendly_name == storename:
30 found = True
31 root = ts.listDirectory(store)
32 location = None
33 if path != "/":
34 location = ts_utils.ts_utils.dirAtPath(root, path)
35 if not location:
36 print "Path not found"
37 sys.exit(3)
38 else:
39 location = root
40 downloadMe = ts_utils.ts_utils.recurseToChildNamed(location, filename)
41 if downloadMe:
42 download = ts.getFile(store, downloadMe)
43 shutil.copy(download, outputFile)
44 else:
45 print "File not found"
46 sys.exit(4)
47 if not found:
48 print "Store not found"
49 sys.exit(2)