annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
1 import sys
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
2 import shutil
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
3 from py_ts import TrustStoreClient, ts_utils
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
4
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
5 if __name__ == '__main__':
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
6
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
7 kms_url = sys.argv[1]
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
8 ims_url = sys.argv[2]
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
9 username = sys.argv[3]
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
10 password = sys.argv[4]
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
11 client_key = sys.argv[5]
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
12 client_secret = sys.argv[6]
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
13 storename = sys.argv[7]
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
14 path = sys.argv[8]
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
15 filename = sys.argv[9]
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
16 outputFile = sys.argv[10]
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
17
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
18 config = TrustStoreClient.Config(ims_url, kms_url, client_key, client_secret)
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
19 ts = TrustStoreClient.TrustStoreClient(headless=True, config=config)
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
20 try:
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
21 ts.authenticate(username, password)
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
22 except TrustStoreClient.TrustStoreClientAuthenticationException as e:
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
23 print e
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
24 sys.exit(5)
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
25 ts.getPrivateKey('privkey.pem')
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
26 listing = ts.listStores()
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
27 found = False
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
28 for store in listing:
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
29 if store.friendly_name == storename:
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
30 found = True
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
31 root = ts.listDirectory(store)
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
32 location = None
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
33 if path != "/":
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
34 location = ts_utils.ts_utils.dirAtPath(root, path)
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
35 if not location:
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
36 print "Path not found"
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
37 sys.exit(3)
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
38 else:
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
39 location = root
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
40 downloadMe = ts_utils.ts_utils.recurseToChildNamed(location, filename)
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
41 if downloadMe:
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
42 download = ts.getFile(store, downloadMe)
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
43 shutil.copy(download, outputFile)
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
44 else:
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
45 print "File not found"
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
46 sys.exit(4)
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
47 if not found:
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
48 print "Store not found"
32d9b3343955 Toooool upload.
Catherine Wise <catherine.wise@csiro.au>
parents:
diff changeset
49 sys.exit(2)