changeset 29:157062f5c547

Fix temporary dir.
author Catherine Wise <catherine.wise@csiro.au>
date Mon, 18 May 2015 11:17:03 +1000
parents a325622e2277
children 0a6dd98baf53
files TrustStoreGalaxyBrowse.py
diffstat 1 files changed, 33 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/TrustStoreGalaxyBrowse.py	Thu May 14 15:43:08 2015 +1000
+++ b/TrustStoreGalaxyBrowse.py	Mon May 18 11:17:03 2015 +1000
@@ -131,8 +131,13 @@
         sys.exit(5)
     kms_url = short_url.split("/short")[0]
 
+    tmp_dir = '/mnt/galaxy/tmp'
+    tmp = None
+    if os.path.exists(tmp_dir):
+        tmp = tmp_dir
+
     config = TrustStoreClient.Config(
-        None, kms_url, CLIENT_KEY, CLIENT_SECRET, tmpDir='/mnt/galaxy/tmp')
+        None, kms_url, CLIENT_KEY, CLIENT_SECRET, tmpDir=tmp)
     truststore = TrustStoreClient.TrustStoreClient(headless=False, config=config)
     try:
         truststore.authenticate(username, password)
@@ -156,29 +161,33 @@
 
     first = True
 
-    with open(metadata_path, 'wb') as metadata_file:
-        for path in paths:
-            locations = utils.Navigation.files_at_path(root, path)
-            for location in locations:
-                if not locations:
-                    print("Path not found: " + path)
-                    continue
-                filename = "".join(c in SAFE_CHARS and c or '-' for c in location.name)
-                extension = os.path.splitext(filename)[1]
-                name = construct_multi_filename(hda_id, filename, extension)
-                target_output_filename = None
-                if first:
-                    target_output_filename = file_name
-                    first = False
-                else:
-                    target_output_filename = os.path.normpath("/".join([extra_files_path, name]))
-                metadata_file.write(
-                    metadata_to_json(dataset_id, filename, name, extension, target_output_filename))
-                download = truststore.getFile(store, location)
-                if download is None:
-                    print("File %s not found." % location.name)
-                    sys.exit(4)
-                ungzip(download, target_output_filename)
+    if root is not None:
+        with open(metadata_path, 'wb') as metadata_file:
+            for path in paths:
+                locations = utils.Navigation.files_at_path(root, path)
+                for location in locations:
+                    if not locations:
+                        print("Path not found: " + path)
+                        continue
+                    filename = "".join(c in SAFE_CHARS and c or '-' for c in location.name)
+                    extension = os.path.splitext(filename)[1]
+                    name = construct_multi_filename(hda_id, filename, extension)
+                    target_output_filename = None
+                    if first:
+                        target_output_filename = file_name
+                        first = False
+                    else:
+                        target_output_filename = os.path.normpath("/".join([extra_files_path, name]))
+                    metadata_file.write(
+                        metadata_to_json(dataset_id, filename, name, extension, target_output_filename))
+                    download = truststore.getFile(store, location)
+                    if download is None:
+                        print("File %s not found." % location.name)
+                        sys.exit(4)
+                    ungzip(download, target_output_filename)
+    else:
+        print("Store is damaged or we don't have sufficient access.")
+        sys.exit(4)
 
 
 if __name__ == '__main__':