annotate data_stores/vdb_folder.py @ 2:269d246ce6d0 draft default tip

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