diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TrustStoreGalaxyImport.py	Thu Dec 12 13:07:45 2013 +1100
@@ -0,0 +1,49 @@
+import sys
+import shutil
+from py_ts import TrustStoreClient, ts_utils
+
+if __name__ == '__main__':
+
+    kms_url = sys.argv[1]
+    ims_url = sys.argv[2]
+    username = sys.argv[3]
+    password = sys.argv[4]
+    client_key = sys.argv[5]
+    client_secret = sys.argv[6]
+    storename = sys.argv[7]
+    path = sys.argv[8]
+    filename = sys.argv[9]
+    outputFile = sys.argv[10]
+
+    config = TrustStoreClient.Config(ims_url, kms_url, client_key, client_secret)
+    ts = TrustStoreClient.TrustStoreClient(headless=True, config=config)
+    try:
+        ts.authenticate(username, password)
+    except TrustStoreClient.TrustStoreClientAuthenticationException as e:
+        print e
+        sys.exit(5)
+    ts.getPrivateKey('privkey.pem')
+    listing = ts.listStores()
+    found = False
+    for store in listing:
+        if store.friendly_name == storename:
+            found = True
+            root = ts.listDirectory(store)
+            location = None
+            if path != "/":
+                location = ts_utils.ts_utils.dirAtPath(root, path)
+                if not location:
+                    print "Path not found"
+                    sys.exit(3)
+            else:
+                location = root
+            downloadMe = ts_utils.ts_utils.recurseToChildNamed(location, filename)
+            if downloadMe:
+                download = ts.getFile(store, downloadMe)
+                shutil.copy(download, outputFile)
+            else:
+                print "File not found"
+                sys.exit(4)
+    if not found:
+        print "Store not found"
+        sys.exit(2)