Mercurial > repos > damion > versioned_data
comparison data_stores/vdb_folder.py @ 1:5c5027485f7d draft
Uploaded correct file
| author | damion | 
|---|---|
| date | Sun, 09 Aug 2015 16:07:50 -0400 | 
| parents | |
| children | 
   comparison
  equal
  deleted
  inserted
  replaced
| 0:d31a1bd74e63 | 1:5c5027485f7d | 
|---|---|
| 1 #!/usr/bin/python | |
| 2 ## ******************************* FILE FOLDER ********************************* | |
| 3 ## | |
| 4 | |
| 5 import re | |
| 6 import os | |
| 7 import vdb_common | |
| 8 import vdb_data_stores | |
| 9 | |
| 10 class VDBFolderDataStore(vdb_data_stores.VDBDataStore): | |
| 11 | |
| 12 versions = None | |
| 13 library = None | |
| 14 | |
| 15 def __init__(self, retrieval_obj, spec_file_id): | |
| 16 """ | |
| 17 Provides list of available versions where each version is indicated by the | |
| 18 existence of a folder that contains its content. This content can be directly | |
| 19 in the galaxy Versioned Data folder tree, OR it can be linked to another folder | |
| 20 on the server. In the latter case, galaxy will treat the Versioned Data folders as caches. | |
| 21 View of versions filters out any folders that are used for derivative data caching. | |
| 22 """ | |
| 23 super(VDBFolderDataStore, self).__init__(retrieval_obj, spec_file_id) | |
| 24 | |
| 25 self.library = retrieval_obj.library | |
| 26 | |
| 27 versions = [] | |
| 28 | |
| 29 # If data source spec file has no content, use the library folder directly. | |
| 30 # Name of EACH subfolder should be a label for each version, including date/time and version id. | |
| 31 if self.data_store_path == '': | |
| 32 try: | |
| 33 lib_label_len = len(self.library_label_path) +1 | |
| 34 | |
| 35 for item in self.library: | |
| 36 # If item is under library_label_path ... | |
| 37 if item['name'][0:lib_label_len] == self.library_label_path + '/': | |
| 38 item_name = item['name'][lib_label_len:len(item['name'])] | |
| 39 if item_name.find('/') == -1 and item_name.find('_') != -1: | |
| 40 (item_date, item_version) = item_name.split('_',1) | |
| 41 created = vdb_common.parse_date(item_date) | |
| 42 versions.append({'name':item_name, 'id':item_name, 'created': created}) | |
| 43 | |
| 44 except Exception as err: | |
| 45 # This is the first call to api so api url or authentication erro can happen here. | |
| 46 versions.append({ | |
| 47 'name':'Software Error: Unable to get version list: ' + err.message, | |
| 48 'id':'', | |
| 49 'created':'' | |
| 50 }) | |
| 51 | |
| 52 else: | |
| 53 | |
| 54 base_file_path = self.data_store_path | |
| 55 #base_file_path = os.path.dirname(self.base_file_name) | |
| 56 #Here we need to get directory listing of linked file location. | |
| 57 for item_name in os.listdir(base_file_path): # Includes files and folders | |
| 58 # Only interested in folders | |
| 59 if os.path.isdir( os.path.join(base_file_path, item_name)) and item_name.find('_') != -1: | |
| 60 (item_date, item_version) = item_name.split('_',1) | |
| 61 created = vdb_common.parse_date(item_date) | |
| 62 versions.append({'name':item_name, 'id':item_name, 'created': created}) | |
| 63 | |
| 64 | |
| 65 self.versions = sorted(versions, key=lambda x: x['name'], reverse=True) | |
| 66 | |
| 67 def get_version(self, version_name): | |
| 68 """ | |
| 69 Return server path of requested version info - BUT ONLY IF IT IS LINKED. | |
| 70 IF NOT LINKED, returns None for self.version_path | |
| 71 | |
| 72 QUESTION: DOES GALAXY AUTOMATICALLY HANDLE tar.gz/zip decompression? | |
| 73 | |
| 74 @uses library_label_path string Full hierarchic label of a library file or folder, PARENT of version id folder. | |
| 75 @uses base_file_name string Server absolute path to data_store spec file | |
| 76 | |
| 77 @param version_name alphaneumeric string (git tag) | |
| 78 """ | |
| 79 self.version_label = version_name | |
| 80 self.library_version_path = os.path.join(self.library_label_path, self.version_label) | |
| 81 | |
| 82 if self.data_store_path == '': | |
| 83 # In this case version content is held in library directly; | |
| 84 self.version_path = self.base_file_name | |
| 85 | |
| 86 else: | |
| 87 | |
| 88 #linked to some other folder, spec is location of base_file_name | |
| 89 self.version_path = os.path.join(self.data_store_path, version_name) | |
| 90 | 
