Mercurial > repos > cathywise > truststore_browse_testing
comparison TrustStoreGalaxyBrowse.py @ 45:31838e0ecf45 default tip
Fixes.
author | Wise, Catherine (Digital, Acton) <Catherine.Wise@csiro.au> |
---|---|
date | Fri, 26 Jun 2015 10:24:40 +1000 |
parents | 174df9815ecd |
children |
comparison
equal
deleted
inserted
replaced
44:5589d367885e | 45:31838e0ecf45 |
---|---|
70 break | 70 break |
71 os.write(file_handle, chunk) | 71 os.write(file_handle, chunk) |
72 os.close(file_handle) | 72 os.close(file_handle) |
73 gzipped_file.close() | 73 gzipped_file.close() |
74 | 74 |
75 shutil.copy(uncompressed, outputFile) | 75 try: |
76 shutil.copy(uncompressed, outputFile) | |
77 except shutil.Error: | |
78 pass # If the file is already in the right location, move along. | |
76 try: | 79 try: |
77 os.remove(uncompressed) | 80 os.remove(uncompressed) |
78 os.remove(download) | 81 os.remove(download) |
79 except OSError: | 82 except OSError: |
80 pass | 83 pass |
81 else: | 84 else: |
82 shutil.copy(download, outputFile) | 85 try: |
86 shutil.copy(download, outputFile) | |
87 except shutil.Error: | |
88 pass # If the file is already in the right location, move along. | |
83 | 89 |
84 def construct_multi_filename(id, name, file_type): | 90 def construct_multi_filename(id, name, file_type): |
85 """ Implementation of *Number of Output datasets cannot be determined until | 91 """ Implementation of *Number of Output datasets cannot be determined until |
86 tool run* from documentation_. | 92 tool run* from documentation_. |
87 .. _documentation: http://wiki.galaxyproject.org/Admin/Tools/Multiple%20Output%20Files | 93 .. _documentation: http://wiki.galaxyproject.org/Admin/Tools/Multiple%20Output%20Files |
88 From https://github.com/mdshw5/galaxy-json-data-source/blob/master/json_data_source.py | 94 From https://github.com/mdshw5/galaxy-json-data-source/blob/master/json_data_source.py |
89 """ | 95 """ |
90 filename = "%s_%s_%s_%s_%s" % ('primary', id, name, 'visible', file_type) | 96 filename = "%s_%s_%s_%s_%s" % ('primary', id, name, 'visible', file_type) |
91 return filename | 97 return filename |
92 | 98 |
93 def metadata_to_json(dataset_id, filename, name, extesion, ds_type='dataset', primary=False): | 99 def metadata_to_json(dataset_id, filename, name, extension, ds_type='dataset', primary=False): |
94 """ Return line separated JSON | 100 """ Return line separated JSON |
95 From https://github.com/mdshw5/galaxy-json-data-source/blob/master/json_data_source.py | 101 From https://github.com/mdshw5/galaxy-json-data-source/blob/master/json_data_source.py |
96 """ | 102 """ |
103 ext = extension | |
104 if ext == 'fa': | |
105 ext = 'fasta' | |
97 meta_dict = dict(type=ds_type, | 106 meta_dict = dict(type=ds_type, |
98 ext=extesion, | 107 ext=ext, |
99 filename=filename, | 108 filename=filename, |
100 name=name, | 109 name=name, |
101 metadata={}) | 110 metadata={}) |
102 if primary: | 111 if primary: |
103 meta_dict['base_dataset_id'] = dataset_id | 112 meta_dict['base_dataset_id'] = dataset_id |
188 filename = "".join(c in SAFE_CHARS and c or '-' for c in location.name) | 197 filename = "".join(c in SAFE_CHARS and c or '-' for c in location.name) |
189 extension = os.path.splitext(filename)[1].strip(".") | 198 extension = os.path.splitext(filename)[1].strip(".") |
190 name = construct_multi_filename(hda_id, filename, extension) | 199 name = construct_multi_filename(hda_id, filename, extension) |
191 target_output_filename = None | 200 target_output_filename = None |
192 data_type = "new_primary_dataset" | 201 data_type = "new_primary_dataset" |
193 # if first: | |
194 # target_output_filename = file_name | |
195 # dataset = "new_primary_dataset" | |
196 # first = False | |
197 # else: | |
198 target_output_filename = os.path.normpath(os.path.join(extra_files_path, name)) | 202 target_output_filename = os.path.normpath(os.path.join(extra_files_path, name)) |
199 download = truststore.getFile(store, location) | 203 download = truststore.getFile(store, location) |
204 primary = not first | |
200 if download is None: | 205 if download is None: |
201 print("File %s not found." % location.name) | 206 print("File %s not found." % location.name) |
202 sys.exit(4) | 207 sys.exit(4) |
208 if first: | |
209 first = False | |
210 target_output_filename = file_name | |
211 data_type = "dataset" | |
203 ungzip(download, target_output_filename) | 212 ungzip(download, target_output_filename) |
213 metadata_file.write( | |
214 metadata_to_json(dataset_id, target_output_filename, name, extension, data_type, primary=primary)) | |
204 # ext = sniff.handle_uploaded_dataset_file(target_output_filename, datatypes_registry, ext=ext) | 215 # ext = sniff.handle_uploaded_dataset_file(target_output_filename, datatypes_registry, ext=ext) |
205 # print("Guessed file type: " + ext) | 216 # print("Guessed file type: " + ext) |
206 print("in file: " + properties_file) | |
207 metadata_file.write( | |
208 metadata_to_json(dataset_id, target_output_filename, name, extension, data_type)) | |
209 else: | 217 else: |
210 print("Store is damaged or we don't have sufficient access.") | 218 print("Store is damaged or we don't have sufficient access.") |
211 sys.exit(4) | 219 sys.exit(4) |
212 | 220 |
213 | 221 |